0

我们正在尝试为我们的产品使用奇妙的IdentityServer。您的应用程序应该能够与不同的租户一起工作,并且每个租户都可以拥有自己的身份提供者。用于多租户的多个OpenIdConnectAuthentication-Middlewares

的IdentityServer部分“可能”(它的工作原理,但我不知道这是否是超级聪明的)来解决这样的:

app.Map("/demotenant", (test) => 
     { 
      test.UseIdentityServer(new IdentityServerOptions 
      { 
       SiteName = "Embedded IdentityServer", 
       SigningCertificate = Certificate.Load(), 
       Factory = factory, 
       RequireSsl = false, 
       AuthenticationOptions = new AuthenticationOptions 
       { 
        EnableLocalLogin = false, 
        IdentityProviders = ConfigureIdentityProviders, 
       }, 
      }); 
     }); 

app.Map("/demotenant2", (test) => 
     { 
      test.UseIdentityServer(new IdentityServerOptions 
      { 
       SiteName = "Embedded IdentityServer", 
       SigningCertificate = Certificate.Load(), 
       Factory = factory, 
       RequireSsl = false, 
       AuthenticationOptions = new AuthenticationOptions 
       { 
        EnableLocalLogin = false, 
        IdentityProviders = ConfigureIdentityProviders, 
       }, 
      }); 
     }); 

现在我试图用这个从我的web应用。当我正在/ demotenant它应该使用/ demotenant身份服务器等

app.Map("/demotenant", (test) => 
{ 
    test.UseCookieAuthentication(new CookieAuthenticationOptions() 
    { 
     AuthenticationType = "cookies", 
    }); 
    test.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions() 
    { 
     AuthenticationType = "oidc", 
     SignInAsAuthenticationType = "cookies", 
     Authority = "http://localhost:63958/demotenant", 
     ClientId = "webapp", 
     RedirectUri = "http://localhost:57354/", 
     ResponseType = "id_token", 
     Scope = "openid", 
     Notifications = new OpenIdConnectAuthenticationNotifications 
     { 
      RedirectToIdentityProvider = async f => 
      { 
       f.ProtocolMessage.AcrValues = "datasourceId:test"; 
      }, 
     }, 
    }); 
}); 

app.Map("/demotenant2", (test) => 
{ 
    test.UseCookieAuthentication(new CookieAuthenticationOptions() 
    { 
     AuthenticationType = "cookies", 
    }); 

    test.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions() 
    { 
     AuthenticationType = "oidc", 
     SignInAsAuthenticationType = "cookies", 
     Authority = "http://localhost:63958/demotenant2", 
     ClientId = "webapp", 
     RedirectUri = "http://localhost:57354/", 
     ResponseType = "id_token", 
     Scope = "openid", 
     Notifications = new OpenIdConnectAuthenticationNotifications 
     { 
      RedirectToIdentityProvider = async f => 
      { 
       f.ProtocolMessage.AcrValues = "datasourceId:test"; 
      } 
     }, 
    }); 
}); 

遗憾的是它不工作,或者至少我不能触发认证流程。

我的“简单”示例只是使用[Authorize]属性,它将魔法重定向到我的IdentityServer。 所以问题是:
- 是否有可能基于路由触发其中一个authroization,如果是的话:如何?

回答

0

请注意,您不应该使用app.Map来路由到基于租户的身份提供者[IDP]。在IdentityServer中,您必须根据租户计算确切的IDP。然后,您可以对该特定的IDP进行挑战。

步骤

  1. 确定承租人
  2. 查找的IDP为租户
  3. 现在,从注册IDP的从Owin中间件,你将不得不调用的挑战。 4.将从已确定的承租人处解决保密问题的终端/客户端ID &。
  4. 这使得在多租户生产应用程序中没有租户特定路线的完全动态管线,我们不希望为每个新租户进行全新的部署更新。
  5. 例如,如果租户选择了社交身份提供商,loginmodel.Providers将包含所有登录选项,如Facebook,Google,Twitter等。
  6. 用户可以选择并单击登录。

解决端点代码示例的URI基于从OWIN中间件 OnDemandEndpoints = async (clientid, EndpointUriTypes) => { var endpointResolver = ServiceLocator.Resolve<IClientEndpointResolver>(); return await endpointResolver.ResolveEndpointUri(EndpointUriTypes, clientid); },

需要有一些情况下,可以在整个中间件携带您的租户环境租客,这样从端点分辨率为clientId和ClientSecrets可以动态解析。

希望这对你有所帮助