在OwinStartup之后为新租户添加Owin管道中间件

我有一个多租户应用程序,每个租户可以为WsFed或OpenIdConnect定义自己的ClientID,Authority等。 所有租户都在OwinStartup注册如下:

public void Configuration(IAppBuilder app) { List WsFedTenantOptions = BuildWsFedTenantOptionsList(); List 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); ... } 

它通过context.Authentication.Challenge(AuthenticationType)切换要使用的STS。 这工作得很好。

问题是当新租户注册时,如何在没有应用程序池回收的情况下访问IAppBuilder并添加新的AuthenticationOptions

启动后IAppBuilder不存在,它用于构建请求执行管道然后丢弃。 启动后,管道未设计为可修改。