@axa-fr/react-oidc 6.24.27-beta929 → 6.25.1-alpha941
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/post-install.js +35 -0
- package/dist/FetchToken.d.ts +2 -3
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/OidcProvider.d.ts +4 -5
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts +3 -3
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcServiceWorker.js +559 -0
- package/{service_worker → dist}/OidcTrustedDomains.js +4 -5
- package/dist/ReactOidc.d.ts +4 -4
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.d.ts +2 -2
- package/dist/User.d.ts.map +1 -1
- package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
- package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
- package/dist/core/default-component/Callback.component.d.ts.map +1 -1
- package/dist/core/default-component/Loading.component.d.ts.map +1 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
- package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
- package/dist/core/default-component/index.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/index.d.ts +3 -0
- package/dist/core/routes/index.d.ts.map +1 -0
- package/dist/core/routes/withRouter.d.ts +4 -4
- package/dist/core/routes/withRouter.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +964 -21
- package/dist/index.umd.cjs +27 -0
- package/package.json +37 -42
- package/src/{oidc/FetchToken.tsx → FetchToken.tsx} +14 -16
- package/src/{oidc/OidcProvider.tsx → OidcProvider.tsx} +40 -42
- package/src/{oidc/OidcSecure.tsx → OidcSecure.tsx} +1 -3
- package/src/{oidc/ReactOidc.tsx → ReactOidc.tsx} +1 -3
- package/src/{oidc/User.ts → User.ts} +1 -2
- package/src/{oidc/core → core}/default-component/AuthenticateError.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Authenticating.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Callback.component.tsx +2 -2
- package/src/{oidc/core → core}/default-component/Loading.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/ServiceWorkerNotSupported.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/SessionLost.component.tsx +1 -1
- package/src/{oidc/core → core}/default-component/SilentCallback.component.tsx +1 -2
- package/src/{oidc/core → core}/default-component/SilentLogin.component.tsx +1 -3
- package/src/{oidc/core → core}/routes/OidcRoutes.spec.tsx +3 -2
- package/src/{oidc/core → core}/routes/OidcRoutes.tsx +6 -6
- package/src/{oidc/core → core}/routes/withRouter.spec.tsx +3 -5
- package/src/{oidc/index.ts → index.ts} +7 -2
- package/bin/copy.cjs +0 -43
- package/dist/FetchToken.js +0 -59
- package/dist/FetchToken.js.map +0 -1
- package/dist/OidcProvider.js +0 -134
- package/dist/OidcProvider.js.map +0 -1
- package/dist/OidcSecure.js +0 -25
- package/dist/OidcSecure.js.map +0 -1
- package/dist/ReactOidc.js +0 -156
- package/dist/ReactOidc.js.map +0 -1
- package/dist/User.js +0 -42
- package/dist/User.js.map +0 -1
- package/dist/core/default-component/AuthenticateError.component.js +0 -6
- package/dist/core/default-component/AuthenticateError.component.js.map +0 -1
- package/dist/core/default-component/Authenticating.component.js +0 -6
- package/dist/core/default-component/Authenticating.component.js.map +0 -1
- package/dist/core/default-component/Callback.component.js +0 -54
- package/dist/core/default-component/Callback.component.js.map +0 -1
- package/dist/core/default-component/Loading.component.js +0 -6
- package/dist/core/default-component/Loading.component.js.map +0 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js +0 -6
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +0 -1
- package/dist/core/default-component/SessionLost.component.js +0 -8
- package/dist/core/default-component/SessionLost.component.js.map +0 -1
- package/dist/core/default-component/SilentCallback.component.js +0 -27
- package/dist/core/default-component/SilentCallback.component.js.map +0 -1
- package/dist/core/default-component/SilentLogin.component.js +0 -29
- package/dist/core/default-component/SilentLogin.component.js.map +0 -1
- package/dist/core/default-component/index.js +0 -20
- package/dist/core/default-component/index.js.map +0 -1
- package/dist/core/routes/OidcRoutes.js +0 -64
- package/dist/core/routes/OidcRoutes.js.map +0 -1
- package/dist/core/routes/withRouter.js +0 -31
- package/dist/core/routes/withRouter.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/service_worker/OidcServiceWorker.d.ts +0 -2
- package/dist/service_worker/OidcServiceWorker.d.ts.map +0 -1
- package/dist/service_worker/OidcServiceWorker.js +0 -2
- package/dist/service_worker/OidcServiceWorker.js.map +0 -1
- package/dist/service_worker/constants.d.ts +0 -18
- package/dist/service_worker/constants.d.ts.map +0 -1
- package/dist/service_worker/types.d.ts +0 -87
- package/dist/service_worker/types.d.ts.map +0 -1
- package/dist/service_worker/utils/codeVerifier.d.ts +0 -2
- package/dist/service_worker/utils/codeVerifier.d.ts.map +0 -1
- package/dist/service_worker/utils/domains.d.ts +0 -7
- package/dist/service_worker/utils/domains.d.ts.map +0 -1
- package/dist/service_worker/utils/index.d.ts +0 -6
- package/dist/service_worker/utils/index.d.ts.map +0 -1
- package/dist/service_worker/utils/serializeHeaders.d.ts +0 -3
- package/dist/service_worker/utils/serializeHeaders.d.ts.map +0 -1
- package/dist/service_worker/utils/sleep.d.ts +0 -3
- package/dist/service_worker/utils/sleep.d.ts.map +0 -1
- package/dist/service_worker/utils/strings.d.ts +0 -8
- package/dist/service_worker/utils/strings.d.ts.map +0 -1
- package/dist/service_worker/utils/tokens.d.ts +0 -22
- package/dist/service_worker/utils/tokens.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vanilla/cache.d.ts +0 -3
- package/dist/vanilla/cache.d.ts.map +0 -1
- package/dist/vanilla/cache.js +0 -30
- package/dist/vanilla/cache.js.map +0 -1
- package/dist/vanilla/checkSession.d.ts +0 -4
- package/dist/vanilla/checkSession.d.ts.map +0 -1
- package/dist/vanilla/checkSession.js +0 -73
- package/dist/vanilla/checkSession.js.map +0 -1
- package/dist/vanilla/checkSessionIFrame.d.ts +0 -17
- package/dist/vanilla/checkSessionIFrame.d.ts.map +0 -1
- package/dist/vanilla/checkSessionIFrame.js +0 -73
- package/dist/vanilla/checkSessionIFrame.js.map +0 -1
- package/dist/vanilla/crypto.d.ts +0 -4
- package/dist/vanilla/crypto.d.ts.map +0 -1
- package/dist/vanilla/crypto.js +0 -85
- package/dist/vanilla/crypto.js.map +0 -1
- package/dist/vanilla/events.d.ts +0 -29
- package/dist/vanilla/events.d.ts.map +0 -1
- package/dist/vanilla/events.js +0 -32
- package/dist/vanilla/events.js.map +0 -1
- package/dist/vanilla/index.d.ts +0 -3
- package/dist/vanilla/index.d.ts.map +0 -1
- package/dist/vanilla/index.js +0 -6
- package/dist/vanilla/index.js.map +0 -1
- package/dist/vanilla/initSession.d.ts +0 -22
- package/dist/vanilla/initSession.d.ts.map +0 -1
- package/dist/vanilla/initSession.js +0 -90
- package/dist/vanilla/initSession.js.map +0 -1
- package/dist/vanilla/initWorker.d.ts +0 -30
- package/dist/vanilla/initWorker.d.ts.map +0 -1
- package/dist/vanilla/initWorker.js +0 -317
- package/dist/vanilla/initWorker.js.map +0 -1
- package/dist/vanilla/login.d.ts +0 -8
- package/dist/vanilla/login.d.ts.map +0 -1
- package/dist/vanilla/login.js +0 -175
- package/dist/vanilla/login.js.map +0 -1
- package/dist/vanilla/logout.d.ts +0 -8
- package/dist/vanilla/logout.d.ts.map +0 -1
- package/dist/vanilla/logout.js +0 -118
- package/dist/vanilla/logout.js.map +0 -1
- package/dist/vanilla/oidc.d.ts +0 -101
- package/dist/vanilla/oidc.d.ts.map +0 -1
- package/dist/vanilla/oidc.js +0 -612
- package/dist/vanilla/oidc.js.map +0 -1
- package/dist/vanilla/parseTokens.d.ts +0 -37
- package/dist/vanilla/parseTokens.d.ts.map +0 -1
- package/dist/vanilla/parseTokens.js +0 -167
- package/dist/vanilla/parseTokens.js.map +0 -1
- package/dist/vanilla/renewTokens.d.ts +0 -4
- package/dist/vanilla/renewTokens.d.ts.map +0 -1
- package/dist/vanilla/renewTokens.js +0 -51
- package/dist/vanilla/renewTokens.js.map +0 -1
- package/dist/vanilla/requests.d.ts +0 -33
- package/dist/vanilla/requests.d.ts.map +0 -1
- package/dist/vanilla/requests.js +0 -174
- package/dist/vanilla/requests.js.map +0 -1
- package/dist/vanilla/route-utils.d.ts +0 -13
- package/dist/vanilla/route-utils.d.ts.map +0 -1
- package/dist/vanilla/route-utils.js +0 -71
- package/dist/vanilla/route-utils.js.map +0 -1
- package/dist/vanilla/silentLogin.d.ts +0 -10
- package/dist/vanilla/silentLogin.d.ts.map +0 -1
- package/dist/vanilla/silentLogin.js +0 -144
- package/dist/vanilla/silentLogin.js.map +0 -1
- package/dist/vanilla/timer.d.ts +0 -8
- package/dist/vanilla/timer.d.ts.map +0 -1
- package/dist/vanilla/timer.js +0 -143
- package/dist/vanilla/timer.js.map +0 -1
- package/dist/vanilla/types.d.ts +0 -38
- package/dist/vanilla/types.d.ts.map +0 -1
- package/dist/vanilla/types.js +0 -3
- package/dist/vanilla/types.js.map +0 -1
- package/dist/vanilla/user.d.ts +0 -2
- package/dist/vanilla/user.d.ts.map +0 -1
- package/dist/vanilla/user.js +0 -48
- package/dist/vanilla/user.js.map +0 -1
- package/dist/vanilla/vanillaOidc.d.ts +0 -85
- package/dist/vanilla/vanillaOidc.d.ts.map +0 -1
- package/dist/vanilla/vanillaOidc.js +0 -71
- package/dist/vanilla/vanillaOidc.js.map +0 -1
- package/service_worker/.eslintrc.cjs +0 -18
- package/service_worker/OidcServiceWorker.ts +0 -424
- package/service_worker/constants.ts +0 -32
- package/service_worker/dist/OidcServiceWorker.d.ts +0 -2
- package/service_worker/dist/OidcServiceWorker.d.ts.map +0 -1
- package/service_worker/dist/OidcServiceWorker.js +0 -2
- package/service_worker/dist/OidcServiceWorker.js.map +0 -1
- package/service_worker/dist/constants.d.ts +0 -18
- package/service_worker/dist/constants.d.ts.map +0 -1
- package/service_worker/dist/types.d.ts +0 -87
- package/service_worker/dist/types.d.ts.map +0 -1
- package/service_worker/dist/utils/codeVerifier.d.ts +0 -2
- package/service_worker/dist/utils/codeVerifier.d.ts.map +0 -1
- package/service_worker/dist/utils/domains.d.ts +0 -7
- package/service_worker/dist/utils/domains.d.ts.map +0 -1
- package/service_worker/dist/utils/index.d.ts +0 -6
- package/service_worker/dist/utils/index.d.ts.map +0 -1
- package/service_worker/dist/utils/serializeHeaders.d.ts +0 -3
- package/service_worker/dist/utils/serializeHeaders.d.ts.map +0 -1
- package/service_worker/dist/utils/sleep.d.ts +0 -3
- package/service_worker/dist/utils/sleep.d.ts.map +0 -1
- package/service_worker/dist/utils/strings.d.ts +0 -8
- package/service_worker/dist/utils/strings.d.ts.map +0 -1
- package/service_worker/dist/utils/tokens.d.ts +0 -22
- package/service_worker/dist/utils/tokens.d.ts.map +0 -1
- package/service_worker/tsconfig.json +0 -26
- package/service_worker/types.ts +0 -103
- package/service_worker/utils/__tests__/codeVerifier.spec.ts +0 -14
- package/service_worker/utils/__tests__/domains.spec.ts +0 -90
- package/service_worker/utils/__tests__/serializeHeaders.spec.ts +0 -11
- package/service_worker/utils/__tests__/strings.spec.ts +0 -9
- package/service_worker/utils/__tests__/testHelper.ts +0 -352
- package/service_worker/utils/__tests__/tokens.spec.ts +0 -92
- package/service_worker/utils/codeVerifier.ts +0 -6
- package/service_worker/utils/domains.ts +0 -105
- package/service_worker/utils/index.ts +0 -5
- package/service_worker/utils/serializeHeaders.ts +0 -12
- package/service_worker/utils/sleep.ts +0 -2
- package/service_worker/utils/strings.ts +0 -9
- package/service_worker/utils/tokens.ts +0 -206
- package/src/oidc/vanilla/cache.ts +0 -27
- package/src/oidc/vanilla/checkSession.ts +0 -60
- package/src/oidc/vanilla/checkSessionIFrame.ts +0 -83
- package/src/oidc/vanilla/crypto.ts +0 -61
- package/src/oidc/vanilla/events.ts +0 -29
- package/src/oidc/vanilla/index.ts +0 -2
- package/src/oidc/vanilla/iniWorker.spec.ts +0 -21
- package/src/oidc/vanilla/initSession.ts +0 -90
- package/src/oidc/vanilla/initWorker.ts +0 -321
- package/src/oidc/vanilla/login.ts +0 -174
- package/src/oidc/vanilla/logout.spec.ts +0 -66
- package/src/oidc/vanilla/logout.spec.tsx +0 -64
- package/src/oidc/vanilla/logout.ts +0 -101
- package/src/oidc/vanilla/oidc.ts +0 -614
- package/src/oidc/vanilla/parseTokens.spec.ts +0 -49
- package/src/oidc/vanilla/parseTokens.ts +0 -194
- package/src/oidc/vanilla/renewTokens.ts +0 -37
- package/src/oidc/vanilla/requests.spec.ts +0 -9
- package/src/oidc/vanilla/requests.ts +0 -169
- package/src/oidc/vanilla/route-utils.spec.ts +0 -23
- package/src/oidc/vanilla/route-utils.ts +0 -79
- package/src/oidc/vanilla/silentLogin.ts +0 -144
- package/src/oidc/vanilla/timer.ts +0 -163
- package/src/oidc/vanilla/types.ts +0 -42
- package/src/oidc/vanilla/user.ts +0 -40
- package/src/oidc/vanilla/vanillaOidc.ts +0 -109
- package/src/override/AuthenticateError.component.tsx +0 -15
- package/src/override/Authenticating.component.tsx +0 -15
- package/src/override/Callback.component.tsx +0 -14
- package/src/override/Loading.component.tsx +0 -11
- package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
- package/src/override/SessionLost.component.tsx +0 -22
- package/src/override/style.ts +0 -12
- /package/src/{oidc/core → core}/default-component/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -0
- /package/src/{oidc/core → core}/routes/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/withRouter.tsx +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import cpy from 'cpy';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Script to run after npm install
|
|
6
|
+
*
|
|
7
|
+
* Copy selected files to user's directory
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const initPath = process.env.INIT_CWD;
|
|
11
|
+
// console.log('currentdir:', process.cwd());
|
|
12
|
+
// console.log('userPath:', initPath);
|
|
13
|
+
|
|
14
|
+
function copyProgress(progress) {
|
|
15
|
+
console.log('✓ [react-oidc:copy] ', progress.destinationPath);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const srcDir = '../oidc-client-service-worker/dist/';
|
|
19
|
+
const destinationDir = path.join(initPath, 'public');
|
|
20
|
+
|
|
21
|
+
await cpy([path.join(srcDir,'OidcServiceWorker.js')], destinationDir, {
|
|
22
|
+
overwrite: true,
|
|
23
|
+
}).on('progress', copyProgress);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await cpy([path.join(srcDir,'OidcTrustedDomains.js')], destinationDir, {
|
|
27
|
+
overwrite: false,
|
|
28
|
+
}).on('progress', copyProgress);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (e.code === 'EEXIST') { //file exists
|
|
31
|
+
console.log(
|
|
32
|
+
`✗ [react-oidc:skip] OidcTrustedDomains.js not copied, already exists in ${destinationDir}`
|
|
33
|
+
);
|
|
34
|
+
} else throw e;
|
|
35
|
+
}
|
package/dist/FetchToken.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { Fetch } from './vanilla';
|
|
1
|
+
import { Fetch } from '@axa-fr/vanilla-oidc';
|
|
3
2
|
export interface ComponentWithOidcFetchProps {
|
|
4
3
|
fetch?: Fetch;
|
|
5
4
|
}
|
|
6
|
-
export declare const withOidcFetch: (fetch?: Fetch, configurationName?: string) => (WrappedComponent: any) => (props: ComponentWithOidcFetchProps) => JSX.Element;
|
|
5
|
+
export declare const withOidcFetch: (fetch?: Fetch, configurationName?: string) => (WrappedComponent: any) => (props: ComponentWithOidcFetchProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
6
|
export declare const useOidcFetch: (fetch?: Fetch, configurationName?: string) => {
|
|
8
7
|
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
9
8
|
};
|
package/dist/FetchToken.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/
|
|
1
|
+
{"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/src/FetchToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAe,MAAM,sBAAsB,CAAC;AAG1D,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAiCD,eAAO,MAAM,aAAa,WAAW,KAAK,oEAE7B,2BAA2B,4CAGvC,CAAC;AAEF,eAAO,MAAM,YAAY,WAAW,KAAK;mBAK7B,WAAW,GAAG,GAAG,SAAS,WAAW;CAQhD,CAAC"}
|
package/dist/OidcProvider.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { Fetch, OidcConfiguration, VanillaOidc } from '@axa-fr/vanilla-oidc';
|
|
1
2
|
import { ComponentType, FC, PropsWithChildren } from 'react';
|
|
2
3
|
import { CustomHistory } from './core/routes/withRouter.js';
|
|
3
|
-
|
|
4
|
-
import { VanillaOidc } from './vanilla/vanillaOidc.js';
|
|
5
|
-
export declare type oidcContext = {
|
|
4
|
+
export type oidcContext = {
|
|
6
5
|
(name?: string): VanillaOidc;
|
|
7
6
|
};
|
|
8
|
-
export
|
|
7
|
+
export type OidcProviderProps = {
|
|
9
8
|
callbackSuccessComponent?: ComponentType<any>;
|
|
10
9
|
sessionLostComponent?: ComponentType<any>;
|
|
11
10
|
authenticatingComponent?: ComponentType<any>;
|
|
@@ -22,7 +21,7 @@ export declare type OidcProviderProps = {
|
|
|
22
21
|
onEvent?: (configuration: string, name: string, data: any) => void;
|
|
23
22
|
getFetch?: () => Fetch;
|
|
24
23
|
};
|
|
25
|
-
export
|
|
24
|
+
export type OidcSessionProps = {
|
|
26
25
|
configurationName: string;
|
|
27
26
|
loadingComponent: PropsWithChildren<any>;
|
|
28
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/
|
|
1
|
+
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/src/OidcProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,iBAAiB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAMlF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACtB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAChC,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,wBAAwB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC9C,oBAAoB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,4BAA4B,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAClD,gBAAgB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,kCAAkC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC5C,CAAC;AA0CF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA8HjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/OidcSecure.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { StringMap } from '@axa-fr/vanilla-oidc';
|
|
1
2
|
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
|
-
export declare type OidcSecureProps = {
|
|
3
|
+
export type OidcSecureProps = {
|
|
4
4
|
callbackPath?: string;
|
|
5
5
|
extras?: StringMap;
|
|
6
6
|
configurationName?: string;
|
|
7
7
|
};
|
|
8
8
|
export declare const OidcSecure: FC<PropsWithChildren<OidcSecureProps>>;
|
|
9
|
-
export declare const withOidcSecure: (WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>, callbackPath?: any, extras?: any, configurationName?: string) => (props: any) => JSX.Element;
|
|
9
|
+
export declare const withOidcSecure: (WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>, callbackPath?: any, extras?: any, configurationName?: string) => (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
//# sourceMappingURL=OidcSecure.d.ts.map
|
package/dist/OidcSecure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcSecure.d.ts","sourceRoot":"","sources":["../src/
|
|
1
|
+
{"version":3,"file":"OidcSecure.d.ts","sourceRoot":"","sources":["../src/src/OidcSecure.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAa,MAAM,OAAO,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG;IAC1B,YAAY,CAAC,EAAC,MAAM,CAAC;IACrB,MAAM,CAAC,EAAC,SAAS,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAa7D,CAAC;AAEF,eAAO,MAAM,cAAc,qBACP,GAAG,kBAAkB,eAAe,CAAC,CAAC,0HAMzD,CAAC"}
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
const scriptFilename = "OidcTrustedDomains.js";
|
|
2
|
+
const acceptAnyDomainToken = "*";
|
|
3
|
+
const TOKEN = {
|
|
4
|
+
REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
5
|
+
ACCESS_TOKEN: "ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
6
|
+
NONCE_TOKEN: "NONCE_SECURED_BY_OIDC_SERVICE_WORKER",
|
|
7
|
+
CODE_VERIFIER: "CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER"
|
|
8
|
+
};
|
|
9
|
+
const TokenRenewMode = {
|
|
10
|
+
access_token_or_id_token_invalid: "access_token_or_id_token_invalid",
|
|
11
|
+
access_token_invalid: "access_token_invalid",
|
|
12
|
+
id_token_invalid: "id_token_invalid"
|
|
13
|
+
};
|
|
14
|
+
const openidWellknownUrlEndWith = "/.well-known/openid-configuration";
|
|
15
|
+
function checkDomain(domains, endpoint) {
|
|
16
|
+
if (!endpoint) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const domain = domains.find((domain2) => {
|
|
20
|
+
var _a;
|
|
21
|
+
let testable;
|
|
22
|
+
if (typeof domain2 === "string") {
|
|
23
|
+
testable = new RegExp(`^${domain2}`);
|
|
24
|
+
} else {
|
|
25
|
+
testable = domain2;
|
|
26
|
+
}
|
|
27
|
+
return (_a = testable.test) == null ? void 0 : _a.call(testable, endpoint);
|
|
28
|
+
});
|
|
29
|
+
if (!domain) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Domain " + endpoint + " is not trusted, please add domain in " + scriptFilename
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const getDomains = (trustedDomain, type) => {
|
|
36
|
+
if (Array.isArray(trustedDomain)) {
|
|
37
|
+
return trustedDomain;
|
|
38
|
+
}
|
|
39
|
+
return trustedDomain[`${type}Domains`] ?? trustedDomain.domains ?? [];
|
|
40
|
+
};
|
|
41
|
+
const getCurrentDatabaseDomain = (database2, url, trustedDomains2) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (url.endsWith(openidWellknownUrlEndWith)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
for (const [key, currentDatabase] of Object.entries(database2)) {
|
|
47
|
+
const oidcServerConfiguration = currentDatabase.oidcServerConfiguration;
|
|
48
|
+
if (!oidcServerConfiguration) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (oidcServerConfiguration.tokenEndpoint && url === oidcServerConfiguration.tokenEndpoint) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (oidcServerConfiguration.revocationEndpoint && url === oidcServerConfiguration.revocationEndpoint) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const trustedDomain = trustedDomains2 == null ? [] : trustedDomains2[key];
|
|
58
|
+
const domains = getDomains(trustedDomain, "accessToken");
|
|
59
|
+
const domainsToSendTokens = oidcServerConfiguration.userInfoEndpoint ? [oidcServerConfiguration.userInfoEndpoint, ...domains] : [...domains];
|
|
60
|
+
let hasToSendToken = false;
|
|
61
|
+
if (domainsToSendTokens.find((f) => f === acceptAnyDomainToken)) {
|
|
62
|
+
hasToSendToken = true;
|
|
63
|
+
} else {
|
|
64
|
+
for (let i = 0; i < domainsToSendTokens.length; i++) {
|
|
65
|
+
let domain = domainsToSendTokens[i];
|
|
66
|
+
if (typeof domain === "string") {
|
|
67
|
+
domain = new RegExp(`^${domain}`);
|
|
68
|
+
}
|
|
69
|
+
if ((_a = domain.test) == null ? void 0 : _a.call(domain, url)) {
|
|
70
|
+
hasToSendToken = true;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (hasToSendToken) {
|
|
76
|
+
if (!currentDatabase.tokens) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return currentDatabase;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
function serializeHeaders(headers) {
|
|
85
|
+
const headersObj = {};
|
|
86
|
+
for (const key of headers.keys()) {
|
|
87
|
+
if (headers.has(key)) {
|
|
88
|
+
headersObj[key] = headers.get(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return headersObj;
|
|
92
|
+
}
|
|
93
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
|
+
function countLetter(str, find) {
|
|
95
|
+
return str.split(find).length - 1;
|
|
96
|
+
}
|
|
97
|
+
function parseJwt(token) {
|
|
98
|
+
return JSON.parse(
|
|
99
|
+
b64DecodeUnicode(token.split(".")[1].replace("-", "+").replace("_", "/"))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function b64DecodeUnicode(str) {
|
|
103
|
+
return decodeURIComponent(
|
|
104
|
+
Array.prototype.map.call(
|
|
105
|
+
atob(str),
|
|
106
|
+
(c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)
|
|
107
|
+
).join("")
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
function computeTimeLeft(refreshTimeBeforeTokensExpirationInSecond, expiresAt) {
|
|
111
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
112
|
+
return Math.round(
|
|
113
|
+
expiresAt - refreshTimeBeforeTokensExpirationInSecond - currentTimeUnixSecond
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function isTokensValid(tokens) {
|
|
117
|
+
if (!tokens) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return computeTimeLeft(0, tokens.expiresAt) > 0;
|
|
121
|
+
}
|
|
122
|
+
const extractTokenPayload = (token) => {
|
|
123
|
+
try {
|
|
124
|
+
if (!token) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (countLetter(token, ".") === 2) {
|
|
128
|
+
return parseJwt(token);
|
|
129
|
+
} else {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.warn(e);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
const isTokensOidcValid = (tokens, nonce, oidcServerConfiguration) => {
|
|
138
|
+
if (tokens.idTokenPayload) {
|
|
139
|
+
const idTokenPayload = tokens.idTokenPayload;
|
|
140
|
+
if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {
|
|
141
|
+
return { isValid: false, reason: "Issuer does not match" };
|
|
142
|
+
}
|
|
143
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
144
|
+
if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
|
|
145
|
+
return { isValid: false, reason: "Token expired" };
|
|
146
|
+
}
|
|
147
|
+
const timeInSevenDays = 60 * 60 * 24 * 7;
|
|
148
|
+
if (idTokenPayload.iat && idTokenPayload.iat + timeInSevenDays < currentTimeUnixSecond) {
|
|
149
|
+
return { isValid: false, reason: "Token is used from too long time" };
|
|
150
|
+
}
|
|
151
|
+
if (nonce && idTokenPayload.nonce && idTokenPayload.nonce !== nonce) {
|
|
152
|
+
return { isValid: false, reason: "Nonce does not match" };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { isValid: true, reason: "" };
|
|
156
|
+
};
|
|
157
|
+
function _hideTokens(tokens, currentDatabaseElement, configurationName) {
|
|
158
|
+
if (!tokens.issued_at) {
|
|
159
|
+
const currentTimeUnixSecond = (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
160
|
+
tokens.issued_at = currentTimeUnixSecond;
|
|
161
|
+
}
|
|
162
|
+
const accessTokenPayload = extractTokenPayload(tokens.access_token);
|
|
163
|
+
const secureTokens = {
|
|
164
|
+
...tokens,
|
|
165
|
+
accessTokenPayload
|
|
166
|
+
};
|
|
167
|
+
if (currentDatabaseElement.hideAccessToken) {
|
|
168
|
+
secureTokens.access_token = TOKEN.ACCESS_TOKEN + "_" + configurationName;
|
|
169
|
+
}
|
|
170
|
+
tokens.accessTokenPayload = accessTokenPayload;
|
|
171
|
+
let _idTokenPayload = null;
|
|
172
|
+
if (tokens.id_token) {
|
|
173
|
+
_idTokenPayload = extractTokenPayload(tokens.id_token);
|
|
174
|
+
tokens.idTokenPayload = { ..._idTokenPayload };
|
|
175
|
+
if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {
|
|
176
|
+
const keyNonce = TOKEN.NONCE_TOKEN + "_" + currentDatabaseElement.configurationName;
|
|
177
|
+
_idTokenPayload.nonce = keyNonce;
|
|
178
|
+
}
|
|
179
|
+
secureTokens.idTokenPayload = _idTokenPayload;
|
|
180
|
+
}
|
|
181
|
+
if (tokens.refresh_token) {
|
|
182
|
+
secureTokens.refresh_token = TOKEN.REFRESH_TOKEN + "_" + configurationName;
|
|
183
|
+
}
|
|
184
|
+
const idTokenExpiresAt = _idTokenPayload && _idTokenPayload.exp ? _idTokenPayload.exp : Number.MAX_VALUE;
|
|
185
|
+
const accessTokenExpiresAt = accessTokenPayload && accessTokenPayload.exp ? accessTokenPayload.exp : tokens.issued_at + tokens.expires_in;
|
|
186
|
+
let expiresAt;
|
|
187
|
+
const tokenRenewMode = currentDatabaseElement.oidcConfiguration.token_renew_mode;
|
|
188
|
+
if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
|
|
189
|
+
expiresAt = accessTokenExpiresAt;
|
|
190
|
+
} else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
|
|
191
|
+
expiresAt = idTokenExpiresAt;
|
|
192
|
+
} else {
|
|
193
|
+
expiresAt = idTokenExpiresAt < accessTokenExpiresAt ? idTokenExpiresAt : accessTokenExpiresAt;
|
|
194
|
+
}
|
|
195
|
+
secureTokens.expiresAt = expiresAt;
|
|
196
|
+
tokens.expiresAt = expiresAt;
|
|
197
|
+
const nonce = currentDatabaseElement.nonce ? currentDatabaseElement.nonce.nonce : null;
|
|
198
|
+
const { isValid, reason } = isTokensOidcValid(
|
|
199
|
+
tokens,
|
|
200
|
+
nonce,
|
|
201
|
+
currentDatabaseElement.oidcServerConfiguration
|
|
202
|
+
);
|
|
203
|
+
if (!isValid) {
|
|
204
|
+
throw Error(`Tokens are not OpenID valid, reason: ${reason}`);
|
|
205
|
+
}
|
|
206
|
+
if (currentDatabaseElement.tokens != null && "refresh_token" in currentDatabaseElement.tokens && !("refresh_token" in tokens)) {
|
|
207
|
+
const refreshToken = currentDatabaseElement.tokens.refresh_token;
|
|
208
|
+
currentDatabaseElement.tokens = {
|
|
209
|
+
...tokens,
|
|
210
|
+
refresh_token: refreshToken
|
|
211
|
+
};
|
|
212
|
+
} else {
|
|
213
|
+
currentDatabaseElement.tokens = tokens;
|
|
214
|
+
}
|
|
215
|
+
currentDatabaseElement.status = "LOGGED_IN";
|
|
216
|
+
return secureTokens;
|
|
217
|
+
}
|
|
218
|
+
function hideTokens(currentDatabaseElement) {
|
|
219
|
+
const configurationName = currentDatabaseElement.configurationName;
|
|
220
|
+
return (response) => {
|
|
221
|
+
if (response.status !== 200) {
|
|
222
|
+
return response;
|
|
223
|
+
}
|
|
224
|
+
return response.json().then((tokens) => {
|
|
225
|
+
const secureTokens = _hideTokens(tokens, currentDatabaseElement, configurationName);
|
|
226
|
+
const body = JSON.stringify(secureTokens);
|
|
227
|
+
return new Response(body, response);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function replaceCodeVerifier(codeVerifier, newCodeVerifier) {
|
|
232
|
+
const regex = /code_verifier=[A-Za-z0-9_-]+/i;
|
|
233
|
+
return codeVerifier.replace(regex, `code_verifier=${newCodeVerifier}`);
|
|
234
|
+
}
|
|
235
|
+
const _self = self;
|
|
236
|
+
_self.importScripts(scriptFilename);
|
|
237
|
+
const id = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3).toString();
|
|
238
|
+
const keepAliveJsonFilename = "OidcKeepAliveServiceWorker.json";
|
|
239
|
+
const handleInstall = (event) => {
|
|
240
|
+
console.log("[OidcServiceWorker] service worker installed " + id);
|
|
241
|
+
event.waitUntil(_self.skipWaiting());
|
|
242
|
+
};
|
|
243
|
+
const handleActivate = (event) => {
|
|
244
|
+
console.log("[OidcServiceWorker] service worker activated " + id);
|
|
245
|
+
event.waitUntil(_self.clients.claim());
|
|
246
|
+
};
|
|
247
|
+
let currentLoginCallbackConfigurationName = null;
|
|
248
|
+
const database = {
|
|
249
|
+
default: {
|
|
250
|
+
configurationName: "default",
|
|
251
|
+
tokens: null,
|
|
252
|
+
status: null,
|
|
253
|
+
state: null,
|
|
254
|
+
codeVerifier: null,
|
|
255
|
+
nonce: null,
|
|
256
|
+
oidcServerConfiguration: null,
|
|
257
|
+
hideAccessToken: true
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const getCurrentDatabasesTokenEndpoint = (database2, url) => {
|
|
261
|
+
const databases = [];
|
|
262
|
+
for (const [, value] of Object.entries(database2)) {
|
|
263
|
+
if (value.oidcServerConfiguration != null && url.startsWith(value.oidcServerConfiguration.tokenEndpoint)) {
|
|
264
|
+
databases.push(value);
|
|
265
|
+
} else if (value.oidcServerConfiguration != null && value.oidcServerConfiguration.revocationEndpoint && url.startsWith(value.oidcServerConfiguration.revocationEndpoint)) {
|
|
266
|
+
databases.push(value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return databases;
|
|
270
|
+
};
|
|
271
|
+
const keepAliveAsync = async (event) => {
|
|
272
|
+
const originalRequest = event.request;
|
|
273
|
+
const isFromVanilla = originalRequest.headers.has("oidc-vanilla");
|
|
274
|
+
const init = { status: 200, statusText: "oidc-service-worker" };
|
|
275
|
+
const response = new Response("{}", init);
|
|
276
|
+
if (!isFromVanilla) {
|
|
277
|
+
const originalRequestUrl = new URL(originalRequest.url);
|
|
278
|
+
const minSleepSeconds = Number(originalRequestUrl.searchParams.get("minSleepSeconds")) || 240;
|
|
279
|
+
for (let i = 0; i < minSleepSeconds; i++) {
|
|
280
|
+
await sleep(1e3 + Math.floor(Math.random() * 1e3));
|
|
281
|
+
const cache = await caches.open("oidc_dummy_cache");
|
|
282
|
+
await cache.put(event.request, response.clone());
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return response;
|
|
286
|
+
};
|
|
287
|
+
const handleFetch = async (event) => {
|
|
288
|
+
const originalRequest = event.request;
|
|
289
|
+
const url = originalRequest.url;
|
|
290
|
+
if (originalRequest.url.includes(keepAliveJsonFilename)) {
|
|
291
|
+
event.respondWith(keepAliveAsync(event));
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const currentDatabaseForRequestAccessToken = getCurrentDatabaseDomain(
|
|
295
|
+
database,
|
|
296
|
+
originalRequest.url,
|
|
297
|
+
trustedDomains
|
|
298
|
+
);
|
|
299
|
+
if (currentDatabaseForRequestAccessToken && currentDatabaseForRequestAccessToken.tokens && currentDatabaseForRequestAccessToken.tokens.access_token) {
|
|
300
|
+
while (currentDatabaseForRequestAccessToken.tokens && !isTokensValid(currentDatabaseForRequestAccessToken.tokens)) {
|
|
301
|
+
await sleep(200);
|
|
302
|
+
}
|
|
303
|
+
const newRequest = originalRequest.mode === "navigate" ? new Request(originalRequest, {
|
|
304
|
+
headers: {
|
|
305
|
+
...serializeHeaders(originalRequest.headers),
|
|
306
|
+
authorization: "Bearer " + currentDatabaseForRequestAccessToken.tokens.access_token
|
|
307
|
+
}
|
|
308
|
+
}) : new Request(originalRequest, {
|
|
309
|
+
headers: {
|
|
310
|
+
...serializeHeaders(originalRequest.headers),
|
|
311
|
+
authorization: "Bearer " + currentDatabaseForRequestAccessToken.tokens.access_token
|
|
312
|
+
},
|
|
313
|
+
mode: currentDatabaseForRequestAccessToken.oidcConfiguration.service_worker_convert_all_requests_to_cors ? "cors" : originalRequest.mode
|
|
314
|
+
});
|
|
315
|
+
event.waitUntil(event.respondWith(fetch(newRequest)));
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (event.request.method !== "POST") {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
let currentDatabase = null;
|
|
322
|
+
const currentDatabases = getCurrentDatabasesTokenEndpoint(
|
|
323
|
+
database,
|
|
324
|
+
originalRequest.url
|
|
325
|
+
);
|
|
326
|
+
const numberDatabase = currentDatabases.length;
|
|
327
|
+
if (numberDatabase > 0) {
|
|
328
|
+
const maPromesse = new Promise((resolve, reject) => {
|
|
329
|
+
const clonedRequest = originalRequest.clone();
|
|
330
|
+
const response = clonedRequest.text().then((actualBody) => {
|
|
331
|
+
if (actualBody.includes(TOKEN.REFRESH_TOKEN) || actualBody.includes(TOKEN.ACCESS_TOKEN)) {
|
|
332
|
+
let newBody = actualBody;
|
|
333
|
+
for (let i = 0; i < numberDatabase; i++) {
|
|
334
|
+
const currentDb = currentDatabases[i];
|
|
335
|
+
if (currentDb && currentDb.tokens != null) {
|
|
336
|
+
const keyRefreshToken = TOKEN.REFRESH_TOKEN + "_" + currentDb.configurationName;
|
|
337
|
+
if (actualBody.includes(keyRefreshToken)) {
|
|
338
|
+
newBody = newBody.replace(
|
|
339
|
+
keyRefreshToken,
|
|
340
|
+
encodeURIComponent(currentDb.tokens.refresh_token)
|
|
341
|
+
);
|
|
342
|
+
currentDatabase = currentDb;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
const keyAccessToken = TOKEN.ACCESS_TOKEN + "_" + currentDb.configurationName;
|
|
346
|
+
if (actualBody.includes(keyAccessToken)) {
|
|
347
|
+
newBody = newBody.replace(
|
|
348
|
+
keyAccessToken,
|
|
349
|
+
encodeURIComponent(currentDb.tokens.access_token)
|
|
350
|
+
);
|
|
351
|
+
currentDatabase = currentDb;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const fetchPromise = fetch(originalRequest, {
|
|
357
|
+
body: newBody,
|
|
358
|
+
method: clonedRequest.method,
|
|
359
|
+
headers: {
|
|
360
|
+
...serializeHeaders(originalRequest.headers)
|
|
361
|
+
},
|
|
362
|
+
mode: clonedRequest.mode,
|
|
363
|
+
cache: clonedRequest.cache,
|
|
364
|
+
redirect: clonedRequest.redirect,
|
|
365
|
+
referrer: clonedRequest.referrer,
|
|
366
|
+
credentials: clonedRequest.credentials,
|
|
367
|
+
integrity: clonedRequest.integrity
|
|
368
|
+
});
|
|
369
|
+
if (currentDatabase && currentDatabase.oidcServerConfiguration != null && currentDatabase.oidcServerConfiguration.revocationEndpoint && url.startsWith(
|
|
370
|
+
currentDatabase.oidcServerConfiguration.revocationEndpoint
|
|
371
|
+
)) {
|
|
372
|
+
return fetchPromise.then(async (response2) => {
|
|
373
|
+
const text = await response2.text();
|
|
374
|
+
return new Response(text, response2);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return fetchPromise.then(hideTokens(currentDatabase));
|
|
378
|
+
} else if (actualBody.includes("code_verifier=") && currentLoginCallbackConfigurationName) {
|
|
379
|
+
currentDatabase = database[currentLoginCallbackConfigurationName];
|
|
380
|
+
currentLoginCallbackConfigurationName = null;
|
|
381
|
+
let newBody = actualBody;
|
|
382
|
+
if (currentDatabase && currentDatabase.codeVerifier != null) {
|
|
383
|
+
newBody = replaceCodeVerifier(newBody, currentDatabase.codeVerifier);
|
|
384
|
+
}
|
|
385
|
+
return fetch(originalRequest, {
|
|
386
|
+
body: newBody,
|
|
387
|
+
method: clonedRequest.method,
|
|
388
|
+
headers: {
|
|
389
|
+
...serializeHeaders(originalRequest.headers)
|
|
390
|
+
},
|
|
391
|
+
mode: clonedRequest.mode,
|
|
392
|
+
cache: clonedRequest.cache,
|
|
393
|
+
redirect: clonedRequest.redirect,
|
|
394
|
+
referrer: clonedRequest.referrer,
|
|
395
|
+
credentials: clonedRequest.credentials,
|
|
396
|
+
integrity: clonedRequest.integrity
|
|
397
|
+
}).then(hideTokens(currentDatabase));
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
});
|
|
401
|
+
response.then((r) => {
|
|
402
|
+
if (r !== void 0) {
|
|
403
|
+
resolve(r);
|
|
404
|
+
} else {
|
|
405
|
+
console.log("success undefined");
|
|
406
|
+
reject(new Error("Response is undefined inside a success"));
|
|
407
|
+
}
|
|
408
|
+
}).catch((err) => {
|
|
409
|
+
if (err !== void 0) {
|
|
410
|
+
reject(err);
|
|
411
|
+
} else {
|
|
412
|
+
console.log("error undefined");
|
|
413
|
+
reject(new Error("Response is undefined inside a error"));
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
event.waitUntil(event.respondWith(maPromesse));
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
const trustedDomainsShowAccessToken = {};
|
|
421
|
+
const handleMessage = (event) => {
|
|
422
|
+
const port = event.ports[0];
|
|
423
|
+
const data = event.data;
|
|
424
|
+
const configurationName = data.configurationName;
|
|
425
|
+
let currentDatabase = database[configurationName];
|
|
426
|
+
if (trustedDomains == null) {
|
|
427
|
+
trustedDomains = {};
|
|
428
|
+
}
|
|
429
|
+
if (!currentDatabase) {
|
|
430
|
+
if (trustedDomainsShowAccessToken[configurationName] === void 0) {
|
|
431
|
+
const trustedDomain = trustedDomains[configurationName];
|
|
432
|
+
trustedDomainsShowAccessToken[configurationName] = Array.isArray(trustedDomain) ? false : trustedDomain.showAccessToken;
|
|
433
|
+
}
|
|
434
|
+
database[configurationName] = {
|
|
435
|
+
tokens: null,
|
|
436
|
+
state: null,
|
|
437
|
+
codeVerifier: null,
|
|
438
|
+
oidcServerConfiguration: null,
|
|
439
|
+
oidcConfiguration: void 0,
|
|
440
|
+
nonce: null,
|
|
441
|
+
status: null,
|
|
442
|
+
configurationName,
|
|
443
|
+
hideAccessToken: !trustedDomainsShowAccessToken[configurationName]
|
|
444
|
+
};
|
|
445
|
+
currentDatabase = database[configurationName];
|
|
446
|
+
if (!trustedDomains[configurationName]) {
|
|
447
|
+
trustedDomains[configurationName] = [];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
switch (data.type) {
|
|
451
|
+
case "clear":
|
|
452
|
+
currentDatabase.tokens = null;
|
|
453
|
+
currentDatabase.state = null;
|
|
454
|
+
currentDatabase.codeVerifier = null;
|
|
455
|
+
currentDatabase.status = data.data.status;
|
|
456
|
+
port.postMessage({ configurationName });
|
|
457
|
+
return;
|
|
458
|
+
case "init": {
|
|
459
|
+
const oidcServerConfiguration = data.data.oidcServerConfiguration;
|
|
460
|
+
const trustedDomain = trustedDomains[configurationName];
|
|
461
|
+
const domains = getDomains(trustedDomain, "oidc");
|
|
462
|
+
if (!domains.find((f) => f === acceptAnyDomainToken)) {
|
|
463
|
+
[
|
|
464
|
+
oidcServerConfiguration.tokenEndpoint,
|
|
465
|
+
oidcServerConfiguration.revocationEndpoint,
|
|
466
|
+
oidcServerConfiguration.userInfoEndpoint,
|
|
467
|
+
oidcServerConfiguration.issuer
|
|
468
|
+
].forEach((url) => {
|
|
469
|
+
checkDomain(domains, url);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
currentDatabase.oidcServerConfiguration = oidcServerConfiguration;
|
|
473
|
+
currentDatabase.oidcConfiguration = data.data.oidcConfiguration;
|
|
474
|
+
const where = data.data.where;
|
|
475
|
+
if (where === "loginCallbackAsync" || where === "tryKeepExistingSessionAsync") {
|
|
476
|
+
currentLoginCallbackConfigurationName = configurationName;
|
|
477
|
+
} else {
|
|
478
|
+
currentLoginCallbackConfigurationName = null;
|
|
479
|
+
}
|
|
480
|
+
if (!currentDatabase.tokens) {
|
|
481
|
+
port.postMessage({
|
|
482
|
+
tokens: null,
|
|
483
|
+
status: currentDatabase.status,
|
|
484
|
+
configurationName
|
|
485
|
+
});
|
|
486
|
+
} else {
|
|
487
|
+
const tokens = {
|
|
488
|
+
...currentDatabase.tokens
|
|
489
|
+
};
|
|
490
|
+
if (currentDatabase.hideAccessToken) {
|
|
491
|
+
tokens.access_token = TOKEN.ACCESS_TOKEN + "_" + configurationName;
|
|
492
|
+
}
|
|
493
|
+
if (tokens.refresh_token) {
|
|
494
|
+
tokens.refresh_token = TOKEN.REFRESH_TOKEN + "_" + configurationName;
|
|
495
|
+
}
|
|
496
|
+
if (tokens.idTokenPayload && tokens.idTokenPayload.nonce && currentDatabase.nonce != null) {
|
|
497
|
+
tokens.idTokenPayload.nonce = TOKEN.NONCE_TOKEN + "_" + configurationName;
|
|
498
|
+
}
|
|
499
|
+
port.postMessage({
|
|
500
|
+
tokens,
|
|
501
|
+
status: currentDatabase.status,
|
|
502
|
+
configurationName
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
case "setState":
|
|
508
|
+
currentDatabase.state = data.data.state;
|
|
509
|
+
port.postMessage({ configurationName });
|
|
510
|
+
return;
|
|
511
|
+
case "getState": {
|
|
512
|
+
const state = currentDatabase.state;
|
|
513
|
+
port.postMessage({ configurationName, state });
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
case "setCodeVerifier":
|
|
517
|
+
currentDatabase.codeVerifier = data.data.codeVerifier;
|
|
518
|
+
port.postMessage({ configurationName });
|
|
519
|
+
return;
|
|
520
|
+
case "getCodeVerifier": {
|
|
521
|
+
port.postMessage({
|
|
522
|
+
configurationName,
|
|
523
|
+
codeVerifier: currentDatabase.codeVerifier != null ? TOKEN.CODE_VERIFIER + "_" + configurationName : null
|
|
524
|
+
});
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
case "setSessionState":
|
|
528
|
+
currentDatabase.sessionState = data.data.sessionState;
|
|
529
|
+
port.postMessage({ configurationName });
|
|
530
|
+
return;
|
|
531
|
+
case "getSessionState": {
|
|
532
|
+
const sessionState = currentDatabase.sessionState;
|
|
533
|
+
port.postMessage({ configurationName, sessionState });
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
case "setNonce": {
|
|
537
|
+
const nonce = data.data.nonce;
|
|
538
|
+
if (nonce) {
|
|
539
|
+
currentDatabase.nonce = nonce;
|
|
540
|
+
}
|
|
541
|
+
port.postMessage({ configurationName });
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
case "getNonce": {
|
|
545
|
+
const keyNonce = TOKEN.NONCE_TOKEN + "_" + configurationName;
|
|
546
|
+
const nonce = currentDatabase.nonce ? keyNonce : null;
|
|
547
|
+
port.postMessage({ configurationName, nonce });
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
default:
|
|
551
|
+
currentDatabase.items = { ...data.data };
|
|
552
|
+
port.postMessage({ configurationName });
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
_self.addEventListener("install", handleInstall);
|
|
556
|
+
_self.addEventListener("activate", handleActivate);
|
|
557
|
+
_self.addEventListener("fetch", handleFetch);
|
|
558
|
+
_self.addEventListener("message", handleMessage);
|
|
559
|
+
//# sourceMappingURL=OidcServiceWorker.js.map
|
|
@@ -17,11 +17,10 @@ const trustedDomains = {
|
|
|
17
17
|
// Service worker will continue to give access token to the JavaScript client
|
|
18
18
|
// Ideal to hide refresh token from client JavaScript, but to retrieve access_token for some
|
|
19
19
|
// scenarios which require it. For example, to send it via websocket connection.
|
|
20
|
-
trustedDomains.config_show_access_token = { domains
|
|
21
|
-
|
|
20
|
+
trustedDomains.config_show_access_token = { domains: ['https://demo.duendesoftware.com'], showAccessToken: true };
|
|
22
21
|
|
|
23
22
|
// This example defines domains used by OIDC server separately from domains to which access tokens will be injected.
|
|
24
23
|
trustedDomains.config_separate_oidc_access_token_domains = {
|
|
25
|
-
oidcDomains: [
|
|
26
|
-
accessTokenDomains: [
|
|
27
|
-
};
|
|
24
|
+
oidcDomains: ['https://demo.duendesoftware.com'],
|
|
25
|
+
accessTokenDomains: ['https://myapi'],
|
|
26
|
+
};
|