Skip to content

Commit

Permalink
fix(oidc): record tabIds when service worker receives init event (rel…
Browse files Browse the repository at this point in the history
…ease)
  • Loading branch information
mkrzempek authored and guillaume-chervet committed Jul 22, 2024
1 parent 6b5f6b4 commit 05ace2d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/oidc-client-service-worker/src/OidcServiceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const handleFetch = async (event: FetchEvent) => {
let newBody = actualBody;
for (let i = 0; i < numberDatabase; i++) {
const currentDb = currentDatabases[i];
const currentDbTabs = Object.keys(currentDb.state);
const currentDbTabs = currentDb.tabIds;

if (currentDb?.tokens != null) {
const claimsExtras = {
Expand Down Expand Up @@ -338,6 +338,7 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
: trustedDomain.allowMultiTabLogin;
database[configurationName] = {
tokens: null,
tabIds: [],
state: {},
codeVerifier: {},
oidcServerConfiguration: null,
Expand Down Expand Up @@ -366,6 +367,7 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
switch (data.type) {
case 'clear':
currentDatabase.tokens = null;
currentDatabase.tabIds = [];
currentDatabase.state = {};
currentDatabase.codeVerifier = {};
currentDatabase.demonstratingProofOfPossessionNonce = null;
Expand All @@ -391,6 +393,9 @@ const handleMessage = async (event: ExtendableMessageEvent) => {
}
currentDatabase.oidcServerConfiguration = oidcServerConfiguration;
currentDatabase.oidcConfiguration = data.data.oidcConfiguration;
if (!currentDatabase.tabIds.includes(tabId)) {
currentDatabase.tabIds.push(tabId);
}

if (currentDatabase.demonstratingProofOfPossessionConfiguration == null) {
const demonstratingProofOfPossessionConfiguration = getDpopConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const oidcConfigDefaults = {
demonstratingProofOfPossessionConfiguration: null,
configurationName: '',
tokens: null,
tabIds: [],
status: null,
state: {},
codeVerifier: {},
Expand Down
1 change: 1 addition & 0 deletions packages/oidc-client-service-worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type Nonce = {
export type OidcConfig = {
demonstratingProofOfPossessionConfiguration: DemonstratingProofOfPossessionConfiguration | null;
configurationName: string;
tabIds: string[];
tokens: Tokens | null;
status: Status;
state: Record<string, string | null>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('domains', () => {
default: {
configurationName: 'config',
tokens: {} as Tokens,
tabIds: [],
status: 'NOT_CONNECTED',
state: {},
codeVerifier: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class OidcConfigBuilder {
private oidcConfig: OidcConfig = {
configurationName: '',
tokens: null,
tabIds: [],
status: 'NOT_CONNECTED',
state: { tab1: '' },
codeVerifier: { tab1: '' },
Expand Down

0 comments on commit 05ace2d

Please sign in to comment.