获取refresh_token有两个步骤。 第一步是从 https://login.microsoftonline.com/common/oauth2/v2.0/authorize 端点获取代码。 第二步是交换从步骤 1 获得的代码,以从 https://login.microsoftonline.com/common/oauth2/v2.0/token 端点获取刷新令牌。
如果我在 entra.microsoft.com 上将 redirect_uri 的类型设置为 web,则第一步有效,但第二步将返回错误:AADSTS90023: Cross-origin token redemption is allowed only for the 'Single-Page申请'.
如果我在 entra.microsoft.com 上将redirect_uri 的类型设置为单页应用程序,则第一步会出现 error_description: Proof Key for Code Exchange is required for cross-origin Authorization Code redemption。
有什么想法可以从微软登录获取refresh_token吗?
经过几天的研究,我终于找到了一个包作为潜在的解决方案: npm 我@azure/msal-browser
MSAL.js 抽象了所有刷新令牌的复杂性,因此 MSAL API 在设计上不会公开刷新令牌。 当您需要访问令牌时,请调用
acquireTokenSilent
API,该 API 将从缓存返回一个有效令牌,或者在内部使用刷新令牌来获取新的访问令牌。
return pca.acquireTokenSilent(silentRequest).catch(e => {
if (e instanceof InteractionRequiredAuthError) {
return pca.acquireTokenInteractive(loginRequest)
}
});