@axa-fr/react-oidc 7.22.18 → 7.22.19
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/README.md +87 -114
- package/bin/copy-service-worker-files.mjs +24 -17
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/OidcProvider.d.ts +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcTrustedDomains.js +13 -10
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.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/SilentCallback.component.d.ts +5 -2
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- 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 +165 -72
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/FetchToken.tsx +36 -13
- package/src/OidcProvider.tsx +222 -176
- package/src/OidcSecure.tsx +34 -23
- package/src/ReactOidc.tsx +181 -142
- package/src/User.ts +60 -50
- package/src/core/default-component/Authenticating.component.tsx +1 -1
- package/src/core/default-component/Callback.component.tsx +18 -11
- package/src/core/default-component/Loading.component.tsx +1 -5
- package/src/core/default-component/ServiceWorkerNotSupported.component.tsx +5 -2
- package/src/core/default-component/SessionLost.component.tsx +1 -1
- package/src/core/default-component/SilentCallback.component.tsx +17 -11
- package/src/core/default-component/SilentLogin.component.tsx +18 -18
- package/src/core/routes/OidcRoutes.spec.tsx +2 -2
- package/src/core/routes/OidcRoutes.tsx +12 -5
- package/src/core/routes/withRouter.spec.tsx +5 -6
- package/src/core/routes/withRouter.tsx +21 -19
- package/src/index.ts +8 -3
|
@@ -2,30 +2,30 @@ import { getParseQueryStringFromLocation, OidcClient } from '@axa-fr/oidc-client
|
|
|
2
2
|
import { ComponentType, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
const SilentLogin: ComponentType<any> = ({ configurationName }) => {
|
|
5
|
-
|
|
5
|
+
const queryParams = getParseQueryStringFromLocation(window.location.href);
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const getOidc = OidcClient.get;
|
|
8
|
+
const oidc = getOidc(configurationName);
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
let extras = null;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if (extras === null) {
|
|
17
|
-
extras = {};
|
|
18
|
-
}
|
|
19
|
-
extras[key] = value;
|
|
12
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
13
|
+
if (key === 'state' || key === 'scope') {
|
|
14
|
+
continue;
|
|
20
15
|
}
|
|
16
|
+
if (extras === null) {
|
|
17
|
+
extras = {};
|
|
18
|
+
}
|
|
19
|
+
extras[key] = value;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!oidc.tokens) {
|
|
24
|
+
oidc.loginAsync(null, extras, true, queryParams.scope);
|
|
25
|
+
}
|
|
26
|
+
}, []);
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
return <></>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export default SilentLogin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { render } from
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { describe, expect,it } from 'vitest';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import OidcRoutes from './OidcRoutes';
|
|
6
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {getPath, ILOidcLocation} from '@axa-fr/oidc-client';
|
|
1
|
+
import { getPath, ILOidcLocation } from '@axa-fr/oidc-client';
|
|
2
2
|
import React, { ComponentType, FC, PropsWithChildren, useEffect, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import CallbackComponent from '../default-component/Callback.component.js';
|
|
@@ -24,9 +24,9 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
|
|
|
24
24
|
redirect_uri,
|
|
25
25
|
silent_redirect_uri,
|
|
26
26
|
silent_login_uri,
|
|
27
|
-
children,
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
children,
|
|
28
|
+
configurationName,
|
|
29
|
+
withCustomHistory = null,
|
|
30
30
|
}) => {
|
|
31
31
|
// This exist because in next.js window outside useEffect is null
|
|
32
32
|
const pathname = window ? getPath(window.location.href) : '';
|
|
@@ -56,7 +56,14 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
|
|
|
56
56
|
|
|
57
57
|
switch (path) {
|
|
58
58
|
case callbackPath:
|
|
59
|
-
return
|
|
59
|
+
return (
|
|
60
|
+
<CallbackComponent
|
|
61
|
+
callBackError={callbackErrorComponent}
|
|
62
|
+
callBackSuccess={callbackSuccessComponent}
|
|
63
|
+
configurationName={configurationName}
|
|
64
|
+
withCustomHistory={withCustomHistory}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
60
67
|
default:
|
|
61
68
|
return <>{children}</>;
|
|
62
69
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { beforeEach,describe, expect, it, vi } from 'vitest';
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { CreateEvent, WindowInternal } from './withRouter';
|
|
4
4
|
|
|
5
5
|
describe('WithRouter test Suite', () => {
|
|
6
6
|
const paramsMock = { bubbles: false, cancelable: false, detail: 'detail' };
|
|
7
|
-
beforeEach(() => {
|
|
7
|
+
beforeEach(() => {});
|
|
8
8
|
it('should CreateEvent return correct Event if not on IE', () => {
|
|
9
9
|
const windowMock = {
|
|
10
10
|
CustomEvent: vi.fn().mockImplementation((event, params) => {
|
|
@@ -12,7 +12,7 @@ describe('WithRouter test Suite', () => {
|
|
|
12
12
|
}),
|
|
13
13
|
};
|
|
14
14
|
const documentMock = {} as Document;
|
|
15
|
-
const res = CreateEvent(
|
|
15
|
+
const res = CreateEvent(windowMock as unknown as WindowInternal, documentMock)(
|
|
16
16
|
'event test',
|
|
17
17
|
paramsMock,
|
|
18
18
|
);
|
|
@@ -34,8 +34,8 @@ describe('WithRouter test Suite', () => {
|
|
|
34
34
|
const documentMock = {
|
|
35
35
|
createEvent: vi.fn(() => evtMock),
|
|
36
36
|
};
|
|
37
|
-
const typedDocumentMock =
|
|
38
|
-
const res = CreateEvent(
|
|
37
|
+
const typedDocumentMock = documentMock as unknown as Document;
|
|
38
|
+
const res = CreateEvent(windowMock as unknown as WindowInternal, typedDocumentMock)(
|
|
39
39
|
'event test',
|
|
40
40
|
paramsMock,
|
|
41
41
|
);
|
|
@@ -43,5 +43,4 @@ describe('WithRouter test Suite', () => {
|
|
|
43
43
|
expect(documentMock.createEvent).toHaveBeenCalledWith('CustomEvent');
|
|
44
44
|
expect(evtMock.initCustomEvent).toHaveBeenCalledWith('event test', false, false, 'detail');
|
|
45
45
|
});
|
|
46
|
-
|
|
47
46
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
const generateKey = () =>
|
|
2
|
-
Math.random()
|
|
3
|
-
.toString(36)
|
|
4
|
-
.substr(2, 6);
|
|
1
|
+
const generateKey = () => Math.random().toString(36).slice(2, 8);
|
|
5
2
|
|
|
6
3
|
// Exported only for test
|
|
7
4
|
export type WindowInternal = Window & {
|
|
@@ -20,19 +17,23 @@ type InitCustomEventParams<T = any> = {
|
|
|
20
17
|
};
|
|
21
18
|
|
|
22
19
|
// IE Polyfill for CustomEvent
|
|
23
|
-
export const CreateEvent =
|
|
24
|
-
|
|
25
|
-
params: InitCustomEventParams
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
export const CreateEvent =
|
|
21
|
+
(windowInternal: WindowInternal, documentInternal: Document) =>
|
|
22
|
+
(event: string, params: InitCustomEventParams): CustomEvent => {
|
|
23
|
+
if (typeof windowInternal.CustomEvent === 'function') {
|
|
24
|
+
return new windowInternal.CustomEvent(event, params);
|
|
25
|
+
}
|
|
26
|
+
const paramsToFunction = params || { bubbles: false, cancelable: false, detail: undefined };
|
|
27
|
+
const evt: CustomEvent = documentInternal.createEvent('CustomEvent');
|
|
28
|
+
evt.initCustomEvent(
|
|
29
|
+
event,
|
|
30
|
+
paramsToFunction.bubbles,
|
|
31
|
+
paramsToFunction.cancelable,
|
|
32
|
+
paramsToFunction.detail,
|
|
33
|
+
);
|
|
34
|
+
(evt as CustomEvent & IPrototype).prototype = windowInternal.Event.prototype;
|
|
35
|
+
return evt;
|
|
36
|
+
};
|
|
36
37
|
|
|
37
38
|
type WindowHistoryState = typeof window.history.state;
|
|
38
39
|
|
|
@@ -42,7 +43,7 @@ export interface ReactOidcHistory {
|
|
|
42
43
|
|
|
43
44
|
export type CustomHistory = {
|
|
44
45
|
replaceState(url?: string | null, stateHistory?: WindowHistoryState): void;
|
|
45
|
-
}
|
|
46
|
+
};
|
|
46
47
|
|
|
47
48
|
const getHistory = (
|
|
48
49
|
windowInternal: WindowInternal,
|
|
@@ -59,4 +60,5 @@ const getHistory = (
|
|
|
59
60
|
};
|
|
60
61
|
};
|
|
61
62
|
|
|
62
|
-
export const getCustomHistory = () =>
|
|
63
|
+
export const getCustomHistory = () =>
|
|
64
|
+
getHistory(window, CreateEvent(window, document), generateKey);
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,14 @@ export { OidcUserStatus, useOidcUser } from './User.js';
|
|
|
6
6
|
export type {
|
|
7
7
|
AuthorityConfiguration,
|
|
8
8
|
Fetch,
|
|
9
|
+
ILOidcLocation,
|
|
9
10
|
OidcConfiguration,
|
|
10
11
|
StringMap,
|
|
11
|
-
ILOidcLocation
|
|
12
12
|
} from '@axa-fr/oidc-client';
|
|
13
|
-
export {
|
|
14
|
-
export
|
|
13
|
+
export type { OidcUserInfo } from '@axa-fr/oidc-client';
|
|
14
|
+
export {
|
|
15
|
+
OidcClient,
|
|
16
|
+
OidcLocation,
|
|
17
|
+
TokenAutomaticRenewMode,
|
|
18
|
+
TokenRenewMode,
|
|
19
|
+
} from '@axa-fr/oidc-client';
|