Skip to content

Commit

Permalink
fix(logout): add event when same config name (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Feb 2, 2024
1 parent 0a15e60 commit 31f295c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/oidc-client/src/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { performRevocationRequestAsync, TOKEN_TYPE } from './requests.js';
import timer from './timer.js';
import { StringMap } from './types.js';
import {ILOidcLocation} from "./location";
import Oidc from "./oidc";
import {eventNames} from "./events";

export const oidcLogoutTokens = {
access_token: 'access_token',
Expand Down Expand Up @@ -67,15 +67,18 @@ export const logoutAsync = (oidc, oidcDatabase, fetch, console, oicLocation:ILOi
}
// @ts-ignore
const sub = oidc.tokens && oidc.tokens.idTokenPayload ? oidc.tokens.idTokenPayload.sub : null;
await oidc.destroyAsync('LOGGED_OUT');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [key, itemOidc] of Object.entries(oidcDatabase)) {
if (itemOidc !== oidc) {
// @ts-ignore
await oidc.logoutSameTabAsync(oidc.configuration.client_id, sub);
} else {
oidc.publishEvent(eventNames.logout_from_same_tab, {} );
}
}

await oidc.destroyAsync('LOGGED_OUT');

if (oidcServerConfiguration.endSessionEndpoint) {
if (!extras) {
extras = {
Expand Down
6 changes: 3 additions & 3 deletions packages/oidc-client/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
async logoutSameTabAsync(clientId: string, sub: any) {
// @ts-ignore
if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
this.publishEvent(eventNames.logout_from_same_tab, { message: sub });
this.publishEvent(eventNames.logout_from_same_tab, { mmessage: 'SessionMonitor', sub });
await this.destroyAsync('LOGGED_OUT');
}
}
}

async logoutOtherTabAsync(clientId: string, sub: any) {
// @ts-ignore
if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
await this.destroyAsync('LOGGED_OUT');
this.publishEvent(eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
await this.destroyAsync('LOGGED_OUT');
}
}

Expand Down

0 comments on commit 31f295c

Please sign in to comment.