多租户身份服务器 4

Multitenant Identity Server 4

我正在尝试实现一个 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 核心身份的 IdentityServer4。为了处理多租户客户端身份验证,我遵循了 Scott Brady 在 post 中针对 ASP.NET Identity 给出的说明: https://www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy

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

有没有人遇到过这个问题?

如果你还没有弄明白,这里是解决方案

private readonly IIdentityServerInteractionService _interaction;


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