@@ -523,6 +523,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
523523
524524 this . discoveryDocumentLoaded = true ;
525525 this . discoveryDocumentLoadedSubject . next ( doc ) ;
526+ this . revocationEndpoint = doc . revocation_endpoint ;
526527
527528 if ( this . sessionChecksEnabled ) {
528529 this . restartSessionChecksIfStillLoggedIn ( ) ;
@@ -625,6 +626,14 @@ export class OAuthService extends AuthConfig implements OnDestroy {
625626 ) ;
626627 }
627628
629+ errors = this . validateUrlFromDiscoveryDocument ( doc . revocation_endpoint ) ;
630+ if ( errors . length > 0 ) {
631+ this . logger . error (
632+ 'error validating revocation_endpoint in discovery document' ,
633+ errors
634+ ) ;
635+ }
636+
628637 errors = this . validateUrlFromDiscoveryDocument ( doc . userinfo_endpoint ) ;
629638 if ( errors . length > 0 ) {
630639 this . logger . error (
@@ -804,7 +813,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
804813 this . storeAccessTokenResponse (
805814 tokenResponse . access_token ,
806815 tokenResponse . refresh_token ,
807- tokenResponse . expires_in ,
816+ tokenResponse . expires_in ||
817+ this . fallbackAccessTokenExpirationTimeInSec ,
808818 tokenResponse . scope ,
809819 this . extractRecognizedCustomParameters ( tokenResponse )
810820 ) ;
@@ -890,7 +900,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
890900 this . storeAccessTokenResponse (
891901 tokenResponse . access_token ,
892902 tokenResponse . refresh_token ,
893- tokenResponse . expires_in ,
903+ tokenResponse . expires_in ||
904+ this . fallbackAccessTokenExpirationTimeInSec ,
894905 tokenResponse . scope ,
895906 this . extractRecognizedCustomParameters ( tokenResponse )
896907 ) ;
@@ -1729,7 +1740,8 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17291740 this . storeAccessTokenResponse (
17301741 tokenResponse . access_token ,
17311742 tokenResponse . refresh_token ,
1732- tokenResponse . expires_in ,
1743+ tokenResponse . expires_in ||
1744+ this . fallbackAccessTokenExpirationTimeInSec ,
17331745 tokenResponse . scope ,
17341746 this . extractRecognizedCustomParameters ( tokenResponse )
17351747 ) ;
@@ -2538,4 +2550,64 @@ export class OAuthService extends AuthConfig implements OnDestroy {
25382550 } ) ;
25392551 return foundParameters ;
25402552 }
2553+
2554+ /**
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+ */
2559+ public revokeTokenAndLogout ( ) : Promise < any > {
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+
2590+ return new Promise ( ( resolve , reject ) => {
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+ }
2611+ } ) ;
2612+ }
25412613}
0 commit comments