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.29k stars 264 forks source link

Support multiple identifiers for a tenant #301

Open jasonchester opened 4 years ago

jasonchester commented 4 years ago

We have a mobile application which needs to retrieve tenant information in order to present the correct login experience.

The requirement from the business is to let the user supply their email address which will be compared against a list of email domains for a specific tenant. in order to achieve this I would like to be able to specify multiple identifiers which would map to a tenant.

"Tenants": [
  {
    "Id": "93f330717e5d4f039cd05da312d559cc",
    "Identifier": "megacorp",
    "Identifiers": ["mega.com", "mc.com"],
    "Name": "MegaCorp",
    "ChallengeScheme": "Cookies"
  }
]

It wasn't too hard with a custom configuration store with an updated method but this seems like a common enough scenario that it would be nice if it was supported by the framework.

        private void UpdateTenantMap()
        {
            var newMap = new ConcurrentDictionary<string, SampleTenantInfo>(StringComparer.OrdinalIgnoreCase);
            var tenants = section.GetSection("Tenants").GetChildren();

            foreach(var tenantSection in tenants)
            {
                var newTenant = section.GetSection("Defaults").Get<SampleTenantInfo>((options => options.BindNonPublicProperties = true));
                tenantSection.Bind(newTenant, options => options.BindNonPublicProperties = true);
                newMap.TryAdd(newTenant.Identifier, newTenant);
                foreach(var ident in newTenant.Identifiers)
                {
                    newMap.TryAdd(ident, newTenant);
                }
            }

            var oldMap = tenantMap;
            tenantMap = newMap;
        }
AndrewTriesToCode commented 4 years ago

Hi @jasonchester

I'm glad you figured out a working solution. I'm not sure if you saw it but the "SharedLoginSample" project does something similar. I agree this would be a good enhancement. Maybe something like "Tenant Aliases". I've pinned it to keep the issue from auto-closing.

Thanks for the suggestion!

ChrisComply commented 10 months ago

I would also like this feature. You can image a scenario like using hosting strategy .WithHostStrategy("__tenant__")

and wanting to have the TenantId being the same for: clientName.MySaaSAppDomain.com clientName.com

Having the ability to have multiple identifiers point to the same tenantid out of the box would be very nice.