gpt4 book ai didi

c# - Asp.net Core 2 使用 Identity Server 4 启用 Multi-Tenancy

转载 作者:太空狗 更新时间:2023-10-30 01:13:11 28 4
gpt4 key购买 nike

我有一个 IDP (Identity Server 4) 托管多个绑定(bind):auth.company1.com 和 auth.company2.com我还有一个 API 受到该 IDP 的保护。因此,为了访问 API,我需要从 IDP 获取访问 token 。这是在 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 验证访问 token 并为每个租户提供不同的端点(我需要它为每个租户显示不同的登录屏幕)。

希望它能帮助那里的人:)

关于c# - Asp.net Core 2 使用 Identity Server 4 启用 Multi-Tenancy ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51231697/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com