Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor - Shared login page with multi-tenant users #854

Open
Conway6288 opened this issue Jul 11, 2024 · 1 comment
Open

Blazor - Shared login page with multi-tenant users #854

Conway6288 opened this issue Jul 11, 2024 · 1 comment
Labels

Comments

@Conway6288
Copy link

Looking to create an application which has a single login page for all users. Each user will be assigned to at least one tenant but they can be assigned to multiple and would need to switch between them after logging in. Each tenant needs to be isolated so FinBuckle seems like the perfect solution.

Currently exploring the use of the Claims Strategy, with a user's available tenants being listed in a claim. This works out of the box with the claims strategy assuming there is only one tenant. I have also looked at using the base path strategy, but would still need to do an initial redirect after login to whatever the default tenant is deemed to be. If they change their active tenant, we would then need to redirect them to the current base path or somehow toggle that from the claim.

This has raised several questions:

  • Once logged in, how do you determine and select a default tenant if they have access to multiple?
  • What is the best practice for switching between the available tenants after logging in based on user interaction?
  • Is one strategy recommended over another with this scenario?

I had a look through previous discussions and found several old threads related to this:

That also led me to find the SharedLoginSample here.

Is there an updated example for the SharedLogin anywhere (Ideally for Blazor) or "hot swapping" between tenants after login?

Many thanks in advance, any help or advice appreciated.

@AndrewTriesToCode
Copy link
Sponsor Contributor

hi @Conway6288

I don't have a more up-to-date sample and it looks like you have found the relevant discussions and details. The main thing for this design is to not use MultiTenantIdentityDbContext but rather a normal one that also has an added entity for tenant and a many-to-many relationship between user to tenant and perhaps role to tenant. You can also use this dbcontext for your tenant store if you want. For a default tenant I just have that be a property on the user and when they sign on make that the starting tenant.

For the strategy, claim is ok but can get really tricky. I like the session strategy but that assumes a normal web app -- I'm not sure how well that plays with Blazor and api backends. In those situations I will end up using the host strategy with subdomains but that gets complicated with dns and SSL and other infrastructure. It all comes down to giving them a way to select from their list of tenants and adjusting your flows (Urls, headers, whatever) accordingly.

I'm sorry I don't have a better detailed response for you -- these are almost always more complex and have distinct requirements. Please share what you find works and doesn't work for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants