1- import { Http , URLSearchParams , Headers } from '@angular/http' ;
21import { Injectable , Optional } from '@angular/core' ;
2+ import { HttpClient , HttpHeaders } from '@angular/common/http' ;
33import { Observable } from 'rxjs/Observable' ;
44import { Subject } from 'rxjs/Subject' ;
5+ import { Subscription } from 'rxjs/Subscription' ;
6+
57import { ValidationHandler , ValidationParams } from './token-validation/validation-handler' ;
68import { UrlHelperService } from './url-helper.service' ;
7- import { Subscription } from 'rxjs/Subscription' ;
89import { OAuthEvent , OAuthInfoEvent , OAuthErrorEvent , OAuthSuccessEvent } from './events' ;
910import { OAuthStorage , LoginOptions , ParsedIdToken } from './types' ;
1011import { b64DecodeUnicode } from './base64-helper' ;
@@ -65,7 +66,7 @@ export class OAuthService
6566 private silentRefreshSubject : string ;
6667
6768 constructor (
68- private http : Http ,
69+ private http : HttpClient ,
6970 @Optional ( ) storage : OAuthStorage ,
7071 @Optional ( ) tokenValidationHandler : ValidationHandler ,
7172 @Optional ( ) private config : AuthConfig ,
@@ -92,7 +93,6 @@ export class OAuthService
9293
9394 this . setupRefreshTimer ( ) ;
9495
95-
9696 }
9797
9898 /**
@@ -140,14 +140,13 @@ export class OAuthService
140140 * @param params Additional parameter to pass
141141 */
142142 public setupAutomaticSilentRefresh ( params : object = { } ) {
143- this
144- . events
145- . filter ( e => e . type === 'token_expires' )
146- . subscribe ( e => {
147- this . silentRefresh ( params ) . catch ( _ => {
148- this . debug ( 'automatic silent refresh did not work' ) ;
149- } )
150- } ) ;
143+ this . events
144+ . filter ( e => e . type === 'token_expires' )
145+ . subscribe ( e => {
146+ this . silentRefresh ( params ) . catch ( _ => {
147+ this . debug ( 'automatic silent refresh did not work' ) ;
148+ } ) ;
149+ } ) ;
151150
152151 this . restartRefreshTimerIfStillLoggedIn ( ) ;
153152 }
@@ -306,7 +305,7 @@ export class OAuthService
306305 fullUrl = this . issuer || '' ;
307306 if ( ! fullUrl . endsWith ( '/' ) ) {
308307 fullUrl += '/' ;
309- }
308+ }
310309 fullUrl += '.well-known/openid-configuration' ;
311310 }
312311
@@ -315,7 +314,7 @@ export class OAuthService
315314 return ;
316315 }
317316
318- this . http . get ( fullUrl ) . map ( r => r . json ( ) ) . subscribe (
317+ this . http . get < any > ( fullUrl ) . subscribe (
319318 ( doc ) => {
320319
321320 if ( ! this . validateDiscoveryDocument ( doc ) ) {
@@ -368,7 +367,7 @@ export class OAuthService
368367 private loadJwks ( ) : Promise < object > {
369368 return new Promise < object > ( ( resolve , reject ) => {
370369 if ( this . jwksUri ) {
371- this . http . get ( this . jwksUri ) . map ( r => r . json ( ) ) . subscribe (
370+ this . http . get ( this . jwksUri ) . subscribe (
372371 jwks => {
373372 this . jwks = jwks ;
374373 this . eventsSubject . next ( new OAuthSuccessEvent ( 'discovery_document_loaded' ) ) ;
@@ -458,7 +457,7 @@ export class OAuthService
458457 public fetchTokenUsingPasswordFlowAndLoadUserProfile (
459458 userName : string ,
460459 password : string ,
461- headers : Headers = new Headers ( ) ) : Promise < object > {
460+ headers : HttpHeaders = new HttpHeaders ( ) ) : Promise < object > {
462461 return this
463462 . fetchTokenUsingPasswordFlow ( userName , password , headers )
464463 . then ( ( ) => this . loadUserProfile ( ) ) ;
@@ -481,15 +480,15 @@ export class OAuthService
481480
482481 return new Promise ( ( resolve , reject ) => {
483482
484- let headers = new Headers ( ) ;
485- headers . set ( 'Authorization' , 'Bearer ' + this . getAccessToken ( ) ) ;
483+ const headers = new HttpHeaders ( )
484+ . set ( 'Authorization' , 'Bearer ' + this . getAccessToken ( ) ) ;
486485
487- this . http . get ( this . userinfoEndpoint , { headers } ) . map ( r => r . json ( ) ) . subscribe (
486+ this . http . get < any > ( this . userinfoEndpoint , { headers } ) . subscribe (
488487 ( doc ) => {
489488 this . debug ( 'userinfo received' , doc ) ;
490489
491490 let existingClaims = this . getIdentityClaims ( ) || { } ;
492-
491+
493492 if ( ! this . skipSubjectCheck ) {
494493 if ( this . oidc && ( ! existingClaims [ 'sub' ] || doc . sub !== existingClaims [ 'sub' ] ) ) {
495494 let err = 'if property oidc is true, the received user-id (sub) has to be the user-id '
@@ -522,7 +521,7 @@ export class OAuthService
522521 * @param password
523522 * @param headers Optional additional http-headers.
524523 */
525- public fetchTokenUsingPasswordFlow ( userName : string , password : string , headers : Headers = new Headers ( ) ) : Promise < object > {
524+ public fetchTokenUsingPasswordFlow ( userName : string , password : string , headers : HttpHeaders = new HttpHeaders ( ) ) : Promise < object > {
526525
527526 if ( ! this . validateUrlForHttps ( this . tokenEndpoint ) ) {
528527 throw new Error ( 'tokenEndpoint must use Http. Also check property requireHttps.' ) ;
@@ -544,7 +543,7 @@ export class OAuthService
544543
545544 let params = search . toString ( ) ;
546545
547- this . http . post ( this . tokenEndpoint , params , { headers } ) . map ( r => r . json ( ) ) . subscribe (
546+ this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
548547 ( tokenResponse ) => {
549548 this . debug ( 'tokenResponse' , tokenResponse ) ;
550549 this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
@@ -586,12 +585,12 @@ export class OAuthService
586585 search . set ( 'client_secret' , this . dummyClientSecret ) ;
587586 }
588587
589- let headers = new Headers ( ) ;
590- headers . set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
588+ const headers = new HttpHeaders ( )
589+ . set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
591590
592591 let params = search . toString ( ) ;
593592
594- this . http . post ( this . tokenEndpoint , params , { headers } ) . map ( r => r . json ( ) ) . subscribe (
593+ this . http . post < any > ( this . tokenEndpoint , params , { headers } ) . subscribe (
595594 ( tokenResponse ) => {
596595 this . debug ( 'refresh tokenResponse' , tokenResponse ) ;
597596 this . storeAccessTokenResponse ( tokenResponse . access_token , tokenResponse . refresh_token , tokenResponse . expires_in ) ;
@@ -785,8 +784,7 @@ export class OAuthService
785784 }
786785
787786 private waitForSilentRefreshAfterSessionChange ( ) {
788- this
789- . events
787+ this . events
790788 . filter ( ( e : OAuthEvent ) =>
791789 e . type === 'silently_refreshed'
792790 || e . type === 'silent_refresh_timeout'
@@ -1396,7 +1394,7 @@ export class OAuthService
13961394 this . _storage . removeItem ( 'id_token_expires_at' ) ;
13971395 this . _storage . removeItem ( 'id_token_stored_at' ) ;
13981396 this . _storage . removeItem ( 'access_token_stored_at' ) ;
1399-
1397+
14001398 this . silentRefreshSubject = null ;
14011399
14021400 if ( ! this . logoutUrl ) return ;
@@ -1406,7 +1404,7 @@ export class OAuthService
14061404 let logoutUrl : string ;
14071405
14081406 if ( ! this . validateUrlForHttps ( this . logoutUrl ) ) throw new Error ( 'logoutUrl must use Http. Also check property requireHttps.' ) ;
1409-
1407+
14101408 // For backward compatibility
14111409 if ( this . logoutUrl . indexOf ( '{{' ) > - 1 ) {
14121410 logoutUrl = this . logoutUrl . replace ( / \{ \{ i d _ t o k e n \} \} / , id_token ) ;
0 commit comments