Skip to content

Commit 026dcb3

Browse files
committed
feat(oauth-service): revokeTokenAndLogout with cust params
1 parent 4607d55 commit 026dcb3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

projects/lib/src/oauth-service.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Injectable, NgZone, Optional, OnDestroy, Inject } from '@angular/core';
2-
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
2+
import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
33
import {
44
Observable,
55
Subject,
66
Subscription,
77
of,
88
race,
99
from,
10-
combineLatest
10+
combineLatest,
11+
throwError
1112
} from 'rxjs';
1213
import {
1314
filter,
@@ -16,7 +17,8 @@ import {
1617
tap,
1718
map,
1819
switchMap,
19-
debounceTime
20+
debounceTime,
21+
catchError
2022
} from 'rxjs/operators';
2123
import { DOCUMENT } from '@angular/common';
2224

@@ -2296,9 +2298,10 @@ export class OAuthService extends AuthConfig implements OnDestroy {
22962298
* @param noRedirectToLogoutUrl
22972299
* @param state
22982300
*/
2301+
public logOut(): void;
22992302
public logOut(customParameters: object): void;
23002303
public logOut(noRedirectToLogoutUrl: boolean, state: string): void;
2301-
public logOut(customParameters: boolean | object, state = ''): void {
2304+
public logOut(customParameters: boolean | object = {}, state = ''): void {
23022305
let noRedirectToLogoutUrl = false;
23032306
if (typeof customParameters === 'boolean') {
23042307
noRedirectToLogoutUrl = customParameters;
@@ -2576,7 +2579,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
25762579
* of the token issued allowing the authorization server to clean
25772580
* up any security credentials associated with the authorization
25782581
*/
2579-
public revokeTokenAndLogout(): Promise<any> {
2582+
public revokeTokenAndLogout(customParameters: object = {}, ignoreCorsIssues = false): Promise<any> {
25802583
let revokeEndpoint = this.revocationEndpoint;
25812584
let accessToken = this.getAccessToken();
25822585
let refreshToken = this.getRefreshToken();
@@ -2641,9 +2644,27 @@ export class OAuthService extends AuthConfig implements OnDestroy {
26412644
revokeRefreshToken = of(null);
26422645
}
26432646

2647+
if (ignoreCorsIssues) {
2648+
revokeAccessToken = revokeAccessToken
2649+
.pipe(catchError((err: HttpErrorResponse) => {
2650+
if (err.status === 0) {
2651+
return of<void>();
2652+
}
2653+
return throwError(err);
2654+
}));
2655+
2656+
revokeRefreshToken = revokeRefreshToken
2657+
.pipe(catchError((err: HttpErrorResponse) => {
2658+
if (err.status === 0) {
2659+
return of<void>();
2660+
}
2661+
return throwError(err);
2662+
}));
2663+
}
2664+
26442665
combineLatest([revokeAccessToken, revokeRefreshToken]).subscribe(
26452666
res => {
2646-
this.logOut();
2667+
this.logOut()
26472668
resolve(res);
26482669
this.logger.info('Token successfully revoked');
26492670
},

0 commit comments

Comments
 (0)