简体   繁体   English

使用IdentityServer4的子域多租户登录

[英]Sub domain Multi Tenant login with IdentityServer4

i'm trying to implement multi tenant application with identityserver4 let's say i have 我正在尝试使用Identityserver4实现多租户应用程序

  • web1.local.com web1.local.com
  • web2.local.com web2.local.com

when i logged in to web1.local.com other domain which is web2.local.com also automatically logged in. 当我登录到web1.local.com时,另一个域名为web2.local.com也会自动登录。

is there anyway to separate these logins? 无论如何有分开这些登录?

i was thinking to have custom implementation of IUserSession 我当时想对IUserSession进行自定义实现

public virtual async Task CreateSessionIdAsync(ClaimsPrincipal principal, AuthenticationProperties properties)
{
    if (principal == null) throw new ArgumentNullException(nameof(principal));
    if (properties == null) throw new ArgumentNullException(nameof(properties));

    var currentSubjectId = (await GetUserAsync())?.GetSubjectId();
    var newSubjectId = principal.GetSubjectId();

    if (!properties.Items.ContainsKey(SessionIdKey) || currentSubjectId != newSubjectId)
    {
        properties.Items[SessionIdKey] = CryptoRandom.CreateUniqueId(16);
    }

    IssueSessionIdCookie(properties.Items[SessionIdKey]);

    Principal = principal;
    Properties = properties;
}

private void IssueSessionIdCookie(string sid)
{
    if (Options.Endpoints.EnableCheckSessionEndpoint)
    {
        if (GetSessionIdCookieValue() != sid)
        {
            HttpContext.Response.Cookies.Append(
                Options.Authentication.CheckSessionCookieName,
                sid,
                CreateSessionIdCookieOptions());
        }
    }
}

what is the best approach ? 最好的方法是什么?

I believe the problem you are having is that once the session cookie is issued by IdentityServer regardless of which application was originally used to sign in, IdentityServer will always skip the login on subsequent requests from any other applications (because of that originally administered session cookie). 我相信您遇到的问题是,无论最初使用哪个应用程序登录,IdentityServer发出会话cookie后,IdentityServer都会始终跳过来自其他任何应用程序的后续请求的登录(由于该最初管理的会话cookie) 。

To always force the authentication between different applications, you can use the 'prompt' query string on the authorize request and set it equal to 'login'. 要始终在不同应用程序之间强制进行身份验证,可以在授权请求上使用“提示”查询字符串,并将其设置为等于“登录”。 More information can be found here: http://docs.identityserver.io/en/latest/endpoints/authorize.html?highlight=prompt 可以在这里找到更多信息: http : //docs.identityserver.io/en/latest/endpoints/authorize.html?highlight=prompt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM