我在我的React项目中使用msal.js进行身份验证。在那,我有一个配置文件编辑选项。
修改个人资料的步骤
因此,一旦我编辑了名称,B2C配置文件名称就会更新。但不是id_token。我想强制刷新id_token表B2C。 acquireTokenSilent
方法始终从缓存中获取令牌。是否有任何方法可以强制应用程序从B2C获取新令牌?
这是我的acquireTokenSilent
方法的代码
async acquireToken(request, redirect) {
return msalApp
.acquireTokenSilent(request)
.then((loginResponse) => {
console.log('gg');
if (loginResponse) {
console.log(loginResponse);
this.setState({
account: loginResponse.account,
isAuthenticated: true,
error: null,
});
return true;
}
})
.catch((error) => {
// Call acquireTokenPopup (popup window) in case of acquireTokenSilent failure
// due to consent or interaction required ONLY
if (requiresInteraction(error.errorCode)) {
this.setState({
isAuthenticated: false,
});
return redirect ? msalApp.acquireTokenRedirect(request) : this.onSignIn(redirect);
}
console.error('Non-interactive error:', error.errorCode);
return false;
});
}
[在MSAL.js中检出方法的定义,以获取AcquisitionSilk方法:https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/src/UserAgentApplication.ts#L667
/**
* Use this function to obtain a token before every call to the API / resource provider
*
* MSAL return's a cached token when available
* Or it send's a request to the STS to obtain a new token using a hidden iframe.
*
* @param {@link AuthenticationParameters}
*
* To renew idToken, please pass clientId as the only scope in the Authentication Parameters
* @returns {Promise.<AuthResponse>} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object
*
*/
acquireTokenSilent(userRequest: AuthenticationParameters): Promise<AuthResponse> {
由于您未使用B2C的配置文件编辑策略,因此会产生此结果。如果您清除了会话存储中的msal对象,则只会获得带有acquireTokenSilent的新令牌,否则,直到会话存储中的令牌过期,它都将用作缓存。