0

I have an ASP.NET Core application that does multi-tenanting based on the path. For example to log into tenant1 you would go do https://domain.name/tenant1 and to log in as tenant2 you would go do https://domain.name/tenant2. I have some middleware to get the tenant name from the request URI and pass that to the DbContext.

This works fine in normal use, but as an administator I can't log into more than one tenant at the same time because both of them store identity in the same .Aspnetcore.Identity.Application cookie for the same domain.

I know I can change the name of the cookie in Program.cs using

builder.Services.ConfigureApplicationCookie(options => options.Cookie.Name = "newcookiename")

but what I want to do is have it be different depending on the tenant, so tenant1's credentials would be stored in a .Aspnetcore.Identity.Application.tenant1 cookie and tenant2's credentials would be stored in a .Aspnetcore.Identity.Application.tenant2 cookie.

How can I do this?

2
  • I'm pretty sure CookieAuthenticationHandler is a singleton, so would only have a singleton instance of the options. IMHO write a custom AuthenticationHandler, call the cookie handler, check for admin users, then use the path to create a ticket for another Principal? Build an admin only page to switch users... Commented Sep 12 at 1:41
  • Not sure if this would work, but as you suggested, could you not create your own "custom" cookie(s) from the .Aspnetcore.Identity.Application cookie value? For example, an Administrator for tenant 1 might have a cookie called "tenant1_admin" and the same Administrator might also have a cookie called "tenant2_admin". The values from each of these cookies could then be used to set the .Aspnetcore.Identity.Application cookie value depending on the tenant selected by the Administrator (of course they would need to log in to each tenant in order to get the cookie value). Commented Sep 12 at 2:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.