diff --git a/CHANGELOG.md b/CHANGELOG.md index edc28b3d2..359282d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## 7.22.25 +## 7.22.26 + +- [10e7257](https://github.com/AxaFrance/oidc-client/commit/10e7257a0d2257bd8905b3b00ca1fe7ad757e74c) - fix(oidc): lock unexpected behavior (#1459) (release), 2024-09-27 by _Guillaume Chervet_ + +## v7.22.25 - [3a0d48e](https://github.com/AxaFrance/oidc-client/commit/3a0d48ea0d3609d31de0f45d6aebfb1a23b25e73) - fix(oidc): number timer increase (#1457) (release), 2024-09-26 by _Guillaume Chervet_ @@ -270,7 +274,3 @@ ## v7.13.15 - [c56cc84](https://github.com/AxaFrance/oidc-client/commit/c56cc842d8da427b2aa88eb71f7d63937ea3c363) - fix(react-oidc): missing console.log in useOidcFetch (release), 2024-01-16 by _Guillaume Chervet_ - -## v7.13.14 - -- [3a1883c](https://github.com/AxaFrance/oidc-client/commit/3a1883c343c55637aa1ce5d118cc2841c76d8752) - build(npm): bump react-router-dom from 6.20.1 to 6.21.1 (#1252), 2024-01-02 by _dependabot[bot]_ diff --git a/packages/oidc-client-service-worker/package.json b/packages/oidc-client-service-worker/package.json index 229daa012..d72dc5f5a 100644 --- a/packages/oidc-client-service-worker/package.json +++ b/packages/oidc-client-service-worker/package.json @@ -1,6 +1,6 @@ { "name": "@axa-fr/oidc-client-service-worker", - "version": "7.22.25", + "version": "7.22.26", "type": "module", "private": false, "main": "dist/OidcServiceWorker.js", diff --git a/packages/oidc-client-service-worker/src/version.ts b/packages/oidc-client-service-worker/src/version.ts index 151a0fac4..06bcc740a 100644 --- a/packages/oidc-client-service-worker/src/version.ts +++ b/packages/oidc-client-service-worker/src/version.ts @@ -1 +1 @@ -export default '7.22.25'; +export default '7.22.26'; diff --git a/packages/oidc-client/package.json b/packages/oidc-client/package.json index 431e82dcc..ba728d341 100644 --- a/packages/oidc-client/package.json +++ b/packages/oidc-client/package.json @@ -1,6 +1,6 @@ { "name": "@axa-fr/oidc-client", - "version": "7.22.25", + "version": "7.22.26", "private": false, "type": "module", "main": "./dist/index.umd.cjs", diff --git a/packages/oidc-client/src/fetch.ts b/packages/oidc-client/src/fetch.ts index e07cf8c51..85b6891d3 100644 --- a/packages/oidc-client/src/fetch.ts +++ b/packages/oidc-client/src/fetch.ts @@ -17,7 +17,11 @@ export const fetchWithTokens = const oidcToken: OidcToken = { tokens: oidc.tokens, - configuration: { token_automatic_renew_mode: oidc.configuration.token_automatic_renew_mode }, + configuration: { + token_automatic_renew_mode: oidc.configuration.token_automatic_renew_mode, + refresh_time_before_tokens_expiration_in_second: + oidc.configuration.refresh_time_before_tokens_expiration_in_second, + }, renewTokensAsync: oidc.renewTokensAsync.bind(oidc), }; diff --git a/packages/oidc-client/src/parseTokens.spec.ts b/packages/oidc-client/src/parseTokens.spec.ts index e2931f374..7af5c4512 100644 --- a/packages/oidc-client/src/parseTokens.spec.ts +++ b/packages/oidc-client/src/parseTokens.spec.ts @@ -30,6 +30,7 @@ describe('ParseTokens test Suite', () => { }, configuration: { token_automatic_renew_mode: TokenAutomaticRenewMode.AutomaticBeforeTokenExpiration, + refresh_time_before_tokens_expiration_in_second: 0, }, renewTokensAsync: async (_extras: StringMap) => { await sleepAsync({ milliseconds: 10 }); diff --git a/packages/oidc-client/src/parseTokens.ts b/packages/oidc-client/src/parseTokens.ts index f854da488..dd847ad1f 100644 --- a/packages/oidc-client/src/parseTokens.ts +++ b/packages/oidc-client/src/parseTokens.ts @@ -168,7 +168,10 @@ export const parseOriginalTokens = (tokens, oldTokens, tokenRenewMode: string) = return setTokens(data, oldTokens, tokenRenewMode); }; -export const computeTimeLeft = (refreshTimeBeforeTokensExpirationInSecond, expiresAt) => { +export const computeTimeLeft = ( + refreshTimeBeforeTokensExpirationInSecond: number, + expiresAt: number, +) => { const currentTimeUnixSecond = new Date().getTime() / 1000; const timeLeftSecond = expiresAt - currentTimeUnixSecond; @@ -176,11 +179,11 @@ export const computeTimeLeft = (refreshTimeBeforeTokensExpirationInSecond, expir return Math.round(timeLeftSecond - refreshTimeBeforeTokensExpirationInSecond); }; -export const isTokensValid = tokens => { +export const isTokensValid = (tokens, refreshTimeBeforeTokensExpirationInSecond: number = 0) => { if (!tokens) { return false; } - return computeTimeLeft(0, tokens.expiresAt) > 0; + return computeTimeLeft(refreshTimeBeforeTokensExpirationInSecond, tokens.expiresAt) > 0; }; export type ValidToken = { @@ -191,7 +194,10 @@ export type ValidToken = { export interface OidcToken { tokens?: Tokens; - configuration: { token_automatic_renew_mode?: TokenAutomaticRenewMode }; + configuration: { + token_automatic_renew_mode?: TokenAutomaticRenewMode; + refresh_time_before_tokens_expiration_in_second?: number; + }; renewTokensAsync: (extras: StringMap) => Promise; } @@ -204,7 +210,13 @@ export const getValidTokenAsync = async ( if (!oidc.tokens) { return null; } - while (!isTokensValid(oidc.tokens) && numberWaitTemp > 0) { + while ( + !isTokensValid( + oidc.tokens, + oidc.configuration.refresh_time_before_tokens_expiration_in_second, + ) && + numberWaitTemp > 0 + ) { if ( oidc.configuration.token_automatic_renew_mode == TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted diff --git a/packages/oidc-client/src/version.ts b/packages/oidc-client/src/version.ts index 151a0fac4..06bcc740a 100644 --- a/packages/oidc-client/src/version.ts +++ b/packages/oidc-client/src/version.ts @@ -1 +1 @@ -export default '7.22.25'; +export default '7.22.26'; diff --git a/packages/react-oidc/package.json b/packages/react-oidc/package.json index 95e939a91..a8ce1f426 100644 --- a/packages/react-oidc/package.json +++ b/packages/react-oidc/package.json @@ -1,6 +1,6 @@ { "name": "@axa-fr/react-oidc", - "version": "7.22.25", + "version": "7.22.26", "private": false, "type": "module", "main": "./dist/index.umd.cjs",