[ADF-4665] [ADF] - Application is refreshed when you have two instances of application opened (#4849)

* refactoring getValueFromToken and fix user token refresh

* refactoring getValueFromToken and fix user token refresh

* refactoring getValueFromToken and fix user token refres

* fix unit test
This commit is contained in:
Eugenio Romano
2019-06-14 16:02:12 +01:00
committed by GitHub
parent 4733bc7d3b
commit f47cebc0a4
11 changed files with 94 additions and 93 deletions

View File

@@ -56,19 +56,19 @@ export class AuthGuardSsoRoleService implements CanActivate {
}
getRealmRoles(): string[] {
const access = this.getValueFromToken<any>('realm_access');
const access = this.jwtHelperService.getValueFromLocalAccessToken<any>('realm_access');
const roles = access ? access['roles'] : [];
return roles;
}
getClientRoles(client: string): string[] {
const clientRole = this.getValueFromToken<any>('resource_access')[client];
const clientRole = this.jwtHelperService.getValueFromLocalAccessToken<any>('resource_access')[client];
const roles = clientRole ? clientRole['roles'] : [];
return roles;
}
getAccessToken(): string {
return this.storageService.getItem('access_token');
return this.storageService.getItem(JwtHelperService.USER_ACCESS_TOKEN);
}
hasRealmRole(role: string): boolean {
@@ -104,14 +104,4 @@ export class AuthGuardSsoRoleService implements CanActivate {
}
return hasRole;
}
getValueFromToken<T>(key: string): T {
let value;
const accessToken = this.getAccessToken();
if (accessToken) {
const tokenPayload = this.jwtHelperService.decodeToken(accessToken);
value = tokenPayload[key];
}
return <T> value;
}
}