Giter VIP home page Giter VIP logo

aspnetcore-identity-mongodb's Introduction

Microsoft.AspNetCore.Identity.MongoDB

This is a MongoDB provider for the ASP.NET Core 2 Identity framework. This was ported from the v2 Identity framework that was a part of ASP.NET (AspNet.Identity.Mongo NuGet package)

I've released a new package for the ASP.NET Core 2 Identity framework for the following reasons:

  • Discoverability - named AspNetCore.
  • ASP.NET Core 2 is a rewrite of ASP.NET, this Core Identity framework won't run on traditional ASP.NET.
  • Migrating isn't a matter of updating dependencies.

This project has extensive test coverage.

If you want something easy to setup, this adapter is for you. I do not intend to cover every possible desirable configuration, if you don't like my decisions, write your own adapter. Use this as a learning tool to make your own adapter. These adapters are not complicated, but trying to make them configurable would become a complicated mess. And would confuse the majority of people that want something simple to use. So I'm favoring simplicity over making every last person happy.

Usage

  • Reference this package in project.json: Microsoft.AspNetCore.Identity.MongoDB
  • Then, in ConfigureServices--or wherever you are registering services--include the following to register both the Identity services and MongoDB stores:
services.AddIdentityWithMongoStores("mongodb://localhost/myDB");
  • If you want to customize what is registered, refer to the tests for further options (CoreTests/MongoIdentityBuilderExtensionsTests.cs)
  • Remember with the Identity framework, the whole point is that both a UserManager and RoleManager are provided for you to use, here's how you can resolve instances manually. Of course, constructor injection is also available.
var userManager = provider.GetService<UserManager<IdentityUser>>();
var roleManager = provider.GetService<RoleManager<IdentityRole>>();
  • The following methods help create indexes that will boost lookups by UserName, Email and role Name. These have changed since Identity v2 to refer to Normalized fields. I dislike this aspect of Core Identity, but it is what it is. Basically these three fields are stored in uppercase format for case insensitive searches.
	IndexChecks.EnsureUniqueIndexOnNormalizedUserName(users);
	IndexChecks.EnsureUniqueIndexOnNormalizedEmail(users);
	IndexChecks.EnsureUniqueIndexOnNormalizedRoleName(roles);
  • Here is a sample project, review the commit log for the steps taken to port the default template from EntityFramework MSSQL to MongoDB. aspnetcore2-identity-mongo-sample.

What frameworks are targeted, with rationale:

  • Microsoft.AspNetCore.Identity - supports net461 and netstandard2.0
  • MongoDB.Driver v2.3 - supports net45 and netstandard1.5
  • Thus, the lowest common denominators are net461 (of net46 and net461) and netstandard2.0
  • FYI net461 supports netstandard1.5, that's obviously too low for a single target

Building instructions

run commands in

Migrating from ASP.NET Identity 2.0

  • Roles names need to be normalized as follows
    • On IdentityRole documents, create a NormalizedName field = uppercase(Name). Leave Name as is.
    • On IdentityUser documents, convert the values in the Roles array to uppercase
  • User names need to be normalized as follows
    • On IdentityUser documents, create a NormalizedUserName field = uppercase(UserName) and create a NormalizedEmail field = uppercase(Email). Leave UserName and Email as is.

aspnetcore-identity-mongodb's People

Contributors

g0t4 avatar alextochetto avatar 50chickens avatar

Watchers

James Cloos 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.