diff --git a/CHANGELOG.md b/CHANGELOG.md index fa2bced4d..ac450d052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## 7.22.13 +## 7.22.14 + +- [25c55ee](https://github.com/AxaFrance/oidc-client/commit/25c55eeb7682356c13987a91d7b8645cca1b0ad5) - refactor(oidc): null coalescing (#1404) (release), 2024-07-11 by *Jason Finch* + + +## v7.22.13 - [95c814d](https://github.com/AxaFrance/oidc-client/commit/95c814dd9dd325a3a00c3a0dc049d301d983514e) - fix(ci): setup pnpm (release) (#1399), 2024-07-05 by *Guillaume Chervet* @@ -310,8 +315,3 @@ - [43eac59](https://github.com/AxaFrance/oidc-client/commit/43eac59f1598ab6a5b07dc52deed95297c73f875) - build(npm): bump vite-plugin-dts from 3.4.0 to 3.6.4 (#1227), 2023-12-07 by *dependabot[bot]* -## v7.13.2 - -- [430a06b](https://github.com/AxaFrance/oidc-client/commit/430a06b27b2f7164bc1557a2e55e547b5af3d8d7) - build(npm): bump vite from 4.4.7 to 4.4.12 (#1231), 2023-12-07 by *dependabot[bot]* - - diff --git a/examples/react-oidc-demo/src/Profile.tsx b/examples/react-oidc-demo/src/Profile.tsx index 25d5584fd..73a1028eb 100644 --- a/examples/react-oidc-demo/src/Profile.tsx +++ b/examples/react-oidc-demo/src/Profile.tsx @@ -41,7 +41,7 @@ const DisplayUserInfo = () => { export const Profile = () => { const { logout, isAuthenticated } = useOidc(); return ( -
+
{isAuthenticated &&

} diff --git a/packages/oidc-client-service-worker/package.json b/packages/oidc-client-service-worker/package.json index 9b4f1c20c..6f17eb793 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.13", + "version": "7.22.14", "type": "module", "private": false, "main": "dist/OidcServiceWorker.js", diff --git a/packages/oidc-client-service-worker/src/OidcServiceWorker.ts b/packages/oidc-client-service-worker/src/OidcServiceWorker.ts index 768b5bf9f..1d4466c11 100644 --- a/packages/oidc-client-service-worker/src/OidcServiceWorker.ts +++ b/packages/oidc-client-service-worker/src/OidcServiceWorker.ts @@ -20,6 +20,7 @@ import version from './version'; import {generateJwkAsync, generateJwtDemonstratingProofOfPossessionAsync} from "./jwt"; import {getDpopConfiguration, getDpopOnlyWhenDpopHeaderPresent} from "./dpop"; import {base64urlOfHashOfASCIIEncodingAsync} from "./crypto"; +import { getCurrentDatabasesTokenEndpoint } from './oidcConfig'; // @ts-ignore if (typeof trustedTypes !== 'undefined' && typeof trustedTypes.createPolicy == 'function') { @@ -56,27 +57,6 @@ const handleActivate = (event: ExtendableEvent) => { const database: Database = {}; -const getCurrentDatabasesTokenEndpoint = (database: Database, url: string) => { - const databases: OidcConfig[] = []; - for (const [, value] of Object.entries(database)) { - if ( - value.oidcServerConfiguration != null && - url.startsWith(normalizeUrl(value.oidcServerConfiguration.tokenEndpoint)) - ) { - databases.push(value); - } else if ( - value.oidcServerConfiguration != null && - value.oidcServerConfiguration.revocationEndpoint && - url.startsWith( - normalizeUrl(value.oidcServerConfiguration.revocationEndpoint), - ) - ) { - databases.push(value); - } - } - return databases; -}; - const keepAliveAsync = async (event: FetchEvent) => { const originalRequest = event.request; const isFromVanilla = originalRequest.headers.has('oidc-vanilla'); diff --git a/packages/oidc-client-service-worker/src/__tests__/oidcConfig.spec.ts b/packages/oidc-client-service-worker/src/__tests__/oidcConfig.spec.ts new file mode 100644 index 000000000..186fff848 --- /dev/null +++ b/packages/oidc-client-service-worker/src/__tests__/oidcConfig.spec.ts @@ -0,0 +1,152 @@ +import { describe, expect, it } from 'vitest' +import { getCurrentDatabasesTokenEndpoint } from '../oidcConfig' +import { Database } from '../types' + +const oidcConfigDefaults = { + demonstratingProofOfPossessionConfiguration: null, + configurationName: '', + tokens: null, + status: null, + state: null, + codeVerifier: null, + nonce: null, + hideAccessToken: false, + convertAllRequestsToCorsExceptNavigate: true, + setAccessTokenToNavigateRequests: true, + demonstratingProofOfPossessionNonce: null, + demonstratingProofOfPossessionJwkJson: null, + demonstratingProofOfPossessionOnlyWhenDpopHeaderPresent: false, +} + +const oidcServerConfigDefault = { + revocationEndpoint: '', + tokenEndpoint: '', + issuer: '', + userInfoEndpoint: '', + authorizationEndpoint: '' +} + +describe('getCurrentDatabasesTokenEndpoint', () => { + it('should return configs with matching token endpoint', () => { + const database: Database = { + config1: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.com/token', + }, + }, + config2: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.org/token', + }, + }, + config3: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + revocationEndpoint: 'https://example.net/revoke', + }, + }, + } + + const url = 'https://example.com/token' + const result = getCurrentDatabasesTokenEndpoint(database, url) + + expect(result).toHaveLength(1) + expect(result[0]).toBe(database.config1) + }) + + it('should return configs with matching revocation endpoint', () => { + const database = { + config1: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + revocationEndpoint: 'https://example.com/revoke', + }, + }, + config2: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + revocationEndpoint: 'https://example.org/revoke', + }, + }, + config3: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.net/token', + }, + }, + } + + const url = 'https://example.com/revoke' + const result = getCurrentDatabasesTokenEndpoint(database, url) + + expect(result).toHaveLength(1) + expect(result[0]).toBe(database.config1) + }) + + it('should return multiple matching configs', () => { + const database = { + config1: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.com/token', + revocationEndpoint: 'https://example.com/revoke', + }, + }, + config2: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.org/token', + }, + }, + config3: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.com/token', + revocationEndpoint: 'https://example.com/revoke', + }, + }, + } + + const url = 'https://example.com/token' + const result = getCurrentDatabasesTokenEndpoint(database, url) + + expect(result).toHaveLength(2) + expect(result).toContain(database.config1) + expect(result).toContain(database.config3) + }) + + it('should return empty array for no matching configs', () => { + const database = { + config1: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + tokenEndpoint: 'https://example.com/token', + }, + }, + config2: { + ...oidcConfigDefaults, + oidcServerConfiguration: { + ...oidcServerConfigDefault, + revocationEndpoint: 'https://example.org/revoke', + }, + }, + } + + const url = 'https://example.net/other' + const result = getCurrentDatabasesTokenEndpoint(database, url) + + expect(result).toHaveLength(0) + }) +}) diff --git a/packages/oidc-client-service-worker/src/oidcConfig.ts b/packages/oidc-client-service-worker/src/oidcConfig.ts new file mode 100644 index 000000000..5b6fcf93d --- /dev/null +++ b/packages/oidc-client-service-worker/src/oidcConfig.ts @@ -0,0 +1,17 @@ +import { Database, OidcConfig } from './types'; +import { normalizeUrl } from './utils'; + +const getMatchingOidcConfigurations = (database: Database, url: string): OidcConfig[] => { + return Object.values(database).filter((config) => { + const { oidcServerConfiguration } = config || {}; + const { tokenEndpoint, revocationEndpoint } = oidcServerConfiguration || {}; + + const normalizedUrl = normalizeUrl(url); + return ( + (tokenEndpoint && normalizedUrl.startsWith(normalizeUrl(tokenEndpoint))) || + (revocationEndpoint && normalizedUrl.startsWith(normalizeUrl(revocationEndpoint))) + ); + }); +}; + +export { getMatchingOidcConfigurations as getCurrentDatabasesTokenEndpoint }; diff --git a/packages/oidc-client-service-worker/src/version.ts b/packages/oidc-client-service-worker/src/version.ts index 5c5154488..03d2f7ab3 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.13'; +export default '7.22.14'; diff --git a/packages/oidc-client/package.json b/packages/oidc-client/package.json index b212dee77..dfabd6d3b 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.13", + "version": "7.22.14", "private": false, "type": "module", "main": "./dist/index.umd.cjs", diff --git a/packages/oidc-client/src/version.ts b/packages/oidc-client/src/version.ts index 5c5154488..03d2f7ab3 100644 --- a/packages/oidc-client/src/version.ts +++ b/packages/oidc-client/src/version.ts @@ -1 +1 @@ -export default '7.22.13'; +export default '7.22.14'; diff --git a/packages/react-oidc/package.json b/packages/react-oidc/package.json index 246937cbe..0eb33fbaf 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.13", + "version": "7.22.14", "private": false, "type": "module", "main": "./dist/index.umd.cjs",