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.3k stars 265 forks source link

WithPerTenantOptions OpenIdConnectOptions.Events not called #302

Closed PatrickBorkowicz closed 4 years ago

PatrickBorkowicz commented 4 years ago

Not sure if this is an issue or not, but going directly from the AuthenticationOptions sample, if I add the following:

.WithPerTenantOptions<OpenIdConnectOptions>((options, tenantInfo) =>
{
    options.Events = new OpenIdConnectEvents
    {
        OnRedirectToIdentityProvider = context =>
        {
            // Pass TenantId to IdentityServer.
            context.ProtocolMessage.AcrValues = $"tenant:{tenantInfo.Id}";
            return Task.CompletedTask;
        }
    };
}                 

The OnRedirectToIdentityProvider event handler is never called. It does work as expected if I add it directly to services.AddAuthentication().AddOpenIdConnect() but then I don't have access to the TenantInfo. Is the event handler being overridden somewhere upstream?

Basically I am just trying to pass the tenant Id to my OIDC provider (IdentityServer4) so it can redirect the user to the appropriate external provider. Maybe there is a better way to implement this.

Using .NET Core 3.1. and v5.0.4 of Finbuckle.MultiTenant.

Thank you.

AndrewTriesToCode commented 4 years ago

Hi I’d be happy to take a look. Do you have a github repo with your project I can look at, or can you post your StartupClass?

Also do any per tenant options work for you?

PatrickBorkowicz commented 4 years ago

Hi @AndrewTriesToCode . I created a stripped down sample project to isolate the issue. Annoyingly (although mercifully) the demo works without issue.

After comparing it to my main project I was able to get it to work as well, although I am not certain which tweak fixed it. I will have to look closer. At any rate this is not an issue with Finbuckle.MultiTenant, so I will close this.

Thank you again for your help! Cheers.