diff --git a/CHANGELOG.md b/CHANGELOG.md index c7ae3730d..cb566180e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## 7.12.11 +## 7.12.12 + +- [b070c88](https://github.com/AxaFrance/oidc-client/commit/b070c8848582ac6f52ab7cb00f16b0fe9f702b5f) - fix(oidc-client): Update README.md (release), 2023-11-30 by *Guillaume Chervet* + + +## v7.12.11 - [d1480fb](https://github.com/AxaFrance/oidc-client/commit/d1480fbe2c0e275f17775768f83b70d9adf00ee1) - fix(all): dependencies update break the build (release), 2023-11-30 by *Guillaume Chervet* - [6027511](https://github.com/AxaFrance/oidc-client/commit/6027511a0c8d2112d370d45cf42f144874112f77) - doc(readme) Update README.md, 2023-11-29 by *Guillaume Chervet* @@ -329,9 +334,3 @@ - [db00519](https://github.com/AxaFrance/oidc-client/commit/db00519628cbd0a6f865539245321bcc85570f15) - fix test (alpha), 2023-07-20 by *Guillaume Chervet* -## v6.24.21 - -- [40ec599](https://github.com/AxaFrance/oidc-client/commit/40ec5994043d3a8c294e520e10d24bd5f1e8a02f) - Merge 822f9aba2b245872401fa15905e7e256e4adb879 into 3e535c94dc57d59956498bfa0ca9536106039bda, 2023-07-20 by *Guillaume Chervet* -- [822f9ab](https://github.com/AxaFrance/oidc-client/commit/822f9aba2b245872401fa15905e7e256e4adb879) - test (alpha), 2023-07-20 by *Guillaume Chervet* - - diff --git a/packages/oidc-client-service-worker/package.json b/packages/oidc-client-service-worker/package.json index 97561cedf..5ec2fffb9 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.12.11", + "version": "7.12.12", "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 f75f36be0..e1117b1d6 100644 --- a/packages/oidc-client-service-worker/src/version.ts +++ b/packages/oidc-client-service-worker/src/version.ts @@ -1 +1 @@ -export default '7.12.11'; +export default '7.12.12'; diff --git a/packages/oidc-client/README.md b/packages/oidc-client/README.md index a17f2b93f..b958d2bc0 100644 --- a/packages/oidc-client/README.md +++ b/packages/oidc-client/README.md @@ -194,9 +194,10 @@ const configuration = { refresh_time_before_tokens_expiration_in_second: Number, // default is 120 seconds service_worker_relative_url: String, service_worker_keep_alive_path: String, // default is "/" - service_worker_only: Boolean, // default false - service_worker_activate: () => boolean, // you can take the control of the service worker default activation which use user agent string + service_worker_only: Boolean, // default false, if true, the user will not be able to login if the service worker is not available on its browser + service_worker_activate: () => boolean, // you can take the control of the service worker default activation which use user agent string, if return false, the service worker mode will not be used service_worker_update_require_callback: (registration:any, stopKeepAlive:Function) => Promise, // callback called when service worker need to be updated, you can take the control of the update process + service_worker_register: (url: string) => Promise, // Optional, you can take the control of the service worker registration extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that is sent to the OIDC server (more info: https://github.com/openid/AppAuth-JS) token_request_extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that is sent to the OIDC server during token request (more info: https://github.com/openid/AppAuth-JS) authority_time_cache_wellknowurl_in_second: 60 * 60, // Time to cache in seconds of the openid well-known URL, default is 1 hour diff --git a/packages/oidc-client/package.json b/packages/oidc-client/package.json index faf9d640a..0a900c072 100644 --- a/packages/oidc-client/package.json +++ b/packages/oidc-client/package.json @@ -1,6 +1,6 @@ { "name": "@axa-fr/oidc-client", - "version": "7.12.11", + "version": "7.12.12", "private": false, "type": "module", "main": "./dist/index.umd.cjs", diff --git a/packages/oidc-client/src/initWorker.ts b/packages/oidc-client/src/initWorker.ts index 229a4471f..959bc0a75 100644 --- a/packages/oidc-client/src/initWorker.ts +++ b/packages/oidc-client/src/initWorker.ts @@ -6,7 +6,7 @@ import {ILOidcLocation} from "./location"; let keepAliveServiceWorkerTimeoutId = null; let keepAliveController; -export const sleepAsync = (milliseconds) => { +export const sleepAsync = ({milliseconds}: { milliseconds: any }) => { return new Promise(resolve => timer.setTimeout(resolve, milliseconds)); }; @@ -16,7 +16,7 @@ const keepAlive = (service_worker_keep_alive_path='/') => { keepAliveController = new AbortController(); const promise = fetch(`${service_worker_keep_alive_path}OidcKeepAliveServiceWorker.json?minSleepSeconds=${minSleepSeconds}`, { signal: keepAliveController.signal }); promise.catch(error => { console.log(error); }); - sleepAsync(minSleepSeconds * 1000).then(keepAlive); + sleepAsync({milliseconds: minSleepSeconds * 1000}).then(keepAlive); } catch (error) { console.log(error); } }; @@ -41,7 +41,7 @@ export const defaultServiceWorkerUpdateRequireCallback = (location:ILOidcLocatio await registration.update(); const isSuccess = await registration.unregister(); console.log(`Service worker unregistering ${isSuccess}`) - await sleepAsync(2000); + await sleepAsync({milliseconds: 2000}); location.reload(); } @@ -72,7 +72,12 @@ export const initWorkerAsync = async(configuration, configurationName) => { return null; } - const registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl); + let registration = null; + if(configuration.register) { + registration = await configuration.service_worker_register(serviceWorkerRelativeUrl); + } else { + registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl); + } try { await navigator.serviceWorker.ready; diff --git a/packages/oidc-client/src/oidc.ts b/packages/oidc-client/src/oidc.ts index 0d53d90cf..b0e023a6a 100644 --- a/packages/oidc-client/src/oidc.ts +++ b/packages/oidc-client/src/oidc.ts @@ -352,18 +352,18 @@ Please checkout that you are using OIDC hook inside a 0) { - await sleepAsync(1000); + await sleepAsync({milliseconds: 1000}); numberTryOnline--; this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` }); } let numberTryHidden = Math.floor(Math.random() * 15) + 10; while (document.hidden && numberTryHidden > 0) { - await sleepAsync(1000); + await sleepAsync({milliseconds: 1000}); numberTryHidden--; this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` }); } diff --git a/packages/oidc-client/src/parseTokens.ts b/packages/oidc-client/src/parseTokens.ts index c57816ca9..b1e6f83df 100644 --- a/packages/oidc-client/src/parseTokens.ts +++ b/packages/oidc-client/src/parseTokens.ts @@ -173,7 +173,7 @@ export const getValidTokenAsync = async (oidc: OidcToken, waitMs = 200, numberWa return null; } while (!isTokensValid(oidc.tokens) && numberWaitTemp > 0) { - await sleepAsync(waitMs); + await sleepAsync({milliseconds: waitMs}); numberWaitTemp = numberWaitTemp - 1; } const isValid = isTokensValid(oidc.tokens); diff --git a/packages/oidc-client/src/types.ts b/packages/oidc-client/src/types.ts index 89e4e7a44..54180c818 100644 --- a/packages/oidc-client/src/types.ts +++ b/packages/oidc-client/src/types.ts @@ -3,6 +3,7 @@ export type Fetch = typeof window.fetch; export type LogoutToken = 'access_token' | 'refresh_token'; export type ServiceWorkerUpdateRequireCallback = (registration:any, stopKeepAlive:Function) => Promise; +export type ServiceWorkerRegister = (serviceWorkerRelativeUrl:string) => Promise; export type ServiceWorkerActivate = () => boolean; export type OidcConfiguration = { @@ -19,6 +20,7 @@ export type OidcConfiguration = { refresh_time_before_tokens_expiration_in_second?: number; token_request_timeout?: number; service_worker_relative_url?:string; + service_worker_register?:ServiceWorkerRegister; service_worker_keep_alive_path?:string; service_worker_activate?:ServiceWorkerActivate; service_worker_only?:boolean; diff --git a/packages/oidc-client/src/user.ts b/packages/oidc-client/src/user.ts index ebc1d0600..5068c6435 100644 --- a/packages/oidc-client/src/user.ts +++ b/packages/oidc-client/src/user.ts @@ -8,7 +8,7 @@ export const userInfoAsync = (oidc) => async (noCache = false) => { // We wait the synchronisation before making a request while (oidc.tokens && !isTokensValid(oidc.tokens)) { - await sleepAsync(200); + await sleepAsync({milliseconds: 200}); } if (!oidc.tokens) { diff --git a/packages/oidc-client/src/version.ts b/packages/oidc-client/src/version.ts index f75f36be0..e1117b1d6 100644 --- a/packages/oidc-client/src/version.ts +++ b/packages/oidc-client/src/version.ts @@ -1 +1 @@ -export default '7.12.11'; +export default '7.12.12'; diff --git a/packages/react-oidc/README.md b/packages/react-oidc/README.md index 638da1918..8abaddeb2 100644 --- a/packages/react-oidc/README.md +++ b/packages/react-oidc/README.md @@ -191,6 +191,7 @@ const configuration = { service_worker_only: Boolean, // default false service_worker_activate: () => boolean, // you can take the control of the service worker default activation which use user agent string service_worker_update_require_callback: (registration:any, stopKeepAlive:Function) => Promise, // callback called when service worker need to be updated, you can take the control of the update process + service_worker_register: (url: string) => Promise, // Optional, you can take the control of the service worker registration extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that is sent to the OIDC server (more info: https://github.com/openid/AppAuth-JS) token_request_extras: StringMap | undefined, // ex: {'prompt': 'consent', 'access_type': 'offline'} list of key/value that is sent to the OIDC server during token request (more info: https://github.com/openid/AppAuth-JS) withCustomHistory: Function, // Override history modification, return an instance with replaceState(url, stateHistory) implemented (like History.replaceState()) diff --git a/packages/react-oidc/package.json b/packages/react-oidc/package.json index acaa15593..082bddf35 100644 --- a/packages/react-oidc/package.json +++ b/packages/react-oidc/package.json @@ -1,6 +1,6 @@ { "name": "@axa-fr/react-oidc", - "version": "7.12.11", + "version": "7.12.12", "private": false, "type": "module", "main": "./dist/index.umd.cjs",