【发布时间】:2021-01-09 10:08:54
【问题描述】:
我最近尝试使用“acquireTokenSilent Flow”从 AzureADB2C 获取 accessToken。 我正在使用@azure/msal-browser,我的应用是 React。 所以,现在我的代码是这样的。
const getTokenRedirect = async (account, apiConfig) => {
publicClient.acquireTokenSilent({
scopes: apiConfig.scopes,
account: account,
authority: apiConfig.authority,
}).then(tokenResponse => {
console.log(tokenResponse);
setAccessToken(tokenResponse.accessToken);
}).catch(async (error) => {
console.log(error);
});
}
然后这段代码响应刷新令牌,而不是accessToken。 我不知道为什么acquireTokenSilent 没有响应accessToken。 我确实从 ADB2C 获得了 idToken。另一个示例(msal.js vanilla Sample)获得了 accessToken。 所以我认为B2C设置是正确的。我的代码有一些问题。
有没有人知道这样的解决方案。
【问题讨论】:
-
apiConfig = URI +scopes(我在此 uri 上的应用注册表面板上设置了我的应用程序。并且范围也在范围面板上设置。就像 https://[mywebapplicationURI]/[scopes] . 这个不是 b2c 策略 URL。但我还是得到了刷新令牌。
-
this可以回答你的问题吗?
-
你好,Tiny-wa。感谢您的评论。我发现了这个问题github.com/AzureAD/microsoft-authentication-library-for-js/…。我觉得这个问题和我一样。
-
好的,您提供的链接还提供了同时使用acquireTokenSilent 和acquireTokenRedirect 的解决方案。希望您尽快解决。
标签: azure-ad-b2c msal.js