我使用兩個應用程式作為客戶端實作了單點登錄 (SSO)。我希望用戶通過 SSO 應用程式在第一個應用程式中進行身份驗證,而在第二個應用程式中不需要再次登錄和身份驗證。(共享身份驗證 cookie)。
資訊:
localhost:44372 => SSO
localhost:44387 => SSO Client_1
localhost:44382 => SSO Client_2
All Projects are ASP.NET 5
單點登錄專案代碼:
啟動.cs:
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(Config.GetIndentityResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(TestUsers.Users);
}
組態檔:
public class Config
{
public static IEnumerable<IdentityResource> GetIndentityResources()
{
//...
}
public static IEnumerable<Client> GetClients()
{
return new List<Client>()
{
new Client()
{
ClientId = "Client_1",
ClientName = "SSO Application",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris = {"https://localhost:44387/signin-oidc"},
PostLogoutRedirectUris = {"https://localhost:44387/signout-callback-oidc"},
AllowedScopes = new List<string>()
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
}
},
new Client()
{
ClientId = "Client_2",
ClientName = "SSO Application 2",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris = {"https://localhost:44382/signin-oidc"},
PostLogoutRedirectUris = {"https://localhost:44382/signout-callback-oidc"},
AllowedScopes = new List<string>()
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
}
}
};
}
}
如何在客戶端之間共享身份驗證?
uj5u.com熱心網友回復:
IdentityServer 中的 SSO 不是通過共享 cookie 來實作的,而是通過將 Client 授權委托給 IdentityServer 來實作的。您的客戶端應用程式應使用授權端點通過 SSO 進行授權。您還需要考慮使用 authorization_code grant_type https://medium.com/oauth-2/why-you-should-stop-using-the-oauth-implicit-grant-2436ced1c926
uj5u.com熱心網友回復:
Cookie 共享與 Identityserver、OpenId Connect 或任何其他 SSO 技術無關。它是關于服務器托管的應用程式,例如 ASP.NET(Core)MVC 或任何其他類似的應用程式。
身份驗證 cookie 系結到主機和可選路徑,因此當應用程式靠近在一起托管時沒有問題,但是 ASP.Net 將其身份驗證令牌保留在 cookie 中,并且令牌通常系結到 OIdC 會話,因此答案應該是:
當您想在 ASP.NET 中共享 cookie 時,您很可能不需要 OIdC 中的兩個單獨的客戶端
一種選擇是具有兩個應用程式重定向 URL 的單一身份客戶端,另一種選擇是將您的兩個應用程式合二為一并使用內部路由進行分離。
最后可能是因為您誤解了單點登錄的概念。它專為滿足您的要求而設計:用戶登錄一次即可訪問多個應用程式。它不需要共享任何東西,每個唯一的客戶端都獲得自己的身份驗證令牌(以及可選的多個授權令牌以訪問 API)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/371309.html
標籤:asp.net核心 饼干 单点登录 身份服务器4 asp.net5
