@@ -813,7 +813,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
813813 this . storeAccessTokenResponse (
814814 tokenResponse . access_token ,
815815 tokenResponse . refresh_token ,
816- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
816+ tokenResponse . expires_in ||
817+ this . fallbackAccessTokenExpirationTimeInSec ,
817818 tokenResponse . scope ,
818819 this . extractRecognizedCustomParameters ( tokenResponse )
819820 ) ;
@@ -899,7 +900,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
899900 this . storeAccessTokenResponse (
900901 tokenResponse . access_token ,
901902 tokenResponse . refresh_token ,
902- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
903+ tokenResponse . expires_in ||
904+ this . fallbackAccessTokenExpirationTimeInSec ,
903905 tokenResponse . scope ,
904906 this . extractRecognizedCustomParameters ( tokenResponse )
905907 ) ;
@@ -1738,7 +1740,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17381740 this . storeAccessTokenResponse (
17391741 tokenResponse . access_token ,
17401742 tokenResponse . refresh_token ,
1741- tokenResponse . expires_in || this . fallbackAccessTokenExpirationTimeInSec ,
1743+ tokenResponse . expires_in ||
1744+ this . fallbackAccessTokenExpirationTimeInSec ,
17421745 tokenResponse . scope ,
17431746 this . extractRecognizedCustomParameters ( tokenResponse )
17441747 ) ;
@@ -2549,26 +2552,62 @@ export class OAuthService extends AuthConfig implements OnDestroy {
25492552 }
25502553
25512554 /**
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+ */
25562559 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+
25592590 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+ }
25722611 } ) ;
25732612 }
25742613}
0 commit comments