小编Fra*_*sky的帖子

多租户身份服务器4

我正在尝试实现为多租户应用程序处理SSO的IdentityServer。我们的系统将只有一个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);
                };
            });
}
Run Code Online (Sandbox Code Playgroud)

对于身份服务器,使用具有ASP.NET Core身份的IdentityServer4。为了处理多租户客户端身份验证,我按照本文中Scott Brady针对ASP.NET Identity给出的说明进行操作:https : //www.scottbrady91.com/ASPNET-Identity/Quick-and-Easy-ASPNET-Identity-Multitenancy …

c# multi-tenant asp.net-core identityserver4 asp.net-core-identity

7
推荐指数
1
解决办法
2419
查看次数