@axa-fr/react-oidc 7.27.12 → 7.27.14
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/dist/OidcProvider.d.ts +2 -0
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/core/default-component/Callback.component.d.ts +1 -0
- package/dist/core/default-component/Callback.component.d.ts.map +1 -1
- package/dist/core/default-component/LoadingTimeout.component.d.ts +4 -0
- package/dist/core/default-component/LoadingTimeout.component.d.ts.map +1 -0
- package/dist/core/default-component/index.d.ts +1 -0
- package/dist/core/default-component/index.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts +1 -0
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -93
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/OidcProvider.spec.tsx +279 -0
- package/src/OidcProvider.tsx +37 -0
- package/src/core/default-component/Callback.component.spec.tsx +248 -0
- package/src/core/default-component/Callback.component.tsx +62 -3
- package/src/core/default-component/LoadingTimeout.component.tsx +14 -0
- package/src/core/default-component/index.ts +1 -0
- package/src/core/routes/OidcRoutes.tsx +3 -0
- package/src/index.ts +1 -0
package/dist/OidcProvider.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type OidcProviderProps = {
|
|
|
10
10
|
authenticatingComponent?: ComponentType<any>;
|
|
11
11
|
authenticatingErrorComponent?: ComponentType<any>;
|
|
12
12
|
loadingComponent?: ComponentType<any>;
|
|
13
|
+
loadingTimeoutComponent?: ComponentType<any>;
|
|
13
14
|
serviceWorkerNotSupportedComponent?: ComponentType<any>;
|
|
14
15
|
configurationName?: string;
|
|
15
16
|
configuration?: OidcConfiguration;
|
|
@@ -18,6 +19,7 @@ export type OidcProviderProps = {
|
|
|
18
19
|
onLogoutFromAnotherTab?: () => void;
|
|
19
20
|
onLogoutFromSameTab?: () => void;
|
|
20
21
|
withCustomHistory?: () => CustomHistory;
|
|
22
|
+
navigateAfterCallback?: (callbackPath: string) => Promise<void>;
|
|
21
23
|
onEvent?: (configuration: string, name: string, data: any) => void;
|
|
22
24
|
getFetch?: () => Fetch;
|
|
23
25
|
location?: ILOidcLocation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/OidcProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,cAAc,EACd,UAAU,EACV,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"OidcProvider.d.ts","sourceRoot":"","sources":["../src/OidcProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAEL,cAAc,EACd,UAAU,EACV,iBAAiB,EAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAuB,MAAM,OAAO,CAAC;AAYlF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CAC7B,CAAC;AAIF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,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,uBAAuB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C,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,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,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;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAuCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA+MjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
export declare const CallBackSuccess: ComponentType<any>;
|
|
3
|
+
export declare const verifyNavigationCommitted: (targetPath: string, windowInternal?: Window) => boolean;
|
|
3
4
|
declare const CallbackManager: ComponentType<any>;
|
|
4
5
|
export default CallbackManager;
|
|
5
6
|
//# sourceMappingURL=Callback.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Callback.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/Callback.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,OAAO,CAAC;AAK3D,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,GAAG,CAO9C,CAAC;AAEF,QAAA,MAAM,eAAe,EAAE,aAAa,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"Callback.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/Callback.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,OAAO,CAAC;AAK3D,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,GAAG,CAO9C,CAAC;AAIF,eAAO,MAAM,yBAAyB,GACpC,YAAY,MAAM,EAClB,iBAAgB,MAAe,KAC9B,OAGF,CAAC;AAEF,QAAA,MAAM,eAAe,EAAE,aAAa,CAAC,GAAG,CAqFvC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingTimeout.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/LoadingTimeout.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,QAAA,MAAM,cAAc,EAAE,aAAa,CAAC,GAAG,CAStC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -2,6 +2,7 @@ export { default as AuthenticateError } from './AuthenticateError.component.js';
|
|
|
2
2
|
export { default as Authenticating } from './Authenticating.component.js';
|
|
3
3
|
export { default as Callback, CallBackSuccess } from './Callback.component.js';
|
|
4
4
|
export { default as Loading } from './Loading.component.js';
|
|
5
|
+
export { default as LoadingTimeout } from './LoadingTimeout.component.js';
|
|
5
6
|
export { default as ServiceWorkerNotSupported } from './ServiceWorkerNotSupported.component.js';
|
|
6
7
|
export { default as SessionLost } from './SessionLost.component.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -10,6 +10,7 @@ type OidcRoutesProps = {
|
|
|
10
10
|
silent_redirect_uri?: string;
|
|
11
11
|
silent_login_uri?: string;
|
|
12
12
|
withCustomHistory?: () => CustomHistory;
|
|
13
|
+
navigateAfterCallback?: (callbackPath: string) => Promise<void>;
|
|
13
14
|
location: ILOidcLocation;
|
|
14
15
|
};
|
|
15
16
|
declare const _default: React.NamedExoticComponent<React.PropsWithChildren<OidcRoutesProps>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcRoutes.d.ts","sourceRoot":"","sources":["../../../src/core/routes/OidcRoutes.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,EAAE,aAAa,EAA8C,MAAM,OAAO,CAAC;AAKzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,KAAK,eAAe,GAAG;IACrB,wBAAwB,CAAC,EAAE,aAAa,CAAC;IACzC,sBAAsB,CAAC,EAAE,aAAa,CAAC;IACvC,uBAAuB,CAAC,EAAE,aAAa,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;;
|
|
1
|
+
{"version":3,"file":"OidcRoutes.d.ts","sourceRoot":"","sources":["../../../src/core/routes/OidcRoutes.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAW,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,EAAE,aAAa,EAA8C,MAAM,OAAO,CAAC;AAKzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,KAAK,eAAe,GAAG;IACrB,wBAAwB,CAAC,EAAE,aAAa,CAAC;IACzC,sBAAsB,CAAC,EAAE,aAAa,CAAC;IACvC,uBAAuB,CAAC,EAAE,aAAa,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;;AAuDF,wBAAsC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useOidcFetch, withOidcFetch } from './FetchToken.js';
|
|
2
|
+
export type { OidcProviderProps } from './OidcProvider.js';
|
|
2
3
|
export { OidcProvider } from './OidcProvider.js';
|
|
3
4
|
export { OidcSecure, withOidcSecure } from './OidcSecure.js';
|
|
4
5
|
export { useOidc, useOidcAccessToken, useOidcIdToken } from './ReactOidc.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -65,26 +65,61 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
65
65
|
children: "You will be redirected to your application."
|
|
66
66
|
})]
|
|
67
67
|
})
|
|
68
|
-
}), O = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i }) => {
|
|
69
|
-
let [
|
|
68
|
+
}), O = 200, k = (e, t = window) => t.location.pathname === e || e === "/", A = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
|
|
69
|
+
let [o, s] = p(!1);
|
|
70
70
|
return d(() => {
|
|
71
71
|
let e = !0;
|
|
72
72
|
return (async () => {
|
|
73
73
|
let n = t.get;
|
|
74
74
|
try {
|
|
75
|
-
let { callbackPath:
|
|
76
|
-
|
|
75
|
+
let o = n(r), { callbackPath: c } = await o.loginCallbackAsync(), l = c || "/";
|
|
76
|
+
if (a) try {
|
|
77
|
+
await a(l), o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
|
|
78
|
+
configurationName: r,
|
|
79
|
+
callbackPath: l
|
|
80
|
+
});
|
|
81
|
+
} catch (n) {
|
|
82
|
+
o.publishEvent(t.eventNames.loginCallbackAsync_navigation_error, {
|
|
83
|
+
configurationName: r,
|
|
84
|
+
callbackPath: l,
|
|
85
|
+
error: n
|
|
86
|
+
}), e && (console.warn(n), s(!0));
|
|
87
|
+
}
|
|
88
|
+
else (i ? i() : E()).replaceState(l), await new Promise((e) => {
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
e();
|
|
91
|
+
}, O);
|
|
92
|
+
}), e && (k(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
|
|
93
|
+
configurationName: r,
|
|
94
|
+
callbackPath: l
|
|
95
|
+
}) : (o.publishEvent(t.eventNames.loginCallbackAsync_navigation_error, {
|
|
96
|
+
configurationName: r,
|
|
97
|
+
callbackPath: l,
|
|
98
|
+
error: /* @__PURE__ */ Error(`Navigation did not commit: expected "${l}" but found "${window.location.pathname}"`)
|
|
99
|
+
}), s(!0)));
|
|
77
100
|
} catch (t) {
|
|
78
|
-
e && (console.warn(t),
|
|
101
|
+
e && (console.warn(t), s(!0));
|
|
79
102
|
}
|
|
80
103
|
})(), () => {
|
|
81
104
|
e = !1;
|
|
82
105
|
};
|
|
83
|
-
}, []), h(
|
|
84
|
-
},
|
|
106
|
+
}, []), h(o ? e || x : n || D, { configurationName: r });
|
|
107
|
+
}, j = () => /* @__PURE__ */ h("span", {
|
|
85
108
|
className: "oidc-loading",
|
|
86
109
|
children: "Loading"
|
|
87
|
-
}),
|
|
110
|
+
}), M = () => /* @__PURE__ */ h("div", {
|
|
111
|
+
className: "oidc-loading-timeout",
|
|
112
|
+
children: /* @__PURE__ */ g("div", {
|
|
113
|
+
className: "oidc-loading-timeout__container",
|
|
114
|
+
children: [/* @__PURE__ */ h("h1", {
|
|
115
|
+
className: "oidc-loading-timeout__title",
|
|
116
|
+
children: "Loading timeout"
|
|
117
|
+
}), /* @__PURE__ */ h("p", {
|
|
118
|
+
className: "oidc-loading-timeout__content",
|
|
119
|
+
children: "Authentication is taking longer than expected. Please try refreshing the page."
|
|
120
|
+
})]
|
|
121
|
+
})
|
|
122
|
+
}), N = () => /* @__PURE__ */ h("div", {
|
|
88
123
|
className: "oidc-serviceworker",
|
|
89
124
|
children: /* @__PURE__ */ g("div", {
|
|
90
125
|
className: "oidc-serviceworker__container",
|
|
@@ -96,7 +131,7 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
96
131
|
children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
|
|
97
132
|
})]
|
|
98
133
|
})
|
|
99
|
-
}),
|
|
134
|
+
}), P = () => /* @__PURE__ */ h("div", {
|
|
100
135
|
className: "oidc-session-lost",
|
|
101
136
|
children: /* @__PURE__ */ g("div", {
|
|
102
137
|
className: "oidc-session-lost__container",
|
|
@@ -108,40 +143,41 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
108
143
|
children: "Your session has expired. Please re-authenticate."
|
|
109
144
|
})]
|
|
110
145
|
})
|
|
111
|
-
}),
|
|
146
|
+
}), F = ({ configurationName: e }) => (d(() => {
|
|
112
147
|
(async () => {
|
|
113
148
|
t.get(e).silentLoginCallbackAsync();
|
|
114
149
|
})().catch((e) => {
|
|
115
150
|
console.error("Error during silent login callback:", e);
|
|
116
151
|
});
|
|
117
|
-
}, [e]), null),
|
|
152
|
+
}, [e]), null), I = ({ configurationName: e }) => {
|
|
118
153
|
let n = s(window.location.href), r = t.get, i = r(e), a = null;
|
|
119
154
|
for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
|
|
120
155
|
return d(() => {
|
|
121
156
|
i.tokens || i.loginAsync(null, a, !0, n.scope);
|
|
122
157
|
}, []), /* @__PURE__ */ h(m, {});
|
|
123
|
-
},
|
|
124
|
-
let [
|
|
158
|
+
}, L = l.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null, navigateAfterCallback: l = null }) => {
|
|
159
|
+
let [u, f] = p(window ? c(window.location.href) : "");
|
|
125
160
|
d(() => {
|
|
126
|
-
let e = () =>
|
|
161
|
+
let e = () => f(c(window.location.href));
|
|
127
162
|
return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
|
|
128
163
|
}, []);
|
|
129
|
-
let
|
|
130
|
-
if (r &&
|
|
131
|
-
if (i &&
|
|
132
|
-
switch (
|
|
133
|
-
case
|
|
164
|
+
let g = c(n);
|
|
165
|
+
if (r && u === c(r)) return /* @__PURE__ */ h(F, { configurationName: o });
|
|
166
|
+
if (i && u === c(i)) return /* @__PURE__ */ h(I, { configurationName: o });
|
|
167
|
+
switch (u) {
|
|
168
|
+
case g: return /* @__PURE__ */ h(A, {
|
|
134
169
|
callBackError: e,
|
|
135
170
|
callBackSuccess: t,
|
|
136
171
|
configurationName: o,
|
|
137
|
-
withCustomHistory: s
|
|
172
|
+
withCustomHistory: s,
|
|
173
|
+
navigateAfterCallback: l
|
|
138
174
|
});
|
|
139
175
|
default: return /* @__PURE__ */ h(m, { children: a });
|
|
140
176
|
}
|
|
141
|
-
}),
|
|
177
|
+
}), R = {
|
|
142
178
|
name: "",
|
|
143
179
|
data: null
|
|
144
|
-
},
|
|
180
|
+
}, z = ({ loadingComponent: e, children: n, configurationName: r }) => {
|
|
145
181
|
let [i, a] = p(!0), o = t.get, s = o(r);
|
|
146
182
|
return d(() => {
|
|
147
183
|
let e = !0;
|
|
@@ -151,102 +187,120 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
151
187
|
e = !1;
|
|
152
188
|
};
|
|
153
189
|
}, [r]), /* @__PURE__ */ h(m, { children: i ? /* @__PURE__ */ h(e, { configurationName: r }) : /* @__PURE__ */ h(m, { children: n }) });
|
|
154
|
-
},
|
|
190
|
+
}, B = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ h(t, {
|
|
155
191
|
configurationName: r,
|
|
156
192
|
children: n
|
|
157
|
-
}) : /* @__PURE__ */ h(m, { children: n }),
|
|
193
|
+
}) : /* @__PURE__ */ h(m, { children: n }), V = 3e4, H = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = j, loadingTimeoutComponent: l = M, serviceWorkerNotSupportedComponent: u = N, authenticatingErrorComponent: f = x, sessionLostComponent: m = P, onSessionLost: g = null, onLogoutFromAnotherTab: _ = null, onLogoutFromSameTab: v = null, withCustomHistory: y = null, navigateAfterCallback: b = null, onEvent: C = null, getFetch: w = null, location: T = null }) => {
|
|
158
194
|
if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri) throw Error("redirect_uri and silent_redirect_uri must be different");
|
|
159
|
-
let
|
|
195
|
+
let E = (e = "default") => t.getOrCreate(w ?? o, T ?? new r())(n, e), [O, k] = p(R), [A, F] = p(i);
|
|
160
196
|
d(() => {
|
|
161
|
-
let e =
|
|
162
|
-
|
|
197
|
+
let e = E(i).subscribeEvents((e, t) => {
|
|
198
|
+
C && C(i, e, t);
|
|
163
199
|
});
|
|
164
200
|
return () => {
|
|
165
|
-
|
|
201
|
+
E(i).removeEventSubscription(e);
|
|
166
202
|
};
|
|
167
|
-
}, [i,
|
|
168
|
-
let e =
|
|
203
|
+
}, [i, C]), d(() => {
|
|
204
|
+
let e = E(i).subscribeEvents((e, r) => {
|
|
169
205
|
if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
|
|
170
|
-
if (
|
|
171
|
-
|
|
206
|
+
if (g != null) {
|
|
207
|
+
g();
|
|
172
208
|
return;
|
|
173
209
|
}
|
|
174
|
-
|
|
210
|
+
k({
|
|
175
211
|
name: e,
|
|
176
212
|
data: r
|
|
177
213
|
});
|
|
178
214
|
} else if (e === t.eventNames.logout_from_another_tab) {
|
|
179
|
-
if (
|
|
180
|
-
|
|
215
|
+
if (_ != null) {
|
|
216
|
+
_();
|
|
181
217
|
return;
|
|
182
218
|
}
|
|
183
|
-
|
|
219
|
+
k({
|
|
184
220
|
name: e,
|
|
185
221
|
data: r
|
|
186
222
|
});
|
|
187
|
-
} else e === t.eventNames.logout_from_same_tab ?
|
|
223
|
+
} else e === t.eventNames.logout_from_same_tab ? v?.() : (e === t.eventNames.loadingTimeout_error || e === t.eventNames.loginAsync_begin || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.loginAsync_error || e === t.eventNames.loginCallbackAsync_error || e === t.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0) && k({
|
|
188
224
|
name: e,
|
|
189
225
|
data: r
|
|
190
226
|
});
|
|
191
227
|
});
|
|
192
228
|
return queueMicrotask(() => {
|
|
193
|
-
|
|
229
|
+
F(i);
|
|
194
230
|
}), () => {
|
|
195
|
-
|
|
231
|
+
E(i).removeEventSubscription(e), k(R);
|
|
196
232
|
};
|
|
197
|
-
}, [n, i])
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
233
|
+
}, [n, i]), d(() => {
|
|
234
|
+
let e = n?.loading_timeout_ms ?? V;
|
|
235
|
+
if (e <= 0 || !(O.name === "" || O.name === t.eventNames.loginAsync_begin)) return;
|
|
236
|
+
let r = setTimeout(() => {
|
|
237
|
+
E(i).publishEvent(t.eventNames.loadingTimeout_error, { timeoutMs: e });
|
|
238
|
+
}, e);
|
|
239
|
+
return () => clearTimeout(r);
|
|
240
|
+
}, [
|
|
241
|
+
O.name,
|
|
242
|
+
i,
|
|
243
|
+
n
|
|
244
|
+
]);
|
|
245
|
+
let I = m, H = s, U = c, W = l, G = u, K = f, q = A !== i, J = E(i);
|
|
246
|
+
switch (O.name) {
|
|
247
|
+
case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(B, {
|
|
248
|
+
loadingComponent: U,
|
|
249
|
+
isLoading: q,
|
|
203
250
|
configurationName: i,
|
|
204
|
-
children: /* @__PURE__ */ h(
|
|
251
|
+
children: /* @__PURE__ */ h(G, { configurationName: i })
|
|
205
252
|
});
|
|
206
|
-
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(
|
|
207
|
-
loadingComponent:
|
|
208
|
-
isLoading:
|
|
253
|
+
case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(B, {
|
|
254
|
+
loadingComponent: U,
|
|
255
|
+
isLoading: q,
|
|
209
256
|
configurationName: i,
|
|
210
|
-
children: /* @__PURE__ */ h(
|
|
257
|
+
children: /* @__PURE__ */ h(H, { configurationName: i })
|
|
258
|
+
});
|
|
259
|
+
case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ h(B, {
|
|
260
|
+
loadingComponent: U,
|
|
261
|
+
isLoading: q,
|
|
262
|
+
configurationName: i,
|
|
263
|
+
children: /* @__PURE__ */ h(W, { configurationName: i })
|
|
211
264
|
});
|
|
212
265
|
case t.eventNames.loginAsync_error:
|
|
213
|
-
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(
|
|
214
|
-
loadingComponent:
|
|
215
|
-
isLoading:
|
|
266
|
+
case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(B, {
|
|
267
|
+
loadingComponent: U,
|
|
268
|
+
isLoading: q,
|
|
216
269
|
configurationName: i,
|
|
217
|
-
children: /* @__PURE__ */ h(
|
|
270
|
+
children: /* @__PURE__ */ h(K, { configurationName: i })
|
|
218
271
|
});
|
|
219
272
|
case t.eventNames.refreshTokensAsync_error:
|
|
220
273
|
case t.eventNames.syncTokensAsync_error:
|
|
221
|
-
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(
|
|
222
|
-
loadingComponent:
|
|
223
|
-
isLoading:
|
|
274
|
+
case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(B, {
|
|
275
|
+
loadingComponent: U,
|
|
276
|
+
isLoading: q,
|
|
224
277
|
configurationName: i,
|
|
225
|
-
children: /* @__PURE__ */ h(
|
|
278
|
+
children: /* @__PURE__ */ h(I, { configurationName: i })
|
|
226
279
|
});
|
|
227
|
-
default: return /* @__PURE__ */ h(
|
|
228
|
-
loadingComponent:
|
|
229
|
-
isLoading:
|
|
280
|
+
default: return /* @__PURE__ */ h(B, {
|
|
281
|
+
loadingComponent: U,
|
|
282
|
+
isLoading: q,
|
|
230
283
|
configurationName: i,
|
|
231
|
-
children: /* @__PURE__ */ h(
|
|
232
|
-
redirect_uri:
|
|
233
|
-
silent_redirect_uri:
|
|
234
|
-
silent_login_uri:
|
|
284
|
+
children: /* @__PURE__ */ h(L, {
|
|
285
|
+
redirect_uri: J.configuration.redirect_uri,
|
|
286
|
+
silent_redirect_uri: J.configuration.silent_redirect_uri,
|
|
287
|
+
silent_login_uri: J.configuration.silent_login_uri,
|
|
235
288
|
callbackSuccessComponent: a,
|
|
236
|
-
callbackErrorComponent:
|
|
289
|
+
callbackErrorComponent: f,
|
|
237
290
|
authenticatingComponent: s,
|
|
238
291
|
configurationName: i,
|
|
239
|
-
withCustomHistory:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
292
|
+
withCustomHistory: y,
|
|
293
|
+
navigateAfterCallback: b,
|
|
294
|
+
location: T ?? new r(),
|
|
295
|
+
children: /* @__PURE__ */ h(z, {
|
|
296
|
+
loadingComponent: U,
|
|
243
297
|
configurationName: i,
|
|
244
298
|
children: e
|
|
245
299
|
})
|
|
246
300
|
})
|
|
247
301
|
});
|
|
248
302
|
}
|
|
249
|
-
},
|
|
303
|
+
}, U = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
|
|
250
304
|
let a = t.get, o = a(i);
|
|
251
305
|
return d(() => {
|
|
252
306
|
o.tokens || o.loginAsync(n, r);
|
|
@@ -255,19 +309,19 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
255
309
|
n,
|
|
256
310
|
r
|
|
257
311
|
]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
|
|
258
|
-
},
|
|
312
|
+
}, W = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(U, {
|
|
259
313
|
callbackPath: t,
|
|
260
314
|
extras: n,
|
|
261
315
|
configurationName: r,
|
|
262
316
|
children: /* @__PURE__ */ h(e, { ...i })
|
|
263
|
-
}),
|
|
317
|
+
}), G = "default", K = (e, t) => {
|
|
264
318
|
let n = !1;
|
|
265
319
|
return e(t) && (n = e(t).tokens != null), n;
|
|
266
|
-
},
|
|
267
|
-
let n = t.get, [r, i] = p(() =>
|
|
320
|
+
}, q = (e = G) => {
|
|
321
|
+
let n = t.get, [r, i] = p(() => K(n, e));
|
|
268
322
|
return d(() => {
|
|
269
323
|
let r = !0, a = n(e), o = a.subscribeEvents((a, o) => {
|
|
270
|
-
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(
|
|
324
|
+
(a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(K(n, e));
|
|
271
325
|
});
|
|
272
326
|
return () => {
|
|
273
327
|
r = !1, a.removeEventSubscription(o);
|
|
@@ -286,10 +340,10 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
286
340
|
},
|
|
287
341
|
isAuthenticated: r
|
|
288
342
|
};
|
|
289
|
-
},
|
|
343
|
+
}, J = {
|
|
290
344
|
accessToken: null,
|
|
291
345
|
accessTokenPayload: null
|
|
292
|
-
},
|
|
346
|
+
}, Y = (e) => {
|
|
293
347
|
let n = t.get, r = n(e);
|
|
294
348
|
if (r.tokens) {
|
|
295
349
|
let e = r.tokens;
|
|
@@ -299,21 +353,21 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
|
|
|
299
353
|
generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
|
|
300
354
|
};
|
|
301
355
|
}
|
|
302
|
-
return
|
|
356
|
+
return J;
|
|
303
357
|
};
|
|
304
|
-
function
|
|
358
|
+
function X(e, t) {
|
|
305
359
|
return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
|
|
306
360
|
}
|
|
307
|
-
var
|
|
308
|
-
let n = t.get, [r, i] = p(() =>
|
|
361
|
+
var Z = (e = G) => {
|
|
362
|
+
let n = t.get, [r, i] = p(() => Y(e));
|
|
309
363
|
return d(() => {
|
|
310
364
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
311
365
|
if ((e === t.eventNames.token_renewed || e === t.eventNames.token_acquired || e === t.eventNames.logout_from_another_tab || e === t.eventNames.logout_from_same_tab || e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) && r) {
|
|
312
366
|
let e = a.tokens;
|
|
313
|
-
i(e == null ?
|
|
367
|
+
i(e == null ? J : {
|
|
314
368
|
accessToken: e.accessToken,
|
|
315
369
|
accessTokenPayload: e.accessTokenPayload,
|
|
316
|
-
generateDemonstrationOfProofOfPossessionAsync:
|
|
370
|
+
generateDemonstrationOfProofOfPossessionAsync: X(a, e)
|
|
317
371
|
});
|
|
318
372
|
}
|
|
319
373
|
});
|
|
@@ -321,10 +375,10 @@ var q = (e = V) => {
|
|
|
321
375
|
r = !1, a.removeEventSubscription(o);
|
|
322
376
|
};
|
|
323
377
|
}, [e]), r;
|
|
324
|
-
},
|
|
378
|
+
}, Q = {
|
|
325
379
|
idToken: null,
|
|
326
380
|
idTokenPayload: null
|
|
327
|
-
},
|
|
381
|
+
}, $ = (e) => {
|
|
328
382
|
let n = t.get, r = n(e);
|
|
329
383
|
if (r.tokens) {
|
|
330
384
|
let e = r.tokens;
|
|
@@ -333,14 +387,14 @@ var q = (e = V) => {
|
|
|
333
387
|
idTokenPayload: e.idTokenPayload
|
|
334
388
|
};
|
|
335
389
|
}
|
|
336
|
-
return
|
|
337
|
-
},
|
|
338
|
-
let n = t.get, [r, i] = p(() =>
|
|
390
|
+
return Q;
|
|
391
|
+
}, ee = (e = G) => {
|
|
392
|
+
let n = t.get, [r, i] = p(() => $(e));
|
|
339
393
|
return d(() => {
|
|
340
394
|
let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
|
|
341
395
|
if ((e === t.eventNames.token_renewed || e === t.eventNames.token_acquired || e === t.eventNames.logout_from_another_tab || e === t.eventNames.logout_from_same_tab || e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) && r) {
|
|
342
396
|
let e = a.tokens;
|
|
343
|
-
i(e == null ?
|
|
397
|
+
i(e == null ? Q : {
|
|
344
398
|
idToken: e.idToken,
|
|
345
399
|
idTokenPayload: e.idTokenPayload
|
|
346
400
|
});
|
|
@@ -350,9 +404,9 @@ var q = (e = V) => {
|
|
|
350
404
|
r = !1, a.removeEventSubscription(o);
|
|
351
405
|
};
|
|
352
406
|
}, [e]), r;
|
|
353
|
-
},
|
|
407
|
+
}, te = /* @__PURE__ */ function(e) {
|
|
354
408
|
return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
|
|
355
|
-
}({}),
|
|
409
|
+
}({}), ne = (e = "default", n = !1) => {
|
|
356
410
|
let r = t.get(e).userInfo(), [i, a] = p({
|
|
357
411
|
user: r,
|
|
358
412
|
status: r ? "User loaded" : "Unauthenticated"
|
|
@@ -404,4 +458,4 @@ var q = (e = V) => {
|
|
|
404
458
|
};
|
|
405
459
|
};
|
|
406
460
|
//#endregion
|
|
407
|
-
export { e as OidcClient, n as OidcLocation,
|
|
461
|
+
export { e as OidcClient, n as OidcLocation, H as OidcProvider, U as OidcSecure, te as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, q as useOidc, Z as useOidcAccessToken, b as useOidcFetch, ee as useOidcIdToken, ne as useOidcUser, y as withOidcFetch, W as withOidcSecure };
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e,t,n=!1)=>async(...r)=>await t().fetchWithTokens(e,n)(...r),p=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=m(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},m=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.get;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o})=>{let[s,c]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.get;try{let{callbackPath:e}=await n(a).loginCallbackAsync();(o?o():b()).replaceState(e||`/`)}catch(t){e&&(console.warn(t),c(!0))}})(),()=>{e=!1}},[]);let l=e||h,u=i||x;return s?(0,r.jsx)(l,{configurationName:a}):(0,r.jsx)(u,{configurationName:a})},C=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),w=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.jsx)(`p`,{className:`oidc-serviceworker__content`,children:`Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.`})]})}),T=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),E=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.get(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),D=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.get,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},O=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null})=>{let[d,f]=(0,n.useState)(window?(0,t.getPath)(window.location.href):``);(0,n.useEffect)(()=>{let e=()=>f((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let p=(0,t.getPath)(a);if(o&&d===(0,t.getPath)(o))return(0,r.jsx)(E,{configurationName:l});if(s&&d===(0,t.getPath)(s))return(0,r.jsx)(D,{configurationName:l});switch(d){case p:return(0,r.jsx)(S,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u});default:return(0,r.jsx)(r.Fragment,{children:c})}}),k={name:``,data:null},A=({loadingComponent:e,children:i,configurationName:a})=>{let[o,s]=(0,n.useState)(!0),c=t.OidcClient.get,l=c(a);return(0,n.useEffect)(()=>{let e=!0;return l&&l.tryKeepExistingSessionAsync().then(()=>{e&&s(!1)}),()=>{e=!1}},[a]),(0,r.jsx)(r.Fragment,{children:o?(0,r.jsx)(e,{configurationName:a}):(0,r.jsx)(r.Fragment,{children:i})})},j=({isLoading:e,loadingComponent:t,children:n,configurationName:i})=>{let a=t;return e?(0,r.jsx)(a,{configurationName:i,children:n}):(0,r.jsx)(r.Fragment,{children:n})},M=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=C,serviceWorkerNotSupportedComponent:l=w,authenticatingErrorComponent:u=h,sessionLostComponent:d=T,onSessionLost:f=null,onLogoutFromAnotherTab:p=null,onLogoutFromSameTab:m=null,withCustomHistory:_=null,onEvent:v=null,getFetch:y=null,location:b=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let S=(e=`default`)=>t.OidcClient.getOrCreate(y??t.getFetchDefault,b??new t.OidcLocation)(i,e),[E,D]=(0,n.useState)(k),[M,N]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=S(a).subscribeEvents((e,t)=>{v&&v(a,e,t)});return()=>{S(a).removeEventSubscription(e)}},[a,v]),(0,n.useEffect)(()=>{let e=S(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}D({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(p!=null){p();return}D({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?m?.():(e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&D({name:e,data:n})});return queueMicrotask(()=>{N(a)}),()=>{S(a).removeEventSubscription(e),D(k)}},[i,a]);let P=d,F=s,I=c,L=l,R=u,z=M!==a,B=S(a);switch(E.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(L,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(F,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(R,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(P,{configurationName:a})});default:return(0,r.jsx)(j,{loadingComponent:I,isLoading:z,configurationName:a,children:(0,r.jsx)(O,{redirect_uri:B.configuration.redirect_uri,silent_redirect_uri:B.configuration.silent_redirect_uri,silent_login_uri:B.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:u,authenticatingComponent:s,configurationName:a,withCustomHistory:_,location:b??new t.OidcLocation,children:(0,r.jsx)(A,{loadingComponent:I,configurationName:a,children:e})})})}},N=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.get,c=s(o);return(0,n.useEffect)(()=>{c.tokens||c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},P=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(N,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),F=`default`,I=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},L=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>I(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(I(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>r(e).loginAsync(t,n,!1,a,i),logout:(t=void 0,n=void 0)=>r(e).logoutAsync(t,n),renewTokens:async(t=void 0)=>{let n=await r(e).renewTokensAsync(t);return{accessToken:n.accessToken,accessTokenPayload:n.accessTokenPayload,idToken:n.idToken,idTokenPayload:n.idTokenPayload}},isAuthenticated:i}},R={accessToken:null,accessTokenPayload:null},z=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return R};function B(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var V=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>z(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?R:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:B(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},H={idToken:null,idTokenPayload:null},U=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return H},W=(e=F)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?H:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},G=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=M,e.OidcSecure=N,e.OidcUserStatus=G,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=L,e.useOidcAccessToken=V,e.useOidcFetch=m,e.useOidcIdToken=W,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e).userInfo(),[a,o]=(0,n.useState)({user:i,status:i?`User loaded`:`Unauthenticated`}),[s,c]=(0,n.useState)(+!!i),l=(0,n.useRef)(+!!i);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(n&&n.tokens){let e=s===l.current;if(e&&n.userInfo())return;l.current=s,queueMicrotask(()=>{i&&o({...a,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:`User loaded`})}).catch(()=>o({...a,status:`Error loading user`}))}else queueMicrotask(()=>{i&&o({user:null,status:`Unauthenticated`})});let c=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&o({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(c)}},[s,e,r]),{oidcUser:a.user,oidcUserLoadingState:a.status,reloadOidcUser:()=>{c(s+1)}}},e.withOidcFetch=p,e.withOidcSecure=P});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e,t,n=!1)=>async(...r)=>await t().fetchWithTokens(e,n)(...r),p=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=m(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},m=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.get;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=200,C=(e,t=window)=>t.location.pathname===e||e===`/`,w=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o,navigateAfterCallback:s})=>{let[c,l]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.get;try{let r=n(a),{callbackPath:i}=await r.loginCallbackAsync(),c=i||`/`;if(s)try{await s(c),r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c})}catch(n){r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:n}),e&&(console.warn(n),l(!0))}else (o?o():b()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},S)}),e&&(C(c)?r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c}):(r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:Error(`Navigation did not commit: expected "${c}" but found "${window.location.pathname}"`)}),l(!0)))}catch(t){e&&(console.warn(t),l(!0))}})(),()=>{e=!1}},[]);let u=e||h,d=i||x;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},T=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),E=()=>(0,r.jsx)(`div`,{className:`oidc-loading-timeout`,children:(0,r.jsxs)(`div`,{className:`oidc-loading-timeout__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-loading-timeout__title`,children:`Loading timeout`}),(0,r.jsx)(`p`,{className:`oidc-loading-timeout__content`,children:`Authentication is taking longer than expected. Please try refreshing the page.`})]})}),D=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.jsx)(`p`,{className:`oidc-serviceworker__content`,children:`Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.`})]})}),O=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),k=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.get(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),A=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.get,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},j=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null,navigateAfterCallback:d=null})=>{let[f,p]=(0,n.useState)(window?(0,t.getPath)(window.location.href):``);(0,n.useEffect)(()=>{let e=()=>p((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let m=(0,t.getPath)(a);if(o&&f===(0,t.getPath)(o))return(0,r.jsx)(k,{configurationName:l});if(s&&f===(0,t.getPath)(s))return(0,r.jsx)(A,{configurationName:l});switch(f){case m:return(0,r.jsx)(w,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u,navigateAfterCallback:d});default:return(0,r.jsx)(r.Fragment,{children:c})}}),M={name:``,data:null},N=({loadingComponent:e,children:i,configurationName:a})=>{let[o,s]=(0,n.useState)(!0),c=t.OidcClient.get,l=c(a);return(0,n.useEffect)(()=>{let e=!0;return l&&l.tryKeepExistingSessionAsync().then(()=>{e&&s(!1)}),()=>{e=!1}},[a]),(0,r.jsx)(r.Fragment,{children:o?(0,r.jsx)(e,{configurationName:a}):(0,r.jsx)(r.Fragment,{children:i})})},P=({isLoading:e,loadingComponent:t,children:n,configurationName:i})=>{let a=t;return e?(0,r.jsx)(a,{configurationName:i,children:n}):(0,r.jsx)(r.Fragment,{children:n})},F=3e4,I=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=T,loadingTimeoutComponent:l=E,serviceWorkerNotSupportedComponent:u=D,authenticatingErrorComponent:d=h,sessionLostComponent:f=O,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:b=null,getFetch:S=null,location:C=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let w=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,A]=(0,n.useState)(M),[I,L]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,t)=>{b&&b(a,e,t)});return()=>{w(a).removeEventSubscription(e)}},[a,b]),(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}A({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}A({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?_?.():(e===t.OidcClient.eventNames.loadingTimeout_error||e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&A({name:e,data:n})});return queueMicrotask(()=>{L(a)}),()=>{w(a).removeEventSubscription(e),A(M)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||!(k.name===``||k.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{w(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,a,i]);let R=f,z=s,B=c,V=l,H=u,U=d,W=I!==a,G=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(z,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(U,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(R,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:B,isLoading:W,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:G.configuration.redirect_uri,silent_redirect_uri:G.configuration.silent_redirect_uri,silent_login_uri:G.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,navigateAfterCallback:y,location:C??new t.OidcLocation,children:(0,r.jsx)(N,{loadingComponent:B,configurationName:a,children:e})})})}},L=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.get,c=s(o);return(0,n.useEffect)(()=>{c.tokens||c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},R=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(L,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),z=`default`,B=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},V=(e=z)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>B(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(B(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>r(e).loginAsync(t,n,!1,a,i),logout:(t=void 0,n=void 0)=>r(e).logoutAsync(t,n),renewTokens:async(t=void 0)=>{let n=await r(e).renewTokensAsync(t);return{accessToken:n.accessToken,accessTokenPayload:n.accessTokenPayload,idToken:n.idToken,idTokenPayload:n.idTokenPayload}},isAuthenticated:i}},H={accessToken:null,accessTokenPayload:null},U=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return H};function W(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var G=(e=z)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?H:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:W(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},K={idToken:null,idTokenPayload:null},q=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return K},J=(e=z)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>q(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e),o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?K:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=I,e.OidcSecure=L,e.OidcUserStatus=Y,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=V,e.useOidcAccessToken=G,e.useOidcFetch=m,e.useOidcIdToken=J,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e).userInfo(),[a,o]=(0,n.useState)({user:i,status:i?`User loaded`:`Unauthenticated`}),[s,c]=(0,n.useState)(+!!i),l=(0,n.useRef)(+!!i);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(n&&n.tokens){let e=s===l.current;if(e&&n.userInfo())return;l.current=s,queueMicrotask(()=>{i&&o({...a,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:`User loaded`})}).catch(()=>o({...a,status:`Error loading user`}))}else queueMicrotask(()=>{i&&o({user:null,status:`Unauthenticated`})});let c=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&o({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(c)}},[s,e,r]),{oidcUser:a.user,oidcUserLoadingState:a.status,reloadOidcUser:()=>{c(s+1)}}},e.withOidcFetch=p,e.withOidcSecure=R});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/react-oidc",
|
|
3
|
-
"version": "7.27.
|
|
3
|
+
"version": "7.27.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"lint": "eslint src"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@axa-fr/oidc-client": "7.27.
|
|
44
|
-
"@axa-fr/oidc-client-service-worker": "7.27.
|
|
43
|
+
"@axa-fr/oidc-client": "7.27.14",
|
|
44
|
+
"@axa-fr/oidc-client-service-worker": "7.27.14"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
|