【发布时间】: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并将其传递给AccountControllerLogin,如下所示: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