GithubHelp home page GithubHelp logo

anthrax3 / ravendb.identity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from judahgabriel/ravendb.identity

0.0 2.0 0.0 1.26 MB

RavenDB Identity provider for ASP.NET Core. Let RavenDB manage your users and logins.

Home Page: https://www.nuget.org/packages/RavenDB.Identity/1.0.0

License: MIT License

C# 100.00%

ravendb.identity's Introduction

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 Updating From Old Version 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": ""
},
  1. In Startup.cs, wire it all up:
public void ConfigureServices(IServiceCollection services)
{
    // Grab our RavenSettings object from appsettings.json.
    services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
    
    ...
    
    // 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>(); // Use RavenDB as the store for identity users and roles.
    ...
}

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.

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 = "-";
})

Updating From Old Version of RavenDB.Identity

Using an old version of RavenDB.Identity and want to upgrade to the latest? You need to call the MigrateToV6 method:

// Update our existing users to the latest RavenDB.Identity v6.
// This is necessary only if you stored users with a previous version of RavenDB.Identity.
// Failure to call this method will result in existing users not being able to login.
// This method can take several minutes if you have thousands of users.
UserStore<AppUser>.MigrateToV6(docStore);

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

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

Getting Started and Sample Project

Need help? Checkout the Razor Pages sample or MVC sample to see it all in action.

Not using .NET Core?

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

ravendb.identity's People

Contributors

abremora avatar joshclose avatar judahgabriel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.