@@ -813,7 +813,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
813
813
this . storeAccessTokenResponse (
814
814
tokenResponse . access_token ,
815
815
tokenResponse . refresh_token ,
816
- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
816
+ tokenResponse . expires_in ||
817
+ this . fallbackAccessTokenExpirationTimeInSec ,
817
818
tokenResponse . scope ,
818
819
this . extractRecognizedCustomParameters ( tokenResponse )
819
820
) ;
@@ -899,7 +900,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
899
900
this . storeAccessTokenResponse (
900
901
tokenResponse . access_token ,
901
902
tokenResponse . refresh_token ,
902
- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
903
+ tokenResponse . expires_in ||
904
+ this . fallbackAccessTokenExpirationTimeInSec ,
903
905
tokenResponse . scope ,
904
906
this . extractRecognizedCustomParameters ( tokenResponse )
905
907
) ;
@@ -1738,7 +1740,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
1738
1740
this . storeAccessTokenResponse (
1739
1741
tokenResponse . access_token ,
1740
1742
tokenResponse . refresh_token ,
1741
- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
1743
+ tokenResponse . expires_in ||
1744
+ this . fallbackAccessTokenExpirationTimeInSec ,
1742
1745
tokenResponse . scope ,
1743
1746
this . extractRecognizedCustomParameters ( tokenResponse )
1744
1747
) ;
@@ -2549,26 +2552,62 @@ export class OAuthService extends AuthConfig implements OnDestroy {
2549
2552
}
2550
2553
2551
2554
/**
2552
- * Revokes the auth token to secure the vulnarability
2553
- * of the token issued allowing the authorization server to clean
2554
- * up any security credentials associated with the authorization
2555
- */
2555
+ * Revokes the auth token to secure the vulnarability
2556
+ * of the token issued allowing the authorization server to clean
2557
+ * up any security credentials associated with the authorization
2558
+ */
2556
2559
public revokeTokenAndLogout ( ) : Promise < any > {
2557
- const revoke_endpoint = this . revocationEndpoint ;
2558
- const current_access_token = this . getAccessToken ( ) ;
2560
+ let revoke_endpoint = this . revocationEndpoint ;
2561
+ let current_access_token = this . getAccessToken ( ) ;
2562
+ let params = new HttpParams ( )
2563
+ . set ( 'token' , current_access_token )
2564
+ . set ( 'token_type_hint' , 'access_token' ) ;
2565
+
2566
+ let headers = new HttpHeaders ( ) . set (
2567
+ 'Content-Type' ,
2568
+ 'application/x-www-form-urlencoded'
2569
+ ) ;
2570
+
2571
+ if ( this . useHttpBasicAuth ) {
2572
+ const header = btoa ( `${ this . clientId } :${ this . dummyClientSecret } ` ) ;
2573
+ headers = headers . set ( 'Authorization' , 'Basic ' + header ) ;
2574
+ }
2575
+
2576
+ if ( ! this . useHttpBasicAuth ) {
2577
+ params = params . set ( 'client_id' , this . clientId ) ;
2578
+ }
2579
+
2580
+ if ( ! this . useHttpBasicAuth && this . dummyClientSecret ) {
2581
+ params = params . set ( 'client_secret' , this . dummyClientSecret ) ;
2582
+ }
2583
+
2584
+ if ( this . customQueryParams ) {
2585
+ for ( const key of Object . getOwnPropertyNames ( this . customQueryParams ) ) {
2586
+ params = params . set ( key , this . customQueryParams [ key ] ) ;
2587
+ }
2588
+ }
2589
+
2559
2590
return new Promise ( ( resolve , reject ) => {
2560
- fetch ( revoke_endpoint , {
2561
- method : 'POST' ,
2562
- headers :
2563
- {
2564
- 'Content-Type' : 'application/x-www-form-urlencoded'
2565
- } ,
2566
- body : `token=${ current_access_token } `
2567
- } ) . then ( res => {
2568
- console . log ( 'token successfully revoked' ) ;
2569
- this . logOut ( ) ;
2570
- resolve ( res ) ;
2571
- } ) ;
2591
+ if ( current_access_token ) {
2592
+ this . http
2593
+ . post < any > ( revoke_endpoint , params , { headers } )
2594
+ . subscribe (
2595
+ res => {
2596
+ this . logOut ( ) ;
2597
+ resolve ( res ) ;
2598
+ this . logger . info ( 'Token successfully revoked' ) ;
2599
+ } ,
2600
+ err => {
2601
+ this . logger . error ( 'Error revoking token' , err ) ;
2602
+ this . eventsSubject . next (
2603
+ new OAuthErrorEvent ( 'token_revoke_error' , err )
2604
+ ) ;
2605
+ reject ( err ) ;
2606
+ }
2607
+ ) ;
2608
+ } else {
2609
+ this . logger . warn ( 'User not logged in to revoke token.' ) ;
2610
+ }
2572
2611
} ) ;
2573
2612
}
2574
2613
}
0 commit comments