gpt4 book ai didi

oauth-2.0 - 使用 Microsoft 帐户 (login.live.com) 在 Azure AD B2C 上使用 MSAL.js acquireTokenSilent

转载 作者:行者123 更新时间:2023-12-01 22:33:36 25 4
gpt4 key购买 nike

login.live.com 存在问题,导致无法使用身份提供商 Microsoft 帐户通过 MSAL.js 获取 Azure AD B2C 的访问 token 。

当 iframe (msalRenewFrame...) 尝试在 https://login.live.com/oauth20_authorize.srfhttps://login 进行身份验证时.live.com/oauth20_authorize.srf 尝试“framebust”(导航作为主站点的 iframe 的父级)。 Chrome 显示此警告:

Frame with URL 'https://login.live.com/oauth20_authorize.srf?client_id=… attempted to navigate its top-level window with URL 'http://localhost:4200/#/dashboard'. Navigating the top-level window from a cross-origin iframe will soon require that the iframe has received a user gesture. See https://www.chromestatus.com/features/5851021045661696.

DoSubmit @ oauth20_authorize…
onload @ oauth20_authorize…

这会导致主站点重定向,从而将 acquireTokenSilent 变为 acquireTokenBoisterous。开个玩笑。

我尝试使用 ifr.setAttribute("sandbox", "allow-formsallow-pointer-lockallow-popupsallow-same-originallow-scripts"对 msalRenewFrame… 进行沙箱处理) 根据 https://www.w3schools.com/tags/att_iframe_sandbox.asp 。现在主站点不会重定向,但现在 Chrome 显示错误:

Unsafe JavaScript attempt to initiate navigation for frame with URL 'http://localhost:4200/#/dashboard' from frame with URL 'https://login.live.com/oauth20_authorize.srf?client_id=… The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

我认为发生这种帧破坏是出于兼容性原因(我们都知道如何将大量登录重定向到 Microsoft 服务)。恐怕这并不容易解决。但无论如何,Chrome 很快就会打破它,所以也许 https://login.live.com/oauth20_authorize.srf 背后的团队已经在着手解决这个问题。在此之前,Azure AD B2C 与真实帐户和 MSAL.js 的结合已被破坏且无法使用。

我已在 issue 267 of MSAL.js 上发布了此发现,但由于这不是 MSAL.js 问题,因此我也将其发布在这里。我希望 Microsoft 客户团队的某个人能够看到它并可能提供更多信息。

<小时/>

这就是我实例化 MSAL 的方式:

public initAndHandleRedirects() {
const authority = `https://login.microsoftonline.com/tfp/${environment.msalConfig.tenant}/${environment.msalConfig.signUpSignInPolicy}`;
this.clientApplication = new UserAgentApplication(environment.msalConfig.clientId, authority,
function (errorDesc, token, error, tokenType) {
if (error) {
console.error(error);
} else {
console.warn(`got new ${tokenType} token: ${token}`);
}
},
{
navigateToLoginRequestUrl: false,
redirectUri: environment.msalConfig.redirectUri,
logger: new Logger(this.log)
}
);

if (this.authenticated) {
console.warn(`User: ${this.idToken['extension_Nickname']} (${this.idToken['sub']})`);
}
}

这就是我尝试获取访问 token 的方式

public getAccessToken(): Observable<string> {
const that = this;
const acquireTokenPromise = this.clientApplication.acquireTokenSilent(environment.msalConfig.scopes);
return fromPromise(acquireTokenPromise);
}

范围是['https://....onmicrosoft.com/.../user_impersonation']

最佳答案

您可以request access 来自 B2C 的 token ,适用于 B2C 中定义的范围。

示例:

https://login.microsoftonline.com/<tenantName>.onmicrosoft.com/oauth2/v2.0/authorize?p=<yourPolicyId>&client_id=<appID_of_your_client_application>&nonce=anyRandomValue&redirect_uri=<redirect_uri_of_your_client_application>&scope=https%3A%2F%2Fcontoso.onmicrosoft.com%2Fnotes%2Fread&response_type=code

无法向身份提供商 (IDP) 请求访问权限以进行 B2C 身份验证。

关于oauth-2.0 - 使用 Microsoft 帐户 (login.live.com) 在 Azure AD B2C 上使用 MSAL.js acquireTokenSilent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49831045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com