11import Log from './Log' ;
22
3+ let __global ;
34let __jwtModule ;
45
56try {
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}
1012catch ( 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