1- import { Injectable , Optional } from '@angular/core' ;
1+ import { Injectable , NgZone , Optional } from '@angular/core'
22import { HttpClient , HttpHeaders , HttpParams } from '@angular/common/http' ;
33import { Observable , Subject , Subscription , of , race } from 'rxjs' ;
44import { filter , take , delay , first , tap , map } from 'rxjs/operators' ;
@@ -67,6 +67,7 @@ export class OAuthService
6767 private inImplicitFlow = false ;
6868
6969 constructor (
70+ private ngZone : NgZone ,
7071 private http : HttpClient ,
7172 @Optional ( ) storage : OAuthStorage ,
7273 @Optional ( ) tokenValidationHandler : ValidationHandler ,
@@ -263,10 +264,16 @@ export class OAuthService
263264 let storedAt = this . getAccessTokenStoredAt ( ) ;
264265 let timeout = this . calcTimeout ( storedAt , expiration ) ;
265266
266- this . accessTokenTimeoutSubscription =
267- of ( new OAuthInfoEvent ( 'token_expires' , 'access_token' ) )
268- . pipe ( delay ( timeout ) )
269- . subscribe ( e => this . eventsSubject . next ( e ) ) ;
267+ this . ngZone . runOutsideAngular ( ( ) => {
268+ this . accessTokenTimeoutSubscription =
269+ of ( new OAuthInfoEvent ( 'token_expires' , 'access_token' ) )
270+ . pipe ( delay ( timeout ) )
271+ . subscribe ( e => {
272+ this . ngZone . run ( ( ) => {
273+ this . eventsSubject . next ( e ) ;
274+ } )
275+ } ) ;
276+ } )
270277 }
271278
272279
@@ -275,10 +282,16 @@ export class OAuthService
275282 let storedAt = this . getIdTokenStoredAt ( ) ;
276283 let timeout = this . calcTimeout ( storedAt , expiration ) ;
277284
278- this . idTokenTimeoutSubscription =
279- of ( new OAuthInfoEvent ( 'token_expires' , 'id_token' ) )
280- . pipe ( delay ( timeout ) )
281- . subscribe ( e => this . eventsSubject . next ( e ) ) ;
285+ this . ngZone . runOutsideAngular ( ( ) => {
286+ this . idTokenTimeoutSubscription =
287+ of ( new OAuthInfoEvent ( 'token_expires' , 'id_token' ) )
288+ . pipe ( delay ( timeout ) )
289+ . subscribe ( e => {
290+ this . ngZone . run ( ( ) => {
291+ this . eventsSubject . next ( e ) ;
292+ } )
293+ } ) ;
294+ } )
282295 }
283296
284297 private clearAccessTokenTimer ( ) : void {
0 commit comments