Angular 由于MSAL中超时,令牌续订操作失败
您好,我正在使用azure/msal angular npm包使用SSO登录构建angular应用程序 一切正常,但有时它会在控制台中显示此错误“令牌续订操作因超时而失败”,如下图链接所示 这是我的身份验证码Angular 由于MSAL中超时,令牌续订操作失败,angular,typescript,single-sign-on,msal,Angular,Typescript,Single Sign On,Msal,您好,我正在使用azure/msal angular npm包使用SSO登录构建angular应用程序 一切正常,但有时它会在控制台中显示此错误“令牌续订操作因超时而失败”,如下图链接所示 这是我的身份验证码 async canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot) { var allowedRoles = next.data; // check if log
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;
}
}
MsalModule.forRoot({
auth: {
clientId: environment.clientId,
authority: environment.authority,
validateAuthority: true,
redirectUri: environment.redirectUrl,
postLogoutRedirectUri: environment.redirectUrl,
navigateToLoginRequestUrl: true
},
cache: {
storeAuthStateInCookie: false,
}
}),
应用程序模块文件中的MSAL配置
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;
}
}
MsalModule.forRoot({
auth: {
clientId: environment.clientId,
authority: environment.authority,
validateAuthority: true,
redirectUri: environment.redirectUrl,
postLogoutRedirectUri: environment.redirectUrl,
navigateToLoginRequestUrl: true
},
cache: {
storeAuthStateInCookie: false,
}
}),
您能否帮助我解决此令牌错误,以及如何获取新令牌?您是否尝试升级到最新的msal(1.4.3)库以及最新的@azure/msal angular(1.1.1)?@pixelbits,升级后此令牌问题将得到解决?…当前在package.json文件中我有此版本….“msal”:“^1.4.0”,“@azure/msal angular”:“^1.1.1”…嗯,试试看?