How to implement Multi-tenant User Login using ASP.NET Identity

asp.net-identity entity-framework-6 multi-tenant

Question

I want to use the most recent Identity in ASP.NET framework, specifically the Enterprise Framework implementation, because I'm working on a multi-tenant solution.

I basically need to allow for the sharing of usernames amongst users, however they must be distinct inside a tenant. I also want to use third-party sign-ins like Twitter, Microsoft, Facebook, and Google.

The framework does appear to allow expansion, but as far as I can tell, multi-tenancy was not considered when it was built. Although I'd want to use as many pre-existing components as I can, I currently believe I will have to forgo the Enterprise Framework implementation and write all of the code from scratch.

Has anyone else attempted this, and how much of the coding was done by them?

1
25
11/7/2014 7:33:42 AM

Accepted Answer

Currently, I have a functional fix, which I've provided in a GitHub repository:

https://github.com/JSkimming/AspNet.Identity.EntityFramework.Multitenant

The 1.0.0 release of Microsoft.AspNet.Identity.EntityFramework does not have the extensibility needed to allow multi-tenancy (at least not without a lot of special effort), but the 1.1 alpha release, which is now accessible through the NuGet packages for the nightly ASP.NET Web Stack, does.

Since my creation currently requires the NuGet packages for the nightly ASP.NET Web Stack, I've chosen to make it available as a NuGet package, AspNet.Identity.EntityFramework.Multitenant.

Two straightforward sites that utilize the package to support multi-tenancy are offered by me:

  1. The default MVC5 template project utilizes string primary keys, and its ID is Vanilla Execution.
    • The modifications required to support multi-tenancy have only been made in this commit.
  2. Implementation of the Integer Primary Key, which is modifying the software a little bit more to use integer primary keys
    • The modifications required to offer multi-tenancy have only been made in this commit.

As soon as ASP.NET Identity version 1.1 is made available, I want to update the solution.

I sincerely hope that others may find some use for the nuget package I've made available; any input is greatly appreciated.


Update

Now that Microsoft.AspNet.Identity.EntityFramework 2.0 has been released, the solution has been changed to use it.

27
8/28/2014 10:09:30 AM

Popular Answer

Yes, we left this as an extensibility case on purpose. This should be possible by creating your own unique IUserStore and overriding UserManager attributes. However, you might be able to just add a tenantId to your user and extend the EF UserStore.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow