Skip to content

Commit 676c9dd

Browse files
committed
locate correct reference for JWT library loaded into browser
1 parent 69d208d commit 676c9dd

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎src/JwtUtil.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Log from './Log';
22

3-
let __global;
3+
let __jwtModule;
44

55
try {
66
// this is assuming we have a reference to
77
// the jsrsasign library loaded in the browser
8-
__global = window;
8+
__jwtModule = window.KJUR;
99
}
1010
catch (e) {
1111
// this will certainly throw in our unit tests
@@ -18,13 +18,13 @@ export default class JwtUtil {
1818
// this is used to configure jsrsasign loaded via
1919
// require in our unit tests
2020
static init(global) {
21-
__global = global;
21+
__jwtModule = global;
2222
}
2323

2424
static parseJwt(jwt) {
2525
Log.info("JwtUtil.parseJwt");
2626
try {
27-
var token = __global.jws.JWS.parse(jwt);
27+
var token = __jwtModule.jws.JWS.parse(jwt);
2828
return {
2929
header: token.headerObj,
3030
payload: token.payloadObj
@@ -41,10 +41,10 @@ export default class JwtUtil {
4141
try {
4242
if (key.kty === "RSA") {
4343
if (key.e && key.n) {
44-
key = __global.KEYUTIL.getKey(key);
44+
key = __jwtModule.KEYUTIL.getKey(key);
4545
}
4646
else if (key.x5c && key.x5c.length) {
47-
key = __global.KEYUTIL.getKey(__global.X509.getPublicKeyFromCertPEM(key.x5c[0]));
47+
key = __jwtModule.KEYUTIL.getKey(__jwtModule.X509.getPublicKeyFromCertPEM(key.x5c[0]));
4848
}
4949
else {
5050
Log.error("RSA key missing key material", key);
@@ -53,7 +53,7 @@ export default class JwtUtil {
5353
}
5454
else if (key.kty === "EC") {
5555
if (key.crv && key.x && key.y) {
56-
key = __global.KEYUTIL.getKey(key);
56+
key = __jwtModule.KEYUTIL.getKey(key);
5757
}
5858
else {
5959
Log.error("EC key missing key material", key);
@@ -65,7 +65,7 @@ export default class JwtUtil {
6565
return false;
6666
}
6767

68-
return __global.jws.JWS.verifyJWT(jwt,
68+
return __jwtModule.jws.JWS.verifyJWT(jwt,
6969
key,
7070
{
7171
alg: ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'ES512'],
@@ -84,7 +84,7 @@ export default class JwtUtil {
8484
static hashString(value, alg) {
8585
Log.info("JwtUtil.hashString", value, alg);
8686
try {
87-
return __global.crypto.Util.hashString(value, alg);
87+
return __jwtModule.crypto.Util.hashString(value, alg);
8888
}
8989
catch (e) {
9090
Log.error(e);
@@ -94,7 +94,7 @@ export default class JwtUtil {
9494
static hexToBase64Url(value) {
9595
Log.info("JwtUtil.hexToBase64Url", value);
9696
try {
97-
return __global.hextob64u(value);
97+
return __jwtModule.hextob64u(value);
9898
}
9999
catch (e) {
100100
Log.error(e);

0 commit comments

Comments
 (0)