Code Monkey home page Code Monkey logo

aspnet.identity.entityframework.multitenant's Introduction

ASP.NET Identity EntityFramework Multitenant

NuGet Version NuGet Downloads Build status Latest release

Multi-tenant support for ASP.NET Identity using Entity Framework

This library was created to solve a problem I asked on Stack Overflow, it was needed for a commercial project, this part has been open sourced in the hope that it may receive improvements and future support by receiving wider usage.

It is available to download as a NuGet package.

Additionally a Continious integration Build NuGet feed is also provided by AppVeyor https://ci.appveyor.com/nuget/aspnet-identity-entityframewor-avbe23sgoogy Add this feed to your NuGet Configuration Settings to include the CI build, which includes yet to be accepted pull requests.

How to use multi-tenancy

To use this library the TenantId property on the MultitenantUserStore needs to be set for the relevant tenant. How and when this is set is determined by the application.

Thereafter, the UserManager (which has a dependency on the UserStore) can be used and it will only find and update users for the specified tenant.

What has been multi-tenanted?

The intention is to provide a means to allow for identical users (uniquely keyed upon email/username/external login) to register and authenticate multiple times under different tenants, but still remaining unique within a tenant, all within the same database and entity context.

The two entities that have been extended to support multi tenancy are IdentityUser and IdentityUserLogin, both of which have had the TenantId property added.

Following the same patterns of Microsoft ASP.NET Identity EntityFramework there is both a generic and non generic equivalent proved:

  1. Use or extend MultitenantIdentityUser and MultitenantIdentityUserLogin if you want the TenantId to be a string
  2. Extend MultitenantIdentityUser<TKey, TTenantKey, TLogin, TRole, TClaim> and MultitenantIdentityUserLogin<TKey, TTenantKey> if you want custom TenantId.

The UserStore<TUser> has been extended to have a TenantId property and to override the necessary methods to implement multi-tenancy. The TenantId needs to be specified directly otherwise an InvalidOperationException will be thrown. See the MultitenantUserStore<TUser, TRole, TKey, TTenantKey, TUserLogin, TUserRole, TUserClaim> for more details.

Lastly the IdentityDbContext<TUser> has been extended to add the necessary validation and model creation to implement multi-tenancy. See the MultitenantIdentityDbContext<TUser, TRole, TKey, TTenantKey, TUserLogin, TUserRole, TUserClaim> for more details.

Example

Two simple sites that make use the package to allow for multi-tenancy are provided as example:

  1. Vanilla Implementation which is the standard MVC5 template project that uses a string primary keys.
  • The changes necessary to provide multi-tenancy have been isolated to this commit.
  1. Integer Primary Key Implementation which is making a few more customisations to use integer primary keys
  • The changes necessary to provide multi-tenancy have been isolated to this commit.

aspnet.identity.entityframework.multitenant's People

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.