Benday.Identity.CosmosDb 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Benday.Identity.CosmosDb --version 2.0.0
                    
NuGet\Install-Package Benday.Identity.CosmosDb -Version 2.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" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Benday.Identity.CosmosDb" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Benday.Identity.CosmosDb" />
                    
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 --version 2.0.0
                    
#r "nuget: Benday.Identity.CosmosDb, 2.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@2.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&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Benday.Identity.CosmosDb&version=2.0.0
                    
Install as a Cake Tool

Benday.Identity.CosmosDb

ASP.NET Core Identity implementation using Azure Cosmos DB as the backing store. Built on top of the Benday.CosmosDb repository pattern library.

Packages

Package Description
Benday.Identity.CosmosDb Core identity models and stores
Benday.Identity.CosmosDb.UI Registration extension method, pre-built Razor Pages (Login/Logout/AccessDenied), RedirectToLogin Blazor component, and admin seeding utility

Features

  • Full ASP.NET Core Identity support with Cosmos DB storage
  • User management (create, update, delete, find)
  • Role-based access control
  • Claims-based authorization
  • Account lockout protection
  • Two-factor authentication (2FA) support
  • External login providers (Google, Facebook, Microsoft, etc.)
  • Phone number verification
  • Security stamp management for token invalidation
  • LINQ query support
  • One-line registration via AddCosmosIdentity() (in UI package)
  • Pre-built Login/Logout/AccessDenied pages (in UI package)
  • RedirectToLogin Blazor component (in UI package)
  • Admin user seeding utility (in UI package)

Install both packages:

dotnet add package Benday.Identity.CosmosDb.UI

Register everything in Program.cs:

using Benday.Identity.CosmosDb.UI;
using Benday.CosmosDb.Utilities;

var cosmosConfig = builder.Configuration.GetCosmosConfig();

builder.Services.AddCosmosIdentity(cosmosConfig);
builder.Services.AddRazorPages();

// ...

app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();

That's it. No partition key knowledge, no store registration, no cookie configuration. Login/logout pages work out of the box.

Customization

builder.Services.AddCosmosIdentity(cosmosConfig,
    options =>
    {
        options.CookieName = "MyApp.Auth";
        options.UsersContainerName = "AppUsers";
        options.CookieExpiration = TimeSpan.FromDays(30);
    },
    identity =>
    {
        identity.Password.RequiredLength = 12;
        identity.Lockout.MaxFailedAccessAttempts = 3;
    })
    .AddDefaultTokenProviders();

Blazor Server: RedirectToLogin

In your App.razor or route component:

<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)">
    <NotAuthorized>
        <RedirectToLogin />
    </NotAuthorized>
</AuthorizeRouteView>

Seed Admin User

In Program.cs:

if (args.Contains("--seed-admin"))
{
    await CosmosIdentitySeeder.SeedAdminUserInteractive(app.Services);
    return;
}

Then run: dotnet run -- --seed-admin

Core Package Only

If you want just the models and stores without the UI package:

dotnet add package Benday.Identity.CosmosDb

You'll need to register the stores, identity, and cookie configuration manually.

Dependencies

  • Benday.CosmosDb - Cosmos DB repository pattern library
  • Microsoft.Extensions.Identity.Core

Implemented Interfaces

User Store (CosmosDbUserStore)

  • IUserStore<CosmosIdentityUser>
  • IUserPasswordStore<CosmosIdentityUser>
  • IUserEmailStore<CosmosIdentityUser>
  • IUserRoleStore<CosmosIdentityUser>
  • IUserSecurityStampStore<CosmosIdentityUser>
  • IUserLockoutStore<CosmosIdentityUser>
  • IUserClaimStore<CosmosIdentityUser>
  • IUserTwoFactorStore<CosmosIdentityUser>
  • IUserPhoneNumberStore<CosmosIdentityUser>
  • IUserAuthenticatorKeyStore<CosmosIdentityUser>
  • IUserTwoFactorRecoveryCodeStore<CosmosIdentityUser>
  • IUserLoginStore<CosmosIdentityUser>
  • IQueryableUserStore<CosmosIdentityUser>

Role Store (CosmosDbRoleStore)

  • IRoleStore<CosmosIdentityRole>
  • IRoleClaimStore<CosmosIdentityRole>
  • IQueryableRoleStore<CosmosIdentityRole>

Claims Principal Factory

  • DefaultUserClaimsPrincipalFactory - A default implementation that adds role claims to the identity.

Domain Models

CosmosIdentityUser

The user entity with support for:

  • Username and email (with automatic normalization)
  • Password hash
  • Security stamp and concurrency stamp
  • Phone number with confirmation
  • Two-factor authentication (authenticator key, recovery codes)
  • Account lockout
  • Claims collection
  • External login providers

CosmosIdentityRole

The role entity with support for:

  • Role name (with automatic normalization)
  • Concurrency stamp
  • Claims collection

Partition Key Strategy

All identity entities use a "SYSTEM" partition key by default, meaning all users and roles are stored in the same logical partition. This simplifies queries and works well for most applications. If you need a different partitioning strategy, you can override the SystemOwnedItem base class.

Migration from v1.x

v2.0 is a breaking change. All identity classes have been renamed to avoid namespace collisions with Microsoft.AspNetCore.Identity:

v1.x v2.0
IdentityUser CosmosIdentityUser
IdentityRole CosmosIdentityRole
IdentityConstants CosmosIdentityConstants
IdentityClaim CosmosIdentityClaim
IdentityUserClaim CosmosIdentityUserClaim
IdentityUserLogin CosmosIdentityUserLogin

Using aliases are no longer needed. You can remove any using IdentityUser = Benday.Identity.CosmosDb.IdentityUser; directives.

License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Benday.Identity.CosmosDb:

Package Downloads
Benday.Identity.CosmosDb.UI

ASP.NET Core Identity UI for Azure Cosmos DB. Provides pre-built Login/Logout/AccessDenied Razor Pages, a RedirectToLogin Blazor component, and AddCosmosIdentityWithUI() convenience method that combines core identity registration with cookie authentication. Built on top of Benday.Identity.CosmosDb.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.10 126 5/10/2026
6.0.9-alpha 103 4/27/2026
6.0.8-alpha 104 4/20/2026
6.0.7-alpha 103 4/20/2026
6.0.2-alpha 110 4/4/2026
6.0.1-alpha 120 4/3/2026
6.0.0-alpha 115 3/25/2026
3.2.0 167 3/13/2026
3.1.2 164 3/10/2026
3.1.1 160 3/10/2026
3.1.0 126 3/9/2026
3.0.0 124 2/27/2026
2.1.0 146 2/9/2026
2.0.0 144 2/5/2026
1.1.0 115 2/4/2026
1.0.0-alpha 480 12/9/2025

v2.0.0 - BREAKING: Renamed all identity classes with Cosmos prefix to avoid namespace collisions (IdentityUser -> CosmosIdentityUser, IdentityRole -> CosmosIdentityRole, etc.)
v1.1.0 - Update dependencies and package metadata; Changing target framework to netstandard2.1; Removing alpha tag
v1.0.0 - Initial release with full ASP.NET Core Identity store implementations for Cosmos DB