Skip to content

Commit f7d3860

Browse files
committed
jwt lib and rest of crypto at two different namespaces in node module vs bower module #bizzare
1 parent 676c9dd commit f7d3860

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/JwtUtil.js‎

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

3+
let __global;
34
let __jwtModule;
45

56
try {
67
// this is assuming we have a reference to
78
// the jsrsasign library loaded in the browser
9+
__global = window;
810
__jwtModule = window.KJUR;
911
}
1012
catch (e) {
@@ -18,6 +20,7 @@ export default class JwtUtil {
1820
// this is used to configure jsrsasign loaded via
1921
// require in our unit tests
2022
static init(global) {
23+
__global = global;
2124
__jwtModule = global;
2225
}
2326

@@ -41,10 +44,10 @@ export default class JwtUtil {
4144
try {
4245
if (key.kty === "RSA") {
4346
if (key.e && key.n) {
44-
key = __jwtModule.KEYUTIL.getKey(key);
47+
key = __global.KEYUTIL.getKey(key);
4548
}
4649
else if (key.x5c && key.x5c.length) {
47-
key = __jwtModule.KEYUTIL.getKey(__jwtModule.X509.getPublicKeyFromCertPEM(key.x5c[0]));
50+
key = __global.KEYUTIL.getKey(__global.X509.getPublicKeyFromCertPEM(key.x5c[0]));
4851
}
4952
else {
5053
Log.error("RSA key missing key material", key);
@@ -53,7 +56,7 @@ export default class JwtUtil {
5356
}
5457
else if (key.kty === "EC") {
5558
if (key.crv && key.x && key.y) {
56-
key = __jwtModule.KEYUTIL.getKey(key);
59+
key = __global.KEYUTIL.getKey(key);
5760
}
5861
else {
5962
Log.error("EC key missing key material", key);
@@ -84,7 +87,7 @@ export default class JwtUtil {
8487
static hashString(value, alg) {
8588
Log.info("JwtUtil.hashString", value, alg);
8689
try {
87-
return __jwtModule.crypto.Util.hashString(value, alg);
90+
return __global.crypto.Util.hashString(value, alg);
8891
}
8992
catch (e) {
9093
Log.error(e);
@@ -94,7 +97,7 @@ export default class JwtUtil {
9497
static hexToBase64Url(value) {
9598
Log.info("JwtUtil.hexToBase64Url", value);
9699
try {
97-
return __jwtModule.hextob64u(value);
100+
return __global.hextob64u(value);
98101
}
99102
catch (e) {
100103
Log.error(e);

0 commit comments

Comments
 (0)