Skip to content

Commit

Permalink
feat(oauth-service): pass custom url params to logOut
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Jun 30, 2020
1 parent 8d83567 commit 4607d55
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,9 @@ export class OAuthService extends AuthConfig implements OnDestroy {
this.saveNoncesInLocalStorage &&
typeof window['localStorage'] !== 'undefined'
) {
localStorage.setItem('PKCI_verifier', verifier);
localStorage.setItem('PKCE_verifier', verifier);
} else {
this._storage.setItem('PKCI_verifier', verifier);
this._storage.setItem('PKCE_verifier', verifier);
}

url += '&code_challenge=' + challenge;
Expand Down Expand Up @@ -1689,21 +1689,21 @@ export class OAuthService extends AuthConfig implements OnDestroy {
.set('redirect_uri', options.customRedirectUri || this.redirectUri);

if (!this.disablePKCE) {
let pkciVerifier;
let PKCEVerifier;

if (
this.saveNoncesInLocalStorage &&
typeof window['localStorage'] !== 'undefined'
) {
pkciVerifier = localStorage.getItem('PKCI_verifier');
PKCEVerifier = localStorage.getItem('PKCE_verifier');
} else {
pkciVerifier = this._storage.getItem('PKCI_verifier');
PKCEVerifier = this._storage.getItem('PKCE_verifier');
}

if (!pkciVerifier) {
console.warn('No PKCI verifier found in oauth storage!');
if (!PKCEVerifier) {
console.warn('No PKCE verifier found in oauth storage!');
} else {
params = params.set('code_verifier', pkciVerifier);
params = params.set('code_verifier', PKCEVerifier);
}
}

Expand Down Expand Up @@ -2296,18 +2296,26 @@ export class OAuthService extends AuthConfig implements OnDestroy {
* @param noRedirectToLogoutUrl
* @param state
*/
public logOut(noRedirectToLogoutUrl = false, state = ''): void {
public logOut(customParameters: object): void;
public logOut(noRedirectToLogoutUrl: boolean, state: string): void;
public logOut(customParameters: boolean | object, state = ''): void {
let noRedirectToLogoutUrl = false;
if (typeof customParameters === 'boolean') {
noRedirectToLogoutUrl = customParameters;
customParameters = {};
}

const id_token = this.getIdToken();
this._storage.removeItem('access_token');
this._storage.removeItem('id_token');
this._storage.removeItem('refresh_token');

if (this.saveNoncesInLocalStorage) {
localStorage.removeItem('nonce');
localStorage.removeItem('PKCI_verifier');
localStorage.removeItem('PKCE_verifier');
} else {
this._storage.removeItem('nonce');
this._storage.removeItem('PKCI_verifier');
this._storage.removeItem('PKCE_verifier');
}

this._storage.removeItem('expires_at');
Expand Down Expand Up @@ -2366,6 +2374,10 @@ export class OAuthService extends AuthConfig implements OnDestroy {
}
}

for(let key in customParameters) {
params = params.set(key, customParameters[key]);
}

logoutUrl =
this.logoutUrl +
(this.logoutUrl.indexOf('?') > -1 ? '&' : '?') +
Expand Down

0 comments on commit 4607d55

Please sign in to comment.