Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Owin Pipeline Middleware after OwinStartup for new Tenant

I have a multi-tenant application where each tenant can define their own ClientID, Authority, etc for either WsFed or OpenIdConnect. All the tenants are registered in the OwinStartup as below:

 public void Configuration(IAppBuilder app)
 {
    List<WsFederationAuthenticationOptions> WsFedTenantOptions = BuildWsFedTenantOptionsList();
    List<OpenIdConnectAuthenticationOptions> OpenIdConnectTenantOptions = BuildOpenIdConnectTenantOptionsList();

    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    app.UseCookieAuthentication(new CookieAuthenticationOptions() { CookieSecure = CookieSecureOption.Never });

    foreach (var WsFedTenantOption in WsFedTenantOptions)
        app.UseWsFederationAuthentication(WsFedTenantOption);

    foreach (var OpenIdConnectTenantOption in OpenIdConnectTenantOptions)
        app.UseOpenIdConnectAuthentication(OpenIdConnectTenantOption);

    ...
}

It switches which STS to use via context.Authentication.Challenge(AuthenticationType). This is working really well.

The issue is that when a new tenant signs up, how do I access the IAppBuilder and add the new AuthenticationOptions without an Application Pool recycle?

like image 691
mgrowan Avatar asked Mar 10 '15 02:03

mgrowan


1 Answers

IAppBuilder does not exist after Startup, it is used to build the request execution pipeline and then discarded. The pipeline was not designed to be modified after Startup.

like image 140
Tratcher Avatar answered Nov 11 '22 08:11

Tratcher