[英]Custom attribute not passed into ID_TOKEN created by AWS Cognito
[英]Understanding the id_token flow from magic link
我有一個 SPA 應用程序,其核心后端為 .NET,使用 AD B2C。 SPA angular 前端使用angular-oauth2-oidc創建登錄流程。 樣本:
this.authConfig = {
redirectUri: this.envService.redirectUri,
responseType: this.envService.responseType,
issuer: this.envService.issuer,
:
clientId: this.envService.clientId,
scope: this.envService.scope,
skipIssuerCheck: true,
clearHashAfterLogin: true,
oidc: true,
logoutUrl: this.envService.logoutUrl,
showDebugInformation: true,
};
: this.oauthService.configure(this.authConfig);
this.oauthService.tokenValidationHandler = new NullValidationHandler();
const helper = new JwtHelperService();
let url = this.DiscoveryDocumentConfig.signInURL;
:
:
this.oauthService.loadDiscoveryDocument(url).then(() => {
this.oauthService.tryLoginImplicitFlow().then(() => {
if (!this.oauthService.hasValidAccessToken()) {
this.oauthService.initImplicitFlow();
現在我使用魔術鏈接登錄應用程序,魔術鏈接的策略提取聲明並發出 id_token(示例 - https://github.com/azure-ad-b2c/samples/tree/ master/policies/sign-in-with-magic-link )。 在這種情況下,我需要自己創建一個 session 還是 AD B2C 處理相同?
通過 id_token 訪問應用程序是否支持通過 msal 或 angular-oauth2-oidc?任何指針都會有所幫助。
謝謝
我認為有必要澄清一下。 首先,即使您使用魔術鏈接,Azure AD B2C 也會像您使用用戶名和密碼進行身份驗證一樣處理用戶的 session。 在這種情況下,您將 id_token_hint 傳遞給 Azure AD B2C(連同 state 參數),Azure AD B2C 驗證令牌,提取聲明並返回專用於您的應用程序的 ID 令牌。 AD B2C端創建用戶session。
我將MSAL.js與 Angular(我強烈推薦)一起使用,它會自動處理 session,但您也可以對其進行配置。 這是官方文檔中用於傳遞 id_token_hint 的片段:
還有一個重要的事實:
Azure Active Directory (Azure AD) 通過在用戶首次進行身份驗證時設置 session cookie 來啟用 SSO。 MSAL.js 還在每個應用程序域的瀏覽器存儲中緩存用戶的 ID 令牌和訪問令牌。 這兩種機制(即 Azure AD session cookie 和 MSAL 緩存)彼此獨立,但協同工作以提供 SSO 行為:
https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-js-sso
在這種情況下,msal.js 使用瀏覽器存儲(會話存儲或本地存儲)來存儲令牌。 此外,還有一個由 Azure AD B2C 投放的 cookie 來保存有關用戶 session 的信息。這就是為什么即使您在瀏覽器存儲中沒有令牌並打開登錄頁面,Azure AD B2C 也會自動讓您登錄而無需請求證書(當然前提是 session 仍然存在)。 我希望這個能有一點幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.