@@ -352,8 +352,8 @@ export default class CrossidClient {
352
352
public async getUser < E extends IDToken > (
353
353
opts : GetUserOpts = { }
354
354
) : Promise < E | undefined > {
355
- const aud = opts . audience || this . opts . audience || [ '' ]
356
- const scp = uniqueScopes ( this . scope , opts . scope )
355
+ const aud = this . getFinalAudience ( opts . audience )
356
+ const scp = this . getFinalScope ( opts . scope )
357
357
const keys = this . _getTokensKeysFromCache ( 'id_token' , aud , scp )
358
358
const tok = this . _getNarrowedKey < DecodedJWT < E > > ( keys )
359
359
return tok ?. payload
@@ -368,8 +368,8 @@ export default class CrossidClient {
368
368
public async getAccessToken (
369
369
opts : GetAccessTokenOpts = { }
370
370
) : Promise < string | undefined > {
371
- const aud = opts . audience || this . opts . audience || [ '' ]
372
- const scp = uniqueScopes ( this . scope , opts . scope )
371
+ const aud = this . getFinalAudience ( opts . audience )
372
+ const scp = this . getFinalScope ( opts . scope )
373
373
const keys = this . _getTokensKeysFromCache ( 'access_token' , aud , scp )
374
374
const tok = this . _getNarrowedKey < DecodedJWT < JWTClaims > > ( keys )
375
375
return tok ?. payload ?. _raw
@@ -387,8 +387,8 @@ export default class CrossidClient {
387
387
public async introspectAccessToken (
388
388
opts : GetAccessTokenOpts = { }
389
389
) : Promise < JWTClaims | undefined > {
390
- const aud = opts . audience || this . opts . audience
391
- const scp = uniqueScopes ( this . scope , opts . scope )
390
+ const aud = this . getFinalAudience ( opts . audience )
391
+ const scp = this . getFinalScope ( opts . scope )
392
392
const keys = this . _getTokensKeysFromCache ( 'access_token' , aud , scp )
393
393
const tok = this . _getNarrowedKey < DecodedJWT < JWTClaims > > ( keys )
394
394
@@ -540,12 +540,12 @@ export default class CrossidClient {
540
540
) : AuthorizationRequest {
541
541
return {
542
542
client_id : this . opts . client_id ,
543
- audience : opts . audience || this . opts . audience ,
543
+ audience : this . getFinalAudience ( opts . audience ) ,
544
544
response_type : opts . response_type || this . opts . response_type || 'code' ,
545
545
redirect_uri : opts . redirect_uri || this . opts . redirect_uri ,
546
546
nonce : opts . nonce ,
547
547
state : opts . state ,
548
- scope : opts . scope || this . opts . scope ,
548
+ scope : this . getFinalScope ( opts . scope ) . join ( ' ' ) ,
549
549
code_challenge : opts . code_challenge ,
550
550
code_challenge_method : 'S256' ,
551
551
}
@@ -824,13 +824,13 @@ export default class CrossidClient {
824
824
// _getTokensKeysFromCache returns key names that matches the given criteria.
825
825
private _getTokensKeysFromCache (
826
826
tokType : tokenTypes ,
827
- aud : string [ ] ,
827
+ aud : string [ ] = [ '' ] ,
828
828
scp : string [ ]
829
829
) : string [ ] {
830
830
let idx = this . cache . get ( CACHE_IDX_KEY ) || { }
831
831
// this method currently handles single aud only
832
832
const aud1 = aud [ 0 ]
833
- const audIdx = idx [ aud1 ]
833
+ const audIdx = idx [ aud1 ] || [ '' ]
834
834
if ( ! audIdx ) return [ ]
835
835
836
836
let inter
@@ -896,4 +896,14 @@ export default class CrossidClient {
896
896
}
897
897
this . cache . set ( CACHE_IDX_KEY , idx )
898
898
}
899
+
900
+ private getFinalAudience ( localAud : string [ ] ) : string [ ] {
901
+ return localAud || this . opts . audience
902
+ }
903
+
904
+ private getFinalScope ( localScp : string ) : string [ ] {
905
+ return localScp !== undefined
906
+ ? uniqueScopes ( localScp )
907
+ : uniqueScopes ( this . scope )
908
+ }
899
909
}
0 commit comments