@@ -18,6 +18,12 @@ export type PrivkeyResolver = (keyId: string) => PrivkeyData | Promise<PrivkeyDa
1818type JwtVerifyAsync = < T extends string | object > ( token : string , publicKey : string | Buffer , options ?: jwt . VerifyOptions ) => Promise < T >
1919type JwtSignAsync = ( payload : string | Buffer | object , privateKey : { } , options ?: jwt . SignOptions ) => Promise < string >
2020
21+ export interface JwtHandlerOptions {
22+ debugNamePrefix : string
23+ pubkeyResolver ?: PubkeyResolver
24+ privkeyResolver ?: PrivkeyResolver
25+ }
26+
2127shim ( ) // util.promisify shim
2228
2329export class JwtHandler {
@@ -30,12 +36,23 @@ export class JwtHandler {
3036 private jwtVerifyAsync = util . promisify ( jwt . verify ) as JwtVerifyAsync
3137 private jwtSignAsync = util . promisify ( jwt . sign ) as JwtSignAsync
3238
39+ public constructor ( options : JwtHandlerOptions )
3340 public constructor ( debugNamePrefix : string ,
34- pubkeyResolver : PubkeyResolver | null ,
35- privkeyResolver : PrivkeyResolver | null ) {
36- this . debug = debug ( debugNamePrefix + ":jwt.handler" )
37- this . pubkeyResolver = pubkeyResolver
38- this . privkeyResolver = privkeyResolver
41+ pubkeyResolver ?: PubkeyResolver | null ,
42+ privkeyResolver ?: PrivkeyResolver | null )
43+ public constructor ( arg1 : string | JwtHandlerOptions , arg2 ?: PubkeyResolver | null , arg3 ?: PrivkeyResolver | null ) {
44+ if ( typeof arg1 === "object" ) {
45+ arg2 = arg1 . pubkeyResolver
46+ arg3 = arg1 . privkeyResolver
47+ arg1 = arg1 . debugNamePrefix
48+ }
49+
50+ arg2 = arg2 || null
51+ arg3 = arg3 || null
52+
53+ this . debug = debug ( arg1 + ":jwt.handler" )
54+ this . pubkeyResolver = arg2
55+ this . privkeyResolver = arg3
3956 }
4057
4158 /**
0 commit comments