Skip to content

fix logout without OIDC (id_token false) #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,13 @@ export class OAuthService extends AuthConfig {
* @param noRedirectToLogoutUrl
*/
public logOut(noRedirectToLogoutUrl = false): void {
const id_token = this.getIdToken();

let id_token : string;

if(this.oidc) {
id_token = this.getIdToken();
}

this.clearStorage();

this.silentRefreshSubject = null;
Expand All @@ -1824,7 +1830,7 @@ export class OAuthService extends AuthConfig {
if (noRedirectToLogoutUrl) {
return;
}
if (!id_token) {
if (this.oidc && !id_token) {
return;
}

Expand All @@ -1838,18 +1844,25 @@ export class OAuthService extends AuthConfig {

// For backward compatibility
if (this.logoutUrl.indexOf('{{') > -1) {
logoutUrl = this.logoutUrl
.replace(/\{\{id_token\}\}/, id_token)
.replace(/\{\{client_id\}\}/, this.clientId);
logoutUrl = this.logoutUrl.replace(/\{\{client_id\}\}/, this.clientId);
if(this.oidc) {
logoutUrl = logoutUrl.replace(/\{\{id_token\}\}/, id_token);
}
} else {
logoutUrl =
this.logoutUrl +
(this.logoutUrl.indexOf('?') > -1 ? '&' : '?') +
'id_token_hint=' +
encodeURIComponent(id_token) +
'&post_logout_redirect_uri=' +
encodeURIComponent(this.postLogoutRedirectUri || this.redirectUri);
(this.logoutUrl.indexOf('?') > -1 ? '&' : '?');

let params = [];
if(this.oidc) {
params.push('id_token_hint=' + encodeURIComponent(id_token));
}

params.push('post_logout_redirect_uri=' +
encodeURIComponent(this.postLogoutRedirectUri || this.redirectUri));
logoutUrl += params.join("&");
}

location.href = logoutUrl;
}

Expand Down