Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.33k stars 265 forks source link

Set the TenantInfo based on default user's default #869

Open abhishekp21 opened 2 months ago

abhishekp21 commented 2 months ago

I am working on project based on https://github.com/fullstackhero/dotnet-starter-kit

I have a scenario where user belongs to multiple tenants but I want to collect only the username and password on the login screen, without requiring tenant at that stage. Instead, I want to retrieve the user's default tenant from the UserManager (user table) and generate the token. However, since Finbuckle is implemented, it expects tenant information during the authentication process, which is leading to issues with token generation. Could you help me resolve this?

image image
AndrewTriesToCode commented 2 months ago

Hi, this is something I've done before and found it worked pretty well. I recommend using the regular IdentityDbContext with a many-to-many relationship between users and tenants rather than MultiTenantIdentityDbContext because then a single user cannot belong to multiple tenants as easily and also because you won't know the tenant yet when you need to use the db context.

Then I've stored the default tenant in a user claim or alternatively you could add it as a property on your custom user entity class.