Replace deprated escape()
function with jwt-decode
(#21990)
Closes #22034
This commit is contained in:
parent
29b67fc8df
commit
0536078282
3 changed files with 13 additions and 28 deletions
|
@ -52,6 +52,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"base64-js": "^1.5.1",
|
||||
"js-sha256": "^0.9.0"
|
||||
"js-sha256": "^0.9.0",
|
||||
"jwt-decode": "^3.1.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
import base64 from 'base64-js';
|
||||
import sha256 from 'js-sha256';
|
||||
import jwtDecode from 'jwt-decode';
|
||||
|
||||
if (typeof Promise === 'undefined') {
|
||||
throw Error('Keycloak requires an environment that supports Promises. Make sure that you include the appropriate polyfill.');
|
||||
|
@ -969,7 +970,7 @@ function Keycloak (config) {
|
|||
|
||||
if (refreshToken) {
|
||||
kc.refreshToken = refreshToken;
|
||||
kc.refreshTokenParsed = decodeToken(refreshToken);
|
||||
kc.refreshTokenParsed = jwtDecode(refreshToken);
|
||||
} else {
|
||||
delete kc.refreshToken;
|
||||
delete kc.refreshTokenParsed;
|
||||
|
@ -977,7 +978,7 @@ function Keycloak (config) {
|
|||
|
||||
if (idToken) {
|
||||
kc.idToken = idToken;
|
||||
kc.idTokenParsed = decodeToken(idToken);
|
||||
kc.idTokenParsed = jwtDecode(idToken);
|
||||
} else {
|
||||
delete kc.idToken;
|
||||
delete kc.idTokenParsed;
|
||||
|
@ -985,7 +986,7 @@ function Keycloak (config) {
|
|||
|
||||
if (token) {
|
||||
kc.token = token;
|
||||
kc.tokenParsed = decodeToken(token);
|
||||
kc.tokenParsed = jwtDecode(token);
|
||||
kc.sessionId = kc.tokenParsed.session_state;
|
||||
kc.authenticated = true;
|
||||
kc.subject = kc.tokenParsed.sub;
|
||||
|
@ -1020,30 +1021,6 @@ function Keycloak (config) {
|
|||
}
|
||||
}
|
||||
|
||||
function decodeToken(str) {
|
||||
str = str.split('.')[1];
|
||||
|
||||
str = str.replace(/-/g, '+');
|
||||
str = str.replace(/_/g, '/');
|
||||
switch (str.length % 4) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
str += '==';
|
||||
break;
|
||||
case 3:
|
||||
str += '=';
|
||||
break;
|
||||
default:
|
||||
throw 'Invalid token';
|
||||
}
|
||||
|
||||
str = decodeURIComponent(escape(atob(str)));
|
||||
|
||||
str = JSON.parse(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
function createUUID() {
|
||||
var hexDigits = '0123456789abcdef';
|
||||
var s = generateRandomString(36, hexDigits).split("");
|
||||
|
|
|
@ -356,6 +356,9 @@ importers:
|
|||
js-sha256:
|
||||
specifier: ^0.9.0
|
||||
version: 0.9.0
|
||||
jwt-decode:
|
||||
specifier: ^3.1.2
|
||||
version: 3.1.2
|
||||
devDependencies:
|
||||
'@rollup/plugin-commonjs':
|
||||
specifier: ^25.0.3
|
||||
|
@ -4813,6 +4816,10 @@ packages:
|
|||
object.values: 1.1.6
|
||||
dev: true
|
||||
|
||||
/jwt-decode@3.1.2:
|
||||
resolution: {integrity: sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==}
|
||||
dev: false
|
||||
|
||||
/kolorist@1.8.0:
|
||||
resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==}
|
||||
dev: true
|
||||
|
|
Loading…
Reference in a new issue