您好,我正在使用azure / msal-angular npm软件包通过SSO登录来构建角度应用程序
一切正常,但有时在控制台中显示此错误“令牌更新操作由于超时而失败”,如下面的图像链接所示。
这是我的身份验证代码
async canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
var allowedRoles = next.data;
// check if logged in MSAL
this.isLoggedIn = await !!this.msalService.getAccount();
if (this.isLoggedIn) {
this.user = await this.msalService.getAccount();
localStorage.setItem('userName', this.user.name);
var isAdmin = false;
var userDataObj = this.authService.getUserDataFromSession()
if (userDataObj) {
this.userData = userDataObj;
}
else {
this.userData = await this.authService.getUserRoleByEmail(this.user.userName);
}
if (this.userData) {
for (const key in allowedRoles) {
const element = allowedRoles[key];
console.log(state.url);
console.log(element.toLowerCase(), this.userData.type);
if (state.url == '/' && this.userData.type == 'hq') {
this.router.navigate(['admin']);
break;
}
else if (state.url == '/' && this.userData.type == 'manager') {
this.router.navigate(['manager']);
break;
}
else if (element.toLowerCase() == 'manager' && this.userData.type == 'manager') {
return true;
}
else if (element.toLowerCase() == 'admin' && this.userData.type == 'hq') {
return true;
} else if (element.toLowerCase() == 'employee' && this.userData.type == 'emp') {
return true;
} else {
console.log("You are not allowed to access this page.-->>", state.url);
return false;
}
}
}
} else {
return false;
}
}
MSAL配置应用内模块文件
MsalModule.forRoot({
auth: {
clientId: environment.clientId,
authority: environment.authority,
validateAuthority: true,
redirectUri: environment.redirectUrl,
postLogoutRedirectUri: environment.redirectUrl,
navigateToLoginRequestUrl: true
},
cache: {
storeAuthStateInCookie: false,
}
}),
您能帮我解决此令牌错误以及如何获取新令牌吗?