Add Owin Pipeline Middleware after OwinStartup for

2019-05-03 10:50发布

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?

1条回答
家丑人穷心不美
2楼-- · 2019-05-03 11:30

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.

查看更多
登录 后发表回答