如何解决由于MSAL Angular中的超时,令牌更新操作失败
您好,我正在使用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,}
}),
您能帮我解决此令牌错误以及如何获取新令牌吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。