【问题标题】:Add Owin Pipeline Middleware after OwinStartup for new Tenant在 OwinStartup 之后为新租户添加 Owin 管道中间件
【发布时间】:2015-05-11 09:11:50
【问题描述】:

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

 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);

    ...
}

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

问题是当新租户注册时,我如何访问IAppBuilder 并添加新的AuthenticationOptions 而无需应用程序池回收?

【问题讨论】:

  • 有趣的设置。我也需要这样的东西。你能提供更多关于context.Authentication.Challenge(AuthenticationType)的代码吗?代码如何知道使用哪个OpenIdConnectTenantOption

标签: c# asp.net-mvc owin ws-federation openid-connect


【解决方案1】:

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

【讨论】:

  • 感谢@Tratcher。虽然不是好消息。无论如何,在启动之外做我需要的事情吗?还是可以修改请求执行管道,即使不是这样设计的?我可以通过context.Authentication.Challenge(AuthenticationType) 提供AuthenticationOptions 吗?托管应用程序如何应对希望使用自己的 ADFS 服务器进行身份验证而不修改管道的新租户?谢谢!
  • 这些实现不是为多租户设计的。我建议您不要尝试将数十个单租户组件堆叠到您的应用程序中,而是将代码分叉并将您的多租户需求直接构建到中间件中。这应该使您能够按需添加和删除租户,而无需累积检查每个请求的如此多组件的开销。
  • 感谢@Tratcher。我认为这可能是我们需要走的路。很高兴得到确认。再次感谢您!
  • 这里是稍后插入中间件的解决方法:github.com/Tratcher/MiddlewareInjector
猜你喜欢
  • 2016-11-02
  • 2016-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-13
  • 2014-03-10
  • 2015-04-05
  • 1970-01-01
相关资源
最近更新 更多