我們的團隊在我們的 SP 中使用 Itfoxtec 作為 saml2 處理程式,如下所示:
- 客戶端單擊登錄 API 的鏈接。
- API 將用戶重定向到 IdP 登錄頁面。
- 成功登錄后,API 會收到對 ASC 路由的 SAML2 回應。
- 我們從回應中獲取宣告。
- 如果用戶準備好,我們會生成一個 JWT 令牌,用于使用 Authorization 標頭對其他服務的下一個請求,否則我們會發送未經授權的回應。
這是處理程式的配置:
builder.Services
.AddAuthentication("saml2")
.AddCookie("saml2", cookieAuthenticationOptions =>
{
cookieAuthenticationOptions.SlidingExpiration = true;
cookieAuthenticationOptions.LoginPath = new PathString("/saml/request");
cookieAuthenticationOptions.Cookie.SameSite = SameSiteMode.None;
cookieAuthenticationOptions.Cookie.SecurePolicy = CookieSecurePolicy.Always;
Task UnAuthorizedResponse(RedirectContext<CookieAuthenticationOptions> context) =>
Task.FromResult(context.Response.StatusCode = (int)HttpStatusCode.Unauthorized);
cookieAuthenticationOptions.Events.OnRedirectToAccessDenied = UnAuthorizedResponse;
cookieAuthenticationOptions.Events.OnRedirectToLogin = UnAuthorizedResponse;
});
正如我們所見,Itfoxtec 的使用僅在初始登錄程序中完成,用戶要么獲得未經授權的回應,要么獲得 JWT 令牌,并且沒有對 SP 進行額外的呼叫。
請注意,當我洗掉與 Cookie 相關的配置時,在獲取宣告并在以下行創建會話時會引發例外:
customClaims = await saml2AuthnResponse.CreateSession(HttpContext, claimsTransform: GetCustomClaimsPrincipal);
我們的問題是,有沒有其他方法可以將 Itfoxtec 用作 SAML2 處理程式但不使用 Cookie?
uj5u.com熱心網友回復:
您不需要使用會話 cookie。如果您不使用會話 cookie,則不應呼叫CreateSession創建基于 cookie 的 .NET 會話的方法。
SAML 2.0 Authn 請求在該Unbind方法中得到驗證,之后您可以安全地閱讀saml2AuthnResponse.ClaimsIdentity.Claims.
FoxID使用 ITfoxtec Identity SAML 2.0 組件而不使用基于 cookie 的 .NET 會話,您可以看到 SAML 2.0 Authn 請求如何在AuthnResponseAsync方法中進行驗證。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458737.html
標籤:C# 。网 单点登录 saml-2.0 itfoxtec-身份-saml2
上一篇:如何使BitArray只讀?
下一篇:遍歷C#MVC中的串列并訪問屬性
