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

吉姆·赫尔夏尼

我有一个托管有多个绑定的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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

带有ASP.NET Core 2.2的Identity Server 4

ASP .NET Core MVC部署到Azure Identity Server 4

使用 Asp.net Core 2.1 和 Identity Server 4 的身份验证/授权

如何使用Identity Server 4保护Asp.net Core 2.1和Vue.js单页应用程序

ASP.NET Identity 与 ASP.NET Identity Core:与 Identity Server 等的区别和用法?

使用单个回调URL的多租户应用程序的ASP.NET Core Google Auth?

使用路由配置在多租户环境中检查ASP.NET Core Health

Identity Server 4(2.0)无法读取Asp.Net Core身份cookie

如何在ASP.NET MVC Core中为Identity Server 4编写集成测试

Identity Server 4 与 ASP.NET Core MVC 进行身份验证然后调用 Angular SPA

在 Identity Server ASP.NET Core 中获取 accessToken

ASP.NET Core 2.0+中的多租户

asp.net core 的多租户登录问题

使用ASP.NET Identity v2的Thinktecture Identity Server v2

使用运行Identity Server 4的ASP.NET CORE 3身份验证服务器对ASP.NET MVC 5应用(目标.net 4.5)进行身份验证

Hangfire-多租户,ASP.NET Core-解决正确的租户

带有ASP.NET Core 3.0和EF Core的多租户应用程序

ASP.NET Core Web API客户端不信任Identity Server实例使用的自签名证书

配置 ASP.NET MVC 4 Web 应用程序以使用 Identity Server 4

.Net Core自定义身份验证,使用带有Identity Server 4的API密钥

登录Identity Server 4-.Net Core 2.2

Identity Server 4 .Net Core 2.0:多种认证类型

使用ASP.NET Core Identity 3的用户角色权限

使用Identity Core的ASP.NET MVC框架中的身份

使用FindByIdAsync时取消了ASP.Net Core Identity

使用 Asp.Net Core Identity 添加持久声明

使用ASP.NET Core和JQuery启用防伪令牌

如何使用ASP.NET Identity设置Thinktecture Identity Server v3 beta 1-2?

Identity Server 4 ASP.NET快速入门“拒绝连接”