Benday.Identity.CosmosDb.UI 3.0.0

dotnet add package Benday.Identity.CosmosDb.UI --version 3.0.0
                    
NuGet\Install-Package Benday.Identity.CosmosDb.UI -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Benday.Identity.CosmosDb.UI" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Benday.Identity.CosmosDb.UI" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Benday.Identity.CosmosDb.UI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Benday.Identity.CosmosDb.UI --version 3.0.0
                    
#r "nuget: Benday.Identity.CosmosDb.UI, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Benday.Identity.CosmosDb.UI@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Benday.Identity.CosmosDb.UI&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Benday.Identity.CosmosDb.UI&version=3.0.0
                    
Install as a Cake Tool

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 Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 82 2/27/2026
2.2.0 93 2/11/2026
2.1.0 87 2/9/2026
2.0.0 97 2/5/2026

v3.0.0 - BREAKING: Target net10.0 only (drop net9.0). Added passkey (WebAuthn/FIDO2) login button on login page, ManagePasskeys page for passkey registration and management.
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.