@@ -7,7 +7,7 @@ import { Subscription } from 'rxjs/Subscription';
7
7
import { ValidationHandler , ValidationParams } from './token-validation/validation-handler' ;
8
8
import { UrlHelperService } from './url-helper.service' ;
9
9
import { OAuthEvent , OAuthInfoEvent , OAuthErrorEvent , OAuthSuccessEvent } from './events' ;
10
- import { OAuthStorage , LoginOptions , ParsedIdToken } from './types' ;
10
+ import { OAuthStorage , LoginOptions , ParsedIdToken , OidcDiscoveryDoc , TokenResponse , UserInfo } from './types' ;
11
11
import { b64DecodeUnicode } from './base64-helper' ;
12
12
import { AuthConfig } from './auth.config' ;
13
13
@@ -314,7 +314,7 @@ export class OAuthService
314
314
return ;
315
315
}
316
316
317
- this . http . get < any > ( fullUrl ) . subscribe (
317
+ this . http . get < OidcDiscoveryDoc > ( fullUrl ) . subscribe (
318
318
( doc ) => {
319
319
320
320
if ( ! this . validateDiscoveryDocument ( doc ) ) {
@@ -387,55 +387,55 @@ export class OAuthService
387
387
388
388
}
389
389
390
- private validateDiscoveryDocument ( doc : object ) : boolean {
390
+ private validateDiscoveryDocument ( doc : OidcDiscoveryDoc ) : boolean {
391
391
392
392
let errors : string [ ] ;
393
393
394
- if ( doc [ ' issuer' ] !== this . issuer ) {
394
+ if ( doc . issuer !== this . issuer ) {
395
395
console . error (
396
396
'invalid issuer in discovery document' ,
397
397
'expected: ' + this . issuer ,
398
- 'current: ' + doc [ ' issuer' ]
398
+ 'current: ' + doc . issuer
399
399
) ;
400
400
return false ;
401
401
}
402
402
403
- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' authorization_endpoint' ] ) ;
403
+ errors = this . validateUrlFromDiscoveryDocument ( doc . authorization_endpoint ) ;
404
404
if ( errors . length > 0 ) {
405
405
console . error ( 'error validating authorization_endpoint in discovery document' , errors ) ;
406
406
return false ;
407
407
}
408
408
409
- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' end_session_endpoint' ] ) ;
409
+ errors = this . validateUrlFromDiscoveryDocument ( doc . end_session_endpoint ) ;
410
410
if ( errors . length > 0 ) {
411
411
console . error ( 'error validating end_session_endpoint in discovery document' , errors ) ;
412
412
return false ;
413
413
}
414
414
415
- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' token_endpoint' ] ) ;
415
+ errors = this . validateUrlFromDiscoveryDocument ( doc . token_endpoint ) ;
416
416
if ( errors . length > 0 ) {
417
417
console . error ( 'error validating token_endpoint in discovery document' , errors ) ;
418
418
}
419
419
420
- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' userinfo_endpoint' ] ) ;
420
+ errors = this . validateUrlFromDiscoveryDocument ( doc . userinfo_endpoint ) ;
421
421
if ( errors . length > 0 ) {
422
422
console . error ( 'error validating userinfo_endpoint in discovery document' , errors ) ;
423
423
return false ;
424
424
}
425
425
426
- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' jwks_uri' ] ) ;
426
+ errors = this . validateUrlFromDiscoveryDocument ( doc . jwks_uri ) ;
427
427
if ( errors . length > 0 ) {
428
428
console . error ( 'error validating jwks_uri in discovery document' , errors ) ;
429
429
return false ;
430
430
}
431
431
432
- if ( this . sessionChecksEnabled && ! doc [ ' check_session_iframe' ] ) {
432
+ if ( this . sessionChecksEnabled && ! doc . check_session_iframe ) {
433
433
console . warn (
434
434
'sessionChecksEnabled is activated but discovery document'
435
435
+ ' does not contain a check_session_iframe field' ) ;
436
436
}
437
437
438
- this . sessionChecksEnabled = doc [ ' check_session_iframe' ] ;
438
+ this . sessionChecksEnabled = ! ! doc . check_session_iframe ;
439
439
440
440
return true ;
441
441
}
@@ -483,14 +483,14 @@ export class OAuthService
483
483
const headers = new HttpHeaders ( )
484
484
. set ( 'Authorization' , 'Bearer ' + this . getAccessToken ( ) ) ;
485
485
486
- this . http . get < any > ( this . userinfoEndpoint , { headers } ) . subscribe (
487
- ( doc ) => {
488
- this . debug ( 'userinfo received' , doc ) ;
486
+ this . http . get < UserInfo > ( this . userinfoEndpoint , { headers } ) . subscribe (
487
+ ( info ) => {
488
+ this . debug ( 'userinfo received' , info ) ;
489
489
490
490
let existingClaims = this . getIdentityClaims ( ) || { } ;
491
491
492
492
if ( ! this . skipSubjectCheck ) {
493
- if ( this . oidc && ( ! existingClaims [ 'sub' ] || doc . sub !== existingClaims [ 'sub' ] ) ) {
493
+ if ( this . oidc && ( ! existingClaims [ 'sub' ] || info . sub !== existingClaims [ 'sub' ] ) ) {
494
494
let err = 'if property oidc is true, the received user-id (sub) has to be the user-id '
495
495
+ 'of the user that has logged in with oidc.\n'
496
496
+ 'if you are not using oidc but just oauth2 password flow set oidc to false' ;
@@ -500,11 +500,11 @@ export class OAuthService
500
500
}
501
501
}
502
502
503
- doc = Object . assign ( { } , existingClaims , doc ) ;
503
+ info = Object . assign ( { } , existingClaims , info ) ;
504
504
505
- this . _storage . setItem ( 'id_token_claims_obj' , JSON . stringify ( doc ) ) ;
505
+ this . _storage . setItem ( 'id_token_claims_obj' , JSON . stringify ( info ) ) ;
506
506
this . eventsSubject . next ( new OAuthSuccessEvent ( 'user_profile_loaded' ) ) ;
507
- resolve ( doc ) ;
507
+ resolve ( info ) ;
508
508
} ,
509
509
( err ) => {
510
510
console . error ( 'error loading user info' , err ) ;
@@ -543,7 +543,7 @@ export class OAuthService
543
543
544
544
let params = search . toString ( ) ;
545
545
546
- this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
546
+ this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
547
547
( tokenResponse ) => {
548
548
this . debug ( 'tokenResponse' , tokenResponse ) ;
549
549
this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
@@ -590,7 +590,7 @@ export class OAuthService
590
590
591
591
let params = search . toString ( ) ;
592
592
593
- this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
593
+ this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
594
594
( tokenResponse ) => {
595
595
this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
596
596
this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
0 commit comments