mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -22,7 +22,15 @@ import { Injectable } from '@angular/core';
|
||||
})
|
||||
export class JwtHelperService {
|
||||
|
||||
constructor() {}
|
||||
static USER_NAME = 'name';
|
||||
static FAMILY_NAME = 'family_name';
|
||||
static GIVEN_NAME = 'given_name';
|
||||
static USER_EMAIL = 'email';
|
||||
static USER_ACCESS_TOKEN = 'access_token';
|
||||
static USER_PREFERRED_USERNAME = 'preferred_username';
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a JSON web token into a JS object.
|
||||
@@ -64,4 +72,29 @@ export class JwtHelperService {
|
||||
}
|
||||
return decodeURIComponent(escape(window.atob(output)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a named value from the user access token.
|
||||
* @param key Key name of the field to retrieve
|
||||
* @returns Value from the token
|
||||
*/
|
||||
getValueFromLocalAccessToken<T>(key: string): T {
|
||||
const accessToken = localStorage.getItem(JwtHelperService.USER_ACCESS_TOKEN);
|
||||
return this.getValueFromToken(accessToken, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a named value from the user access token.
|
||||
* @param key accessToken
|
||||
* @param key Key name of the field to retrieve
|
||||
* @returns Value from the token
|
||||
*/
|
||||
getValueFromToken<T>(accessToken: string, key: string): T {
|
||||
let value;
|
||||
if (accessToken) {
|
||||
const tokenPayload = this.decodeToken(accessToken);
|
||||
value = tokenPayload[key];
|
||||
}
|
||||
return <T> value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user