I'd like to support multi-tenancy in my web api app that uses Identity Framework for authentication. I plan to have a single site and a single database with multiple tenants having multiple users. I'd be happy with prefixing user names with tenant id for login purposes and then strip it when returning it to the client app.
However, I'm not sure how to 'intercept' the user login. That is, where would I implement prefixing user names with tenant ids before they are passed to the framework for authentication.
Can someone please let me know how to deal with the above. A small example and pointers to on-line docs would be appreaciated.
Thanks.
Here there is a solution by Scott Brady, you can read explanation there i just write code here with a bit of updates.
Solution:
Add a new property to your user to determine tenants.
public class ApplicationUser : IdentityUser { public int TenantId { get; set; } }
Then you need to customize your
UserStore
to make it aware of your new user property.and also you need to customize
IdentityDbContext
to support multitenancy.And then you can create seprate user manager for each tenant like this:
User1:
User2:
Update:
and tenantId can be the Id of each tenant that signed up.