【问题标题】:Multitenant Identity Server 4多租户身份服务器 4
【发布时间】:2018-07-01 06:07:56
【问题描述】:

我正在尝试实现一个 IdentityServer 来处理多租户应用程序的 SSO。 我们的系统将只有一个 IdentityServer4 实例来处理多租户客户端的身份验证。

在客户端,我使用acr_value 来传递租户 ID。 Startup.cs 文件中的一段代码如下:

public void ConfigureServices(IServiceCollection services)
{
        services.AddMvc();
        services.AddAuthorization();

        services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;
                options.ClientId = "Client1";
                options.ClientSecret = "secret";
                options.ResponseType = "code id_token";
                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;                    
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("offline_access");
                options.Events.OnRedirectToIdentityProvider = n =>
                {
                    if (n.ProtocolMessage.RequestType == 
                          OpenIdConnectRequestType.Authentication)
                    {
                        n.ProtocolMessage.AcrValues = "tenant:clientId1";
                    }
                    return Task.FromResult(0);
                };
            });
}

对于身份服务器,使用带有 ASP.NET Core Identity 的 IdentityServer4。为了处理多租户客户端身份验证,我遵循了 Scott Brady 在这篇文章中针对 ASP.NET Identity 给出的说明: https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy

我修改了 UserStore 以接收租户 ID,但在为 AccountController 注入 UserStore 实例的那一刻,我无法检索传递的acr_value

以前有人遇到过这个问题吗?

【问题讨论】:

  • 或许这篇文章可以帮到你:leastprivilege.com/2017/11/15/…
  • 感谢您的建议。本文旨在将声明 acr 从端点传递给客户端。我正在做相反的事情,将 acr 传递给服务器端点并验证此 acr 租户值的用户是否存在
  • 如果你在这方面取得了任何进展,那就随便看看吧。您是想为每个租户使用不同的.well-known/openid-configuration 还是只有一个?另外,为什么在UserStore 中需要tenantId,您可以创建一个覆盖CanSignInAsync(ApplicationUser user) 的自定义ApplicationSignInManager 并将其传递给AccountController Login,如下所示:var context = await _interaction.GetAuthorizationContextAsync(returnUrl); _signInManager.ClientId = context?.Tenant; 但是,您如何通过这种方法管理退出一个租户而不退出其他租户?
  • @Ovi 正是我猜想即使用户登录其他租户并尝试登录受限租户时也会出现此问题,因为 idsrv sso 会查看 cookie 并绕过身份验证。所以注销也会产生影响。我相信通过这种方法,我们需要创建一个基于租户的 cookie,以便它们在租户级别被隔离。
  • 酷@Jay!关于如何在 aspnetcore 2 中创建基于租户的 cookie 的任何示例?

标签: c# asp.net-core identityserver4 multi-tenant asp.net-core-identity


【解决方案1】:

如果你还没有弄清楚,这里是解决方案

private readonly IIdentityServerInteractionService _interaction;


 var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);
            var tenant = context.Tenant;

【讨论】:

  • 我不知道该把代码放在哪里。它只是没有任何上下文的代码。
  • @Fred 那是因为您还没有查看制作 IS4 服务器所需的基本代码。 IIdentityServerInteractionService 通常用于控制器中... github.com/IdentityServer/IdentityServer4/blob/main/src/…
  • @Fred 该代码可用于您想知道传入请求租户 ID 的任何服务。也可以使用 HttpContext 服务来提取请求 URL
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-15
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
相关资源
最近更新 更多