我有一个使用react-aad-msal库验证Azure AD的react应用程序。下面的代码运行良好。但是当访问令牌过期时,getAccessToken方法会自动获取新的访问令牌,并使应用程序继续运行。但是,我需要在访问令牌过期时要求用户重新进行身份验证,并且如果用户在整个持续时间内都处于空闲状态。有办法做到这一点吗?
const apiAuthenticationParameters = {
scopes: [config.appScope],
forceRefresh: true,
};
const getAccessToken = () => {
return AuthProvider.getAccessToken(apiAuthenticationParameters);
};发布于 2020-12-21 16:50:06
如果令牌即将过期,似乎没有直接的方法来检查它。您可以在中间件中引用类似的issue。
const checkTokenExpirationMiddleware = store => next => action => {
const token =
JSON.parse(localStorage.getItem("user")) &&
JSON.parse(localStorage.getItem("user"))["token"];
if (jwtDecode(token).exp < Date.now() / 1000) {
next(action);
localStorage.clear();
}
next(action);
};访问令牌的默认生存期为1小时,请参阅here。您可以在该时间之后调用注销函数。
https://stackoverflow.com/questions/65388990
复制相似问题