RavenDB.Identity 9.0.0

dotnet add package RavenDB.Identity --version 9.0.0                
NuGet\Install-Package RavenDB.Identity -Version 9.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="RavenDB.Identity" Version="9.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RavenDB.Identity --version 9.0.0                
#r "nuget: RavenDB.Identity, 9.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.
// Install RavenDB.Identity as a Cake Addin
#addin nuget:?package=RavenDB.Identity&version=9.0.0

// Install RavenDB.Identity as a Cake Tool
#tool nuget:?package=RavenDB.Identity&version=9.0.0                

<img src="https://github.com/JudahGabriel/RavenDB.Identity/blob/master/RavenDB.Identity/nuget-icon.png?raw=true" width="50px" height="50px" /> RavenDB.Identity

The simple and easy Identity provider for RavenDB and ASP.NET Core. Use Raven to store your users and roles.

Instructions

Important: Upgrading from a previous version of RavenDB.Identity? See <a href="#updating-from-old-version">Updating From Old Version</a> for steps to migrate to the latest RavenDB.Identity.

  1. Add an AppUser class that derives from Raven.Identity.IdentityUser:
public class AppUser : Raven.Identity.IdentityUser
{
    /// <summary>
    /// A user's full name.
    /// </summary>
    public string FullName { get; set; }
}
  1. In appsettings.json, configure your connection to Raven:
"RavenSettings": {
    "Urls": [
        "http://live-test.ravendb.net"
    ],
    "DatabaseName": "Raven.Identity.Sample.RazorPages",
    "CertFilePath": "",
    "CertPassword": ""
},

3a. In Startup.cs, wire it all up. Note that this approach will use the email address as part of the User Id, such that changing their email will change their User Id as well:

public void ConfigureServices(IServiceCollection services)
{    
    // Add RavenDB and identity.
    services
        .AddRavenDbDocStore() // Create an IDocumentStore singleton from the RavenSettings.
        .AddRavenDbAsyncSession() // Create a RavenDB IAsyncDocumentSession for each request. You're responsible for calling .SaveChanges after each request.
        .AddIdentity<AppUser, IdentityRole>() // Adds an identity system to ASP.NET Core
        .AddRavenDbIdentityStores<AppUser, IdentityRole>(); // Use RavenDB as the store for identity users and roles. Specify your app user type here, and your role type. If you don't have a role type, use Raven.Identity.IdentityRole.
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...
    // Instruct ASP.NET Core to use authentication and authorization.
    app.UseAuthentication();
    app.UseAuthorization();
    ...
}
  1. In your controller actions, call .SaveChangesAsync() when you're done making changes. Typically this is done via a RavenController base class for MVC/WebAPI projects or via a page filter for Razor Pages projects.

Changing how user IDs are generated

Previous versions of RavenDB.Identity used email-based user IDs, e.g. "AppUser/johndoe@mail.com". Newer versions use Raven's default behavior, typically "AppUsers/1-A"`. To change how Raven controls IDs for your users, see Raven's Global Identifier Generation Conventions.

If you have old users in your database using the email-based ID convention, no problem, Raven.Identity will still work with the old users. If you want consistent IDs across all your users, you can migrate existing users to a new ID generation scheme using the ChangeUserIdType migration:

// Important: backup your database before running this migration.
var newIdType = UserIdType.ServerGenerated; // Or whatever ID type you prefer.
var migration = new Raven.Identity.Migrations.ChangeUserIdType(docStore, newIdType);
migration.Migrate<AppUser>(); // AppUser, or whatever you user type is.

Regardless of how IDs are generated, uniqueness is based on email address. You can't have 2 users in your database with the same email address.

Modifying RavenDB conventions

Need to modify RavenDB conventions? You can use the services.AddRavenDbDocStore(options) overload:

services.AddRavenDbDocStore(options =>
{
    // Maybe we want to change the identity parts separator.
    options.BeforeInitializeDocStore = docStore => docStore.Conventions.IdentityPartsSeparator = "-";
})

<a id="updating-from-old-version">Updating From Old Version of RavenDB.Identity</a>

Using RavenDB.Identity v5 or earlier and want to upgrade to the latest? You need to run the CompareExchangeUniqueness migration:

// Important: backup your database before running this migration.
var migration = new Raven.Identity.Migrations.CompareExchangeUniqueness(docStore);
migration.Migrate();

This upgrade step is necessary because we updated RavenDB.Identity to use RavenDB's cluster-safe compare/exchange to enforce email-based uniqueness.

Previous versions of RavenDB.Identity had relied on IdentityUserByUserName IDs to enforce uniqueness, but this isn't guaranteed to work in a cluster. Doing this migration will create compare/exchange values in Raven for each user email address, and will remove the now-obsolete IdentityUserByUserNames collection.

Getting Started and Sample Project

Need help? Checkout the our samples to see how to use it:

Not using .NET Core?

See our sister project for a RavenDB Identity Provider for the full .NET Framework.

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

NuGet packages (2)

Showing the top 2 NuGet packages that depend on RavenDB.Identity:

Package Downloads
BeyondAuth.Identity.Core

Package Description

LeadSoft.Adapter.RavenDBIdentity

LeadSoft® RavenDB Identity Classes.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RavenDB.Identity:

Repository Stars
RemiBou/Toss.Blazor
Experimental project using AspNetCore Blazor
Version Downloads Last updated
9.0.0 16,607 1/13/2024
8.0.9 27,047 7/6/2023
8.0.8 3,415 4/20/2023
8.0.7 34,989 5/5/2021
8.0.6 1,395 4/1/2021
8.0.5 2,854 12/17/2020
8.0.4 2,477 9/22/2020
8.0.3 1,238 9/2/2020
8.0.2 1,885 7/28/2020
8.0.1 1,098 7/26/2020
8.0.0 1,101 7/25/2020
7.0.1 4,152 12/19/2019
7.0.0 1,201 12/13/2019
6.2.0.2 2,373 12/3/2019
6.2.0.1 1,176 11/28/2019
6.2.0 1,245 11/13/2019
6.1.0 3,713 7/8/2019
6.0.6 1,267 6/26/2019
6.0.5 1,197 6/10/2019
6.0.3 1,976 4/5/2019
6.0.2 4,845 4/1/2019
6.0.1 1,227 3/21/2019
5.0.1 1,224 3/11/2019
5.0.0 1,360 3/4/2019
4.4.1 3,967 10/8/2018
4.3.0 3,395 2/24/2018
4.2.0 1,602 2/23/2018
4.1.1 1,510 2/22/2018
4.0.1 1,636 2/11/2018
4.0.0 1,669 2/9/2018
3.0.0 1,766 9/28/2017
2.1.0 1,665 9/6/2017
2.0.4 1,680 9/5/2017
2.0.3 1,645 9/5/2017
2.0.2 1,644 8/29/2017
2.0.1 1,644 8/29/2017
2.0.0 3,847 8/29/2017
1.0.3 2,105 8/23/2017
1.0.1 5,793 8/23/2017
1.0.0 5,530 8/23/2017

Upgrades to .NET 8, Raven 6