我有一个托管有多个绑定的IDP(身份服务器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可以验证访问令牌,并且每个租户都具有不同的终结点(我需要这样做才能为每个租户显示不同的登录屏幕)。
希望它可以帮助某人:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句