@@ -7,7 +7,7 @@ import { Subscription } from 'rxjs/Subscription';
77import { ValidationHandler , ValidationParams } from './token-validation/validation-handler' ;
88import { UrlHelperService } from './url-helper.service' ;
99import { OAuthEvent , OAuthInfoEvent , OAuthErrorEvent , OAuthSuccessEvent } from './events' ;
10- import { OAuthStorage , LoginOptions , ParsedIdToken } from './types' ;
10+ import { OAuthStorage , LoginOptions , ParsedIdToken , OidcDiscoveryDoc , TokenResponse , UserInfo } from './types' ;
1111import { b64DecodeUnicode } from './base64-helper' ;
1212import { AuthConfig } from './auth.config' ;
1313
@@ -314,7 +314,7 @@ export class OAuthService
314314 return ;
315315 }
316316
317- this . http . get < any > ( fullUrl ) . subscribe (
317+ this . http . get < OidcDiscoveryDoc > ( fullUrl ) . subscribe (
318318 ( doc ) => {
319319
320320 if ( ! this . validateDiscoveryDocument ( doc ) ) {
@@ -387,55 +387,55 @@ export class OAuthService
387387
388388 }
389389
390- private validateDiscoveryDocument ( doc : object ) : boolean {
390+ private validateDiscoveryDocument ( doc : OidcDiscoveryDoc ) : boolean {
391391
392392 let errors : string [ ] ;
393393
394- if ( doc [ ' issuer' ] !== this . issuer ) {
394+ if ( doc . issuer !== this . issuer ) {
395395 console . error (
396396 'invalid issuer in discovery document' ,
397397 'expected: ' + this . issuer ,
398- 'current: ' + doc [ ' issuer' ]
398+ 'current: ' + doc . issuer
399399 ) ;
400400 return false ;
401401 }
402402
403- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' authorization_endpoint' ] ) ;
403+ errors = this . validateUrlFromDiscoveryDocument ( doc . authorization_endpoint ) ;
404404 if ( errors . length > 0 ) {
405405 console . error ( 'error validating authorization_endpoint in discovery document' , errors ) ;
406406 return false ;
407407 }
408408
409- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' end_session_endpoint' ] ) ;
409+ errors = this . validateUrlFromDiscoveryDocument ( doc . end_session_endpoint ) ;
410410 if ( errors . length > 0 ) {
411411 console . error ( 'error validating end_session_endpoint in discovery document' , errors ) ;
412412 return false ;
413413 }
414414
415- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' token_endpoint' ] ) ;
415+ errors = this . validateUrlFromDiscoveryDocument ( doc . token_endpoint ) ;
416416 if ( errors . length > 0 ) {
417417 console . error ( 'error validating token_endpoint in discovery document' , errors ) ;
418418 }
419419
420- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' userinfo_endpoint' ] ) ;
420+ errors = this . validateUrlFromDiscoveryDocument ( doc . userinfo_endpoint ) ;
421421 if ( errors . length > 0 ) {
422422 console . error ( 'error validating userinfo_endpoint in discovery document' , errors ) ;
423423 return false ;
424424 }
425425
426- errors = this . validateUrlFromDiscoveryDocument ( doc [ ' jwks_uri' ] ) ;
426+ errors = this . validateUrlFromDiscoveryDocument ( doc . jwks_uri ) ;
427427 if ( errors . length > 0 ) {
428428 console . error ( 'error validating jwks_uri in discovery document' , errors ) ;
429429 return false ;
430430 }
431431
432- if ( this . sessionChecksEnabled && ! doc [ ' check_session_iframe' ] ) {
432+ if ( this . sessionChecksEnabled && ! doc . check_session_iframe ) {
433433 console . warn (
434434 'sessionChecksEnabled is activated but discovery document'
435435 + ' does not contain a check_session_iframe field' ) ;
436436 }
437437
438- this . sessionChecksEnabled = doc [ ' check_session_iframe' ] ;
438+ this . sessionChecksEnabled = ! ! doc . check_session_iframe ;
439439
440440 return true ;
441441 }
@@ -483,14 +483,14 @@ export class OAuthService
483483 const headers = new HttpHeaders ( )
484484 . set ( 'Authorization' , 'Bearer ' + this . getAccessToken ( ) ) ;
485485
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 ) ;
489489
490490 let existingClaims = this . getIdentityClaims ( ) || { } ;
491491
492492 if ( ! this . skipSubjectCheck ) {
493- if ( this . oidc && ( ! existingClaims [ 'sub' ] || doc . sub !== existingClaims [ 'sub' ] ) ) {
493+ if ( this . oidc && ( ! existingClaims [ 'sub' ] || info . sub !== existingClaims [ 'sub' ] ) ) {
494494 let err = 'if property oidc is true, the received user-id (sub) has to be the user-id '
495495 + 'of the user that has logged in with oidc.\n'
496496 + 'if you are not using oidc but just oauth2 password flow set oidc to false' ;
@@ -500,11 +500,11 @@ export class OAuthService
500500 }
501501 }
502502
503- doc = Object . assign ( { } , existingClaims , doc ) ;
503+ info = Object . assign ( { } , existingClaims , info ) ;
504504
505- this . _storage . setItem ( 'id_token_claims_obj' , JSON . stringify ( doc ) ) ;
505+ this . _storage . setItem ( 'id_token_claims_obj' , JSON . stringify ( info ) ) ;
506506 this . eventsSubject . next ( new OAuthSuccessEvent ( 'user_profile_loaded' ) ) ;
507- resolve ( doc ) ;
507+ resolve ( info ) ;
508508 } ,
509509 ( err ) => {
510510 console . error ( 'error loading user info' , err ) ;
@@ -543,7 +543,7 @@ export class OAuthService
543543
544544 let params = search . toString ( ) ;
545545
546- this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
546+ this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
547547 ( tokenResponse ) => {
548548 this . debug ( 'tokenResponse' , tokenResponse ) ;
549549 this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
@@ -590,7 +590,7 @@ export class OAuthService
590590
591591 let params = search . toString ( ) ;
592592
593- this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
593+ this . http . post < TokenResponse > ( this . tokenEndpoint , params , { headers } ) . subscribe (
594594 ( tokenResponse ) => {
595595 this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
596596 this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
0 commit comments