繁体   English   中英

Asp.net Core 2使用Identity Server 4实现多租户

[英]Asp.net Core 2 enable multi tenancy using Identity Server 4

我有一个托管有多个绑定的IDP(Identity Server 4):auth.company1.com和auth.company2.com我还有一个受该IDP保护的API。 因此,为了访问API,我需要从IDP获取访问令牌。 这是在API级别的启动类中配置的,如下所示:

     services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = "https://auth.company1.com/";
                options.RequireHttpsMetadata = true;
                options.ApiName = "atb_api";
            });

如何配置options.Authority动态,以便它允许来自多个域的权限https://auth.company1.com/https://auth.company2.com/

我解决了这个问题

在启动类的保护API级别,我有这样的配置:

services.AddAuthentication("Bearer")
        .AddIdentityServerAuthentication(options =>
        {
            options.Authority = "https://shared-domain-for-every-tenant/";
            options.RequireHttpsMetadata = true;
            options.ApiName = "atb_api";
        });

神奇的发生在IDP级别(IdentityServer4),配置IdentityServer时,我添加选项IssuerUri,如下所示:

services.AddIdentityServer(options => {
            options.IssuerUri = "https://shared-domain-for-every-tenant/";
        })..AddDeveloperSigningCredential() ...other configurations ...

当我导航到https://auth.company1.com/.well-known/openid-configuration时 ,返回的文档如下所示:

  {
    "issuer": "https://shared-domain-for-every-tenant/",
    "jwks_uri": "https://auth.company1.com/.well-known/openid-configuration/jwks",
    "authorization_endpoint": "https://auth.company1.com/connect/authorize",
    "token_endpoint": "https://auth.company1.com/connect/token",
    "userinfo_endpoint": "https://auth.company1.com/connect/userinfo",
    ...
  }

请注意,issure是一个静态URL,而所有其他端点都是特定于发出请求的租户。 这允许API验证访问令牌,并且每个租户也有不同的端点(我需要它为每个租户显示不同的登录屏幕)。

希望它可以帮助那里的人:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM