Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This is a MongoDB provider for the ASP.NET Core 2 Identity framework

License

NotificationsYou must be signed in to change notification settings

matteofabbri/AspNetCore.Identity.Mongo

Repository files navigation

This is a MongoDB provider for the ASP.NET Core Identity framework. It is completely written from scratch and provides support for all Identity framework interfaces:

  • IUserClaimStore
  • IUserLoginStore
  • IUserRoleStore
  • IUserPasswordStore
  • IUserSecurityStampStore
  • IUserEmailStore
  • IUserPhoneNumberStore
  • IQueryableUserStore
  • IUserTwoFactorStore
  • IUserLockoutStore
  • IUserAuthenticatorKeyStore
  • IUserAuthenticationTokenStore
  • IUserTwoFactorRecoveryCodeStore
  • IProtectedUserStore
  • IRoleStore
  • IRoleClaimStore
  • IQueryableRoleStore

Dotnet Versions support

The latest package version supports only dotnet versions maintainable by Microsoft at the momentSupported Dotnet Versions

Please refer tothis table if you'd like to use this library with older dotnet versions.

MongoDB Indexes

Important note!

Starting fromv9.0.0 we no longer apply indexes on"Users" collection. Main reason for this change thatyou are unable to change default indexes. If you delete index, it will appear again;if you delete index and re-create it with different options, application won't start due to error.You most likely have other indexes of your own, and now you have 2 places where they managed.So it's up to user to decide which indexes should be used (if any), how and where manage them.

Here the old indexes in case someone needs them (collection name could be different):

db.Users.createIndex({ "NormalizedEmail" : 1 })db.Users.createIndex({ "NormalizedUserName" : 1 })

How to use:

AspNetCore.Identity.Mongo is installed from NuGet:

Install-Package AspNetCore.Identity.Mongo

The simplest way to set up:

usingAspNetCore.Identity.Mongo;usingAspNetCore.Identity.Mongo.Model;// At the ConfigureServices section in Startup.csservices.AddIdentityMongoDbProvider<MongoUser>();

With Identity and Mongo options:

usingAspNetCore.Identity.Mongo;usingAspNetCore.Identity.Mongo.Model;// At the ConfigureServices section in Startup.csservices.AddIdentityMongoDbProvider<MongoUser>(identity=>{identity.Password.RequiredLength=8;// other options},   mongo=>{mongo.ConnectionString="mongodb://127.0.0.1:27017/identity";// other options});

Using User and Role models:

usingAspNetCore.Identity.Mongo;usingAspNetCore.Identity.Mongo.Model;// At the ConfigureServices section in Startup.csservices.AddIdentityMongoDbProvider<MongoUser,MongoRole>(identity=>{identity.Password.RequiredLength=8;// other options},    mongo=>{mongo.ConnectionString="mongodb://127.0.0.1:27017/identity";// other options});

Using different type of the primary key (default isMongoDB.Bson.ObjectId):

usingAspNetCore.Identity.Mongo;usingAspNetCore.Identity.Mongo.Model;publicclassApplicationUser:MongoUser<string>{}publicclassApplicationRole:MongoRole<string>{}// At the ConfigureServices section in Startup.csservices.AddIdentityMongoDbProvider<ApplicationUser,ApplicationRole,string>(identity=>{identity.Password.RequiredLength=8;// other options},    mongo=>{mongo.ConnectionString="mongodb://127.0.0.1:27017/identity";// other options});

To add the stores only, use:

usingAspNetCore.Identity.Mongo;usingAspNetCore.Identity.Mongo.Model;// At the ConfigureServices section in Startup.csservices.AddIdentityCore<MongoUser>().AddRoles<MongoRole>().AddMongoDbStores<MongoUser,MongoRole,ObjectId>(mongo=>{mongo.ConnectionString="mongodb://127.0.0.1:27017/identity";// other options}).AddDefaultTokenProviders();

Migration from lower versions

New releases could/will have the breaking changes.

Folderdocs contains migration guides. E.g.:

There you can find information how to migrate from 6.0.0-6.3.5 to 6.7.x version.
There you can find information how to migrate from 3.1.5 to 6.7.x version.

If you have different version of the library and want to update it, please create a new issue. We will try to help you or will create new instruction.

How to Contribute

Before create any issue/PR please look at theCONTRIBUTING

Code of conduct

SeeCODE_OF_CONDUCT

License

This project is licensed under theMIT license


[8]ページ先頭

©2009-2025 Movatter.jp