【发布时间】:2021-04-30 01:18:33
【问题描述】:
@azure/msal-browser 2.14.1 @azure/msal-react 1.0.0-beta.2
我们正在使用自定义 b2c 政策
当我使用 PublicClientApplication 实例调用 acquireTokenSilent 时,它没有从缓存中获取访问令牌,但我可以看到访问令牌存储在 sessionStorage 中,看起来类似于 {homeAccountId}-{tenantSubdomain}.b2clogin.com-AccessToken-{aud}-{tid}。与 refreshToken、clientInfo 和 idToken 格式类似。它确实按预期从端点成功返回令牌。
在 B2C 中,重定向 uri 设置为 SPA,并且禁用了隐式流
配置:
const config = {
auth: {
clientId: applicationID,
authority: signInAuthority,
knownAuthorities: [
`${tenantSubdomain}.b2clogin.com`,
],
redirectUri: reactRedirectUri,
validateAuthority: false,
navigateToLoginRequestUrl: false,
postLogoutRedirectUri: reactRedirectUri,
},
system: {
loggerOptions: {
loggerCallback: (level, message, containsPii) => {
if (containsPii) {
return;
}
switch (level) {
case LogLevel.Error:
console.error(message);
return;
case LogLevel.Info:
console.info(message);
return;
case LogLevel.Verbose:
console.debug(message);
return;
case LogLevel.Warning:
console.warn(message);
return;
}
},
piiLoggingEnabled: false,
},
windowHashTimeout: 60000,
iframeHashTimeout: 6000,
loadFrameTimeout: 0,
tokenRenewalOffsetSeconds: 1,
// allowRedirectInIframe: true,
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true,
},
};
请求:
const signInRequest = {
scopes: [
msalInstance.config.auth.clientId,
],
};
const silentRefreshRequest = {
scopes: [
msalInstance.config.auth.clientId,
],
};
offline_access、openid 和 profile 会自动添加到请求中,我在这些范围上尝试了许多不同的变体。
acquireTokenSilent:
const res = await msalInstance.acquireTokenSilent({
...silentRefreshRequest,
account: msalInstance.getActiveAccount(),
});
我再次尝试了一些不同的变化。有什么我遗漏的东西可以解决从缓存中获取它的问题,还是我只需要解决它?
【问题讨论】:
标签: reactjs azure azure-ad-b2c msal.js