AspNet.Identity.EntityFramework.Multitenant

by JSkimming

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

125 Stars 63 Forks Last release: over 5 years ago (v1.2.1) Apache License 2.0 52 Commits 7 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

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
    and
    MultitenantIdentityUserLogin
    if you want custom
    TenantId
    .

The

UserStore
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
for more details.

Lastly the

IdentityDbContext
has been extended to add the necessary validation and model creation to implement multi-tenancy. See the
MultitenantIdentityDbContext
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.
  2. 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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.