我正在嘗試使用身份服務器4實現多租戶應用程序,假設我有web1.local.comweb2.local.com當我登錄到 web1.local.com 其他域時,web2.local.com 也會自動登錄。有沒有辦法將這些登錄名分開?我正在考慮有自定義實現IUserSessionpublic 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()); } }}什么是最好的方法?
1 回答

繁花不似錦
TA貢獻1851條經驗 獲得超4個贊
我相信您遇到的問題是,一旦會話cookie由IdentityServer發出,無論最初用于登錄哪個應用程序,IdentityServer將始終跳過來自任何其他應用程序的后續請求的登錄(因為最初管理的會話cookie)。
若要始終強制在不同應用程序之間進行身份驗證,可以在授權請求上使用“prompt”查詢字符串,并將其設置為等于“login”。更多信息可以在這里找到:http://docs.identityserver.io/en/latest/endpoints/authorize.html?highlight=prompt
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報
0/150
提交
取消