Skip to content

Commit

Permalink
fix(oidc): lock unexpected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Sep 27, 2024
1 parent 7a3e1f0 commit d028b49
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions packages/oidc-client/src/renewTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,6 @@ async function syncTokens(oidc: Oidc, forceRefresh: boolean, extras: StringMap)
return tokens;
}

const loadLatestTokensAsync = async (
oidc: Oidc,
configuration: OidcConfiguration,
): Promise<Tokens> => {
const serviceWorker = await initWorkerAsync(configuration, oidc.configurationName);
if (serviceWorker) {
const oidcServerConfiguration = await oidc.initAsync(
configuration.authority,
configuration.authority_configuration,
);
const { tokens } = await serviceWorker.initAsync(
oidcServerConfiguration,
'tryKeepExistingSessionAsync',
configuration,
);
return tokens;
} else {
const session = initSession(oidc.configurationName, configuration.storage ?? sessionStorage);
let { tokens } = await session.initAsync();
// @ts-ignore
tokens = setTokens(tokens, oidc.tokens, configuration.token_renew_mode);
return tokens;
}
};

export async function renewTokensAndStartTimerAsync(
oidc,
forceRefresh = false,
Expand All @@ -71,15 +46,19 @@ export async function renewTokensAndStartTimerAsync(
if (configuration?.storage === window?.sessionStorage && !serviceWorker) {
tokens = await syncTokens(oidc, forceRefresh, extras);
} else {
tokens = await navigator.locks.request(lockResourcesName, { ifAvailable: true }, async lock => {
if (!lock) {
oidc.publishEvent(Oidc.eventNames.syncTokensAsync_lock_not_available, {
lock: 'lock not available',
});
return await loadLatestTokensAsync(oidc, configuration);
}
return await syncTokens(oidc, forceRefresh, extras);
});
let status : any = "retry";

Check failure on line 49 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `·:·any·=·"retry"` with `:·any·=·'retry'`

Check failure on line 49 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `·:·any·=·"retry"` with `:·any·=·'retry'`
while (status === "retry") {

Check failure on line 50 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `"retry"` with `'retry'`

Check failure on line 50 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `"retry"` with `'retry'`
status = await navigator.locks.request(lockResourcesName, {ifAvailable: true}, async lock => {

Check failure on line 51 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `lockResourcesName,·{ifAvailable:·true},` with `⏎········lockResourcesName,⏎········{·ifAvailable:·true·},⏎·······`

Check failure on line 51 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `lockResourcesName,·{ifAvailable:·true},` with `⏎········lockResourcesName,⏎········{·ifAvailable:·true·},⏎·······`
if (!lock) {

Check failure on line 52 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`

Check failure on line 52 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`
oidc.publishEvent(Oidc.eventNames.syncTokensAsync_lock_not_available, {

Check failure on line 53 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`

Check failure on line 53 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`
lock: 'lock not available',

Check failure on line 54 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `············` with `··············`

Check failure on line 54 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `············` with `··············`
});

Check failure on line 55 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`

Check failure on line 55 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`
return "retry"

Check failure on line 56 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `··········return·"retry"` with `············return·'retry';`

Check failure on line 56 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Replace `··········return·"retry"` with `············return·'retry';`
}

Check failure on line 57 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`

Check failure on line 57 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`
return await syncTokens(oidc, forceRefresh, extras);

Check failure on line 58 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`

Check failure on line 58 in packages/oidc-client/src/renewTokens.ts

View workflow job for this annotation

GitHub Actions / Run linters

Insert `··`
});
}
tokens = status;
}

if (!tokens) {
Expand Down

0 comments on commit d028b49

Please sign in to comment.