Benday.Identity.CosmosDb.UI
2.2.0
See the version list below for details.
dotnet add package Benday.Identity.CosmosDb.UI --version 2.2.0
NuGet\Install-Package Benday.Identity.CosmosDb.UI -Version 2.2.0
<PackageReference Include="Benday.Identity.CosmosDb.UI" Version="2.2.0" />
<PackageVersion Include="Benday.Identity.CosmosDb.UI" Version="2.2.0" />
<PackageReference Include="Benday.Identity.CosmosDb.UI" />
paket add Benday.Identity.CosmosDb.UI --version 2.2.0
#r "nuget: Benday.Identity.CosmosDb.UI, 2.2.0"
#:package Benday.Identity.CosmosDb.UI@2.2.0
#addin nuget:?package=Benday.Identity.CosmosDb.UI&version=2.2.0
#tool nuget:?package=Benday.Identity.CosmosDb.UI&version=2.2.0
Benday.Identity.CosmosDb.UI
Pre-built ASP.NET Core Identity UI pages for Azure Cosmos DB. One-line setup with AddCosmosIdentityWithUI() gives you login, registration, password reset, email confirmation, and admin user management — all backed by Cosmos DB.
Built on top of Benday.Identity.CosmosDb and Benday.CosmosDb.
Included Pages
| Page | Path | Description |
|---|---|---|
| Login | /Account/Login |
Username/password sign-in |
| Logout | /Account/Logout |
Sign-out |
| Access Denied | /Account/AccessDenied |
Unauthorized access page |
| Register | /Account/Register |
Self-registration (can be disabled) |
| Change Password | /Account/ChangePassword |
Authenticated password change |
| Forgot Password | /Account/ForgotPassword |
Request a password reset email |
| Reset Password | /Account/ResetPassword |
Reset password via emailed token |
| Confirm Email | /Account/ConfirmEmail |
Email confirmation via emailed link |
| User List (Admin) | /Admin/Users |
Search and paginate users |
| Edit User (Admin) | /Admin/Users/Edit/{id} |
Edit email, lockout, roles, and claims |
Quick Start
dotnet add package Benday.Identity.CosmosDb.UI
using Benday.Identity.CosmosDb.UI;
using Benday.CosmosDb.Utilities;
var cosmosConfig = builder.Configuration.GetCosmosConfig();
builder.Services.AddCosmosIdentityWithUI(cosmosConfig);
builder.Services.AddRazorPages();
// ...
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
Customization
builder.Services.AddCosmosIdentityWithUI(cosmosConfig,
options =>
{
options.CookieName = "MyApp.Auth";
options.CookieExpiration = TimeSpan.FromDays(30);
options.AllowRegistration = false; // disable self-registration
options.AdminRoleName = "SuperAdmin"; // custom admin role
options.RequireConfirmedEmail = true; // require email confirmation
},
identity =>
{
identity.Password.RequiredLength = 12;
identity.Lockout.MaxFailedAccessAttempts = 3;
});
All Options
| Option | Default | Description |
|---|---|---|
UsersContainerName |
CosmosConfig.ContainerName |
Container for user documents |
RolesContainerName |
CosmosConfig.ContainerName |
Container for role documents |
CookieName |
"Identity.Auth" |
Authentication cookie name |
LoginPath |
"/Account/Login" |
Login page path |
LogoutPath |
"/Account/Logout" |
Logout page path |
AccessDeniedPath |
"/Account/AccessDenied" |
Access denied page path |
CookieExpiration |
14 days | Cookie expiration time |
SlidingExpiration |
true |
Whether to use sliding expiration |
AllowRegistration |
true |
Whether self-registration is allowed |
AdminRoleName |
"UserAdmin" |
Role name required for admin pages |
RequireConfirmedEmail |
false |
Whether email confirmation is required before sign-in |
FromEmailAddress |
"" |
"From" address used by SmtpCosmosIdentityEmailSender |
Password Reset & Email Confirmation
These flows require a working email sender. By default a no-op sender is registered (emails are silently skipped).
Option 1: Built-in SMTP sender
builder.Services.AddSingleton(new SmtpClient("smtp.yourserver.com")
{
Port = 587,
Credentials = new NetworkCredential("user", "password"),
EnableSsl = true
});
// Register BEFORE AddCosmosIdentityWithUI (it uses TryAddSingleton)
builder.Services.AddSingleton<ICosmosIdentityEmailSender, SmtpCosmosIdentityEmailSender>();
builder.Services.AddCosmosIdentityWithUI(cosmosConfig,
options => { options.FromEmailAddress = "noreply@yourapp.com"; });
Option 2: Custom sender (SendGrid, SES, etc.)
Implement ICosmosIdentityEmailSender and register it before AddCosmosIdentityWithUI():
public class SendGridEmailSender : ICosmosIdentityEmailSender
{
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
{
// Your implementation here
}
}
builder.Services.AddSingleton<ICosmosIdentityEmailSender, SendGridEmailSender>();
builder.Services.AddCosmosIdentityWithUI(cosmosConfig);
Blazor: RedirectToLogin
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
Seed Admin User
if (args.Contains("--seed-admin"))
{
await CosmosIdentitySeeder.SeedAdminUserInteractive(app.Services);
return;
}
Then run: dotnet run -- --seed-admin
Admin Pages
The admin pages at /Admin/Users are protected by the CosmosIdentityAdmin authorization policy (requires the role specified by AdminRoleName, default "UserAdmin"). The CosmosIdentitySeeder automatically assigns this role when seeding.
License
MIT License - see LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Benday.CosmosDb (>= 5.2.0)
- Benday.Identity.CosmosDb (>= 2.1.0)
-
net9.0
- Benday.CosmosDb (>= 5.2.0)
- Benday.Identity.CosmosDb (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.2.0 - Added net10.0 target framework (multi-targets net9.0 and net10.0). Added NuGet package README.
v2.1.0 - Added Register, ChangePassword, ForgotPassword, ResetPassword, ConfirmEmail pages. Added admin User List and Edit User pages with role/claim management and account lockout. Added NoOpCosmosIdentityEmailSender, token providers, and CosmosIdentityAdmin authorization policy.
v2.0.0 - BREAKING: AddCosmosIdentity() moved to core Benday.Identity.CosmosDb package. Use AddCosmosIdentityWithUI() for the full UI experience. CosmosIdentityOptions and CosmosIdentitySeeder also moved to core package.