我在反应应用程序中使用MSAL进行身份验证。我使用 localStorage 作为 UserAgentApplication 实例的缓存存储。loginPopup 方法提供一个有效期为一小时的 idToken。出于我的应用程序的目的,我想在它过期时静默刷新这个 idToken。根据所有文档,如果令牌过期,acquireTokenSilent 函数将自动刷新令牌,否则如果客户端 ID 作为范围参数传递,则将提供缓存的令牌。
但是,我在调用 acquireTokenSilent 函数时遇到了以下异常。
The cache contains multiple tokens satisfying the requirements. Call AcquireToken again providing more requirements like authority|multiple_matching_tokens_detected
令人惊讶的是,这个异常是在 chrome 上引发的,而不是在边缘浏览器上。文件系统中是否存储了任何浏览器特定的缓存?我已经清除了 chrome 中的 cookie 和本地存储数据,但没有任何帮助。
以下是一些负责任的代码片段:
login = () => {
return this.app.loginPopup(this.applicationConfig.graphScopes).then(
idToken => {
return idToken;
},
() => {
return null;
}
);
};
getToken = () => {
return this.app
.acquireTokenSilent([this.applicationConfig.clientID], '', this.app.getUser())
.then(
idToken => {
return idToken;
},
error => {
console.log(
"Error occured while loading silent token. Error - ",
error
);
}
);
};
首先,我尝试调用 getToken 函数,如果找不到令牌,那么我将用户重定向到使用登录函数的登录页面。请注意,我在这两种情况下都使用 idToken,但不是 accessToken。
非常感谢任何帮助以使这项工作在 chrome 中工作。