All Projects → alexandre-spieser → Aspnetcore.identity.mongodbcore

alexandre-spieser / Aspnetcore.identity.mongodbcore

Licence: mit
A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.2. Allows you to use MongoDb instead of SQL server with Microsoft.AspNetCore.Identity 2.2. (not Identity 3.0)

Projects that are alternatives of or similar to Aspnetcore.identity.mongodbcore

Aspnetcore.identity.mongo
This is a MongoDB provider for the ASP.NET Core 2 Identity framework
Stars: ✭ 179 (+51.69%)
Mutual labels:  mongodb, asp-net-core, aspnetcore, identity
Aspnetcore.identity.mongodb
MongoDB Data Store Adaptor for ASP.NET Core Identity
Stars: ✭ 210 (+77.97%)
Mutual labels:  mongodb, aspnetcore, identity
Jpproject.identityserver4.adminui
🔧 ASP.NET Core 3 & Angular 8 Administration Panel for 💞IdentityServer4 and ASP.NET Core Identity
Stars: ✭ 717 (+507.63%)
Mutual labels:  asp-net-core, aspnetcore, identity
Znetcs.aspnetcore.authentication.basic
A simple basic authentication middleware.
Stars: ✭ 40 (-66.1%)
Mutual labels:  asp-net-core, aspnetcore
Awesome Microservices Netcore
💎 A collection of awesome training series, articles, videos, books, courses, sample projects, and tools for Microservices in .NET Core
Stars: ✭ 865 (+633.05%)
Mutual labels:  asp-net-core, aspnetcore
Litecodecore
基于asp.net Core 基础权限系统
Stars: ✭ 13 (-88.98%)
Mutual labels:  asp-net-core, aspnetcore
Aspnetcore2cookieauthentication
Cookie Authentication without ASP.NET Core Identity 3.x
Stars: ✭ 19 (-83.9%)
Mutual labels:  asp-net-core, identity
Aspnetcore.identity.documentdb
A Cosmos DB / DocumentDB Storage Provider for ASP.NET Core Identity
Stars: ✭ 64 (-45.76%)
Mutual labels:  aspnetcore, identity
Ravendb.identity
RavenDB Identity provider for ASP.NET Core. Let RavenDB manage your users and logins.
Stars: ✭ 50 (-57.63%)
Mutual labels:  asp-net-core, identity
Cierge
🗝️ Passwordless OIDC authentication done right
Stars: ✭ 1,245 (+955.08%)
Mutual labels:  asp-net-core, identity
Docker Series
Docker Series about containerizing ASP.NET Core app with MySQL..
Stars: ✭ 88 (-25.42%)
Mutual labels:  asp-net-core, aspnetcore
Csla
A home for your business logic in any .NET application.
Stars: ✭ 865 (+633.05%)
Mutual labels:  asp-net-core, aspnetcore
Znetcs.aspnetcore.logging.entityframeworkcore
This is Entity Framework Core logger and logger provider. A small package to allow store logs in any data store using Entity Framework Core.
Stars: ✭ 24 (-79.66%)
Mutual labels:  asp-net-core, aspnetcore
Aspnetcore Tests Sample
A project to help demonstrate how to do unit, integration and acceptance tests with an web api project using ASP.NET Core and Angular 7 front end.
Stars: ✭ 40 (-66.1%)
Mutual labels:  asp-net-core, aspnetcore
Identity.redis
ASP.NET Identity Redis Provider
Stars: ✭ 22 (-81.36%)
Mutual labels:  asp-net-core, identity
Aspnetcoreid4external
external OpenID Connect Login to IdentityServer4 with AAD
Stars: ✭ 63 (-46.61%)
Mutual labels:  asp-net-core, identity
Greatwall
Util应用框架配套的权限管理系统
Stars: ✭ 88 (-25.42%)
Mutual labels:  aspnetcore, identity
Gitserver
ASP.NET Core Git HTTP Server
Stars: ✭ 98 (-16.95%)
Mutual labels:  asp-net-core, aspnetcore
Squidex
Headless CMS and Content Managment Hub
Stars: ✭ 1,583 (+1241.53%)
Mutual labels:  mongodb, asp-net-core
Jwtsecurity
JWT Server for Asp.Net Core and Asp.Net WebAPI2
Stars: ✭ 16 (-86.44%)
Mutual labels:  asp-net-core, aspnetcore

AspNetCore.Identity.MongoDbCore

A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0 and 3.1. Allows you to use MongoDb instead of SQL server with Microsoft.AspNetCore.Identity 2.0 and 3.1.

Covered by 737 integration tests and unit tests from the modified Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test test suite.

Supports both netstandard2.1 and netcoreapp3.1.

Available as a Nuget package : https://www.nuget.org/packages/AspNetCore.Identity.MongoDbCore/

Install-Package AspNetCore.Identity.MongoDbCore

Support This Project

If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying Alex a coffee: Buy Me A Coffee

User and Role Entities

Your user and role entities must inherit from MongoIdentityUser<TKey> and MongoIdentityRole<TKey> in a way similar to the IdentityUser<TKey> and the IdentityRole<TKey> in Microsoft.AspNetCore.Identity, where TKey is the type of the primary key of your document.

Here is an example:

public class ApplicationUser : MongoIdentityUser<Guid>
{
	public ApplicationUser() : base()
	{
	}

	public ApplicationUser(string userName, string email) : base(userName, email)
	{
	}
}

public class ApplicationRole : MongoIdentityRole<Guid>
{
	public ApplicationRole() : base()
	{
	}

	public ApplicationRole(string roleName) : base(roleName)
	{
	}
}	

Id Fields

The Id field is automatically set at instantiation, this also applies to users inheriting from MongoIdentityUser<int>, where a random integer is assigned to the Id. It is however not advised to rely on such random mechanism to set the primary key of your document. Using documents inheriting from MongoIdentityRole and MongoIdentityUser, which both use the Guid type for primary keys, is recommended. MongoDB ObjectIds can optionally be used in lieu of GUIDs by passing a key type of MongoDB.Bson.ObjectId, e.g. public class ApplicationUser : MongoIdentityUser<ObjectId>.

Collection Names

MongoDB collection names are set to the plural camel case version of the entity class name, e.g. ApplicationUser becomes applicationUsers. To override this behavior apply the CollectionName attribute from the MongoDbGenericRepository nuget package:

using MongoDbGenericRepository.Attributes;

namespace App.Entities
{
    // Name this collection Users
    [CollectionName("Users")]
    public class ApplicationUser : MongoIdentityUser<Guid>
    {
	...

Configuration

To add the stores, you can use the IdentityBuilder extension like so:

services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>
	(
		"mongodb://localhost:27017",
		"MongoDbTests"
	)
	.AddDefaultTokenProviders();

It is also possible to share a common IMongoDbContext across your services (requires https://www.nuget.org/packages/MongoDbGenericRepository/):

var mongoDbContext = new MongoDbContext("mongodb://localhost:27017", "MongoDbTests");
services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<IMongoDbContext>(mongoDbContext)
	.AddDefaultTokenProviders();
// Use the mongoDbContext for other things.

You can also use the more explicit type declaration:

var mongoDbContext = new MongoDbContext("mongodb://localhost:27017", "MongoDbTests");
services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>(mongoDbContext)
	.AddDefaultTokenProviders();
// Use the mongoDbContext for other things.

Alternatively a full configuration can be done by populating a MongoDbIdentityConfiguration object, which can have an IdentityOptionsAction property set to an action you want to perform against the IdentityOptions (Action<IdentityOptions>).

The MongoDbSettings object is used to set MongoDb Settings using the ConnectionString and the DatabaseName properties.

The MongoDb connection is managed using the mongodb-generic-repository, where a repository inheriting IBaseMongoRepository is registered as a singleton. Look at the ServiceCollectionExtension.cs file for more details.

var mongoDbIdentityConfiguration = new MongoDbIdentityConfiguration
{
	MongoDbSettings = new MongoDbSettings
	{
		ConnectionString = "mongodb://localhost:27017",
		DatabaseName = "MongoDbTests"
	},
	IdentityOptionsAction = options =>
	{
		options.Password.RequireDigit = false;
		options.Password.RequiredLength = 8;
		options.Password.RequireNonAlphanumeric = false;
		options.Password.RequireUppercase = false;
		options.Password.RequireLowercase = false;

		// Lockout settings
		options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
		options.Lockout.MaxFailedAccessAttempts = 10;

		// ApplicationUser settings
		options.User.RequireUniqueEmail = true;
		options.User.AllowedUserNameCharacters = "[email protected]-_";
	}
};
services.ConfigureMongoDbIdentity<ApplicationUser, ApplicationRole, Guid>(mongoDbIdentityConfiguration)
        .AddDefaultTokenProviders();

Running the tests

To run the tests, you need a local MongoDb server in default configuration (listening to localhost:27017). Create a database named MongoDbTests for the tests to run.

Author

Alexandre Spieser

License

AspNetCore.Identity.MongoDbCore is under MIT license - http://www.opensource.org/licenses/mit-license.php

The MIT License (MIT)

Copyright (c) 2016-2021 Alexandre Spieser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright

Copyright © 2021

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].