@axa-fr/react-oidc 7.27.3 → 7.27.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # @axa-fr/react-oidc
2
2
 
3
3
  [![Continuous Integration](https://github.com/AxaFrance/react-oidc/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/AxaFrance/react-oidc/actions/workflows/npm-publish.yml)
4
- [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=AxaGuilDEv_react-oidc&metric=alert_status)](https://sonarcloud.io/dashboard?id=AxaGuilDEv_react-oidc) [![Reliability](https://sonarcloud.io/api/project_badges/measure?project=AxaGuilDEv_react-oidc&metric=reliability_rating)](https://sonarcloud.io/component_measures?id=AxaGuilDEv_react-oidc&metric=reliability_rating) [![Security](https://sonarcloud.io/api/project_badges/measure?project=AxaGuilDEv_react-oidc&metric=security_rating)](https://sonarcloud.io/component_measures?id=AxaGuilDEv_react-oidc&metric=security_rating) [![Code Corevage](https://sonarcloud.io/api/project_badges/measure?project=AxaGuilDEv_react-oidc&metric=coverage)](https://sonarcloud.io/component_measures?id=AxaGuilDEv_react-oidc&metric=Coverage) [![Twitter](https://img.shields.io/twitter/follow/GuildDEvOpen?style=social)](https://twitter.com/intent/follow?screen_name=GuildDEvOpen)
4
+ [![npm downloads](https://img.shields.io/npm/dw/@axa-fr/react-oidc)](https://www.npmjs.com/package/@axa-fr/react-oidc)
5
5
 
6
6
  **@axa-fr/oidc-client** the lightest and securest library to manage authentication with OpenID Connect (OIDC) and OAuth2 protocol. It is compatible with all OIDC providers.
7
7
  **@axa-fr/oidc-client** is a pure javascript library. It works with any JavaScript framework or library.
@@ -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;AAWlF,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,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;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;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAmLjE,CAAC;AAEF,eAAe,YAAY,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;AAWlF,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,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;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;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA+KjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,429 +1,407 @@
1
- import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime";
2
- import { OidcClient as c, getParseQueryStringFromLocation as Q, getPath as A, OidcLocation as F, getFetchDefault as J } from "@axa-fr/oidc-client";
3
- import { OidcClient as Me, OidcLocation as Fe, TokenAutomaticRenewMode as qe, TokenRenewMode as De } from "@axa-fr/oidc-client";
4
- import V, { useCallback as X, useState as f, useEffect as v, useRef as Z } from "react";
5
- const R = "default", ee = (t, n, e = !1) => async (...s) => await n().fetchWithTokens(t, e)(...s), Ae = (t = null, n = R, e = !1) => (s) => (o) => {
6
- const { fetch: r } = te(
7
- t || o.fetch,
8
- n,
9
- e
10
- );
11
- return /* @__PURE__ */ i(s, { ...o, fetch: r });
12
- }, te = (t = null, n = R, e = !1) => {
13
- const s = t || window.fetch, o = c.get;
14
- return { fetch: X(
15
- (d, l) => ee(
16
- s,
17
- () => o(n),
18
- e
19
- )(d, l),
20
- [s, n, e]
21
- ) };
22
- }, x = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
23
- /* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Error authentication" }),
24
- /* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "An error occurred during authentication." })
25
- ] }) }), ne = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
26
- /* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Authentication in progress" }),
27
- /* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "You will be redirected to the login page." })
28
- ] }) }), se = () => Math.random().toString(36).slice(2, 8), oe = (t, n) => (e, s) => {
29
- if (typeof t.CustomEvent == "function")
30
- return new t.CustomEvent(e, s);
31
- const o = s || { bubbles: !1, cancelable: !1, detail: void 0 }, r = n.createEvent("CustomEvent");
32
- return r.initCustomEvent(
33
- e,
34
- o.bubbles,
35
- o.cancelable,
36
- o.detail
37
- ), r.prototype = t.Event.prototype, r;
38
- }, ce = (t, n, e) => ({
39
- replaceState: (s, o) => {
40
- const r = e(), d = o || t.history.state;
41
- t.history.replaceState({ key: r, state: d }, null, s), t.dispatchEvent(n("popstate"));
42
- }
43
- }), re = () => ce(window, oe(window, document), se), W = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ E("div", { className: "oidc-callback__container", children: [
44
- /* @__PURE__ */ i("h1", { className: "oidc-callback__title", children: "Authentication complete" }),
45
- /* @__PURE__ */ i("p", { className: "oidc-callback__content", children: "You will be redirected to your application." })
46
- ] }) }), ie = ({
47
- callBackError: t,
48
- callBackSuccess: n,
49
- configurationName: e,
50
- withCustomHistory: s
51
- }) => {
52
- const [o, r] = f(!1);
53
- v(() => {
54
- let a = !0;
55
- return (async () => {
56
- const h = c.get;
57
- try {
58
- const { callbackPath: _ } = await h(e).loginCallbackAsync();
59
- (s ? s() : re()).replaceState(_ || "/");
60
- } catch (_) {
61
- a && (console.warn(_), r(!0));
62
- }
63
- })(), () => {
64
- a = !1;
65
- };
66
- }, []);
67
- const d = t || x, l = n || W;
68
- return o ? /* @__PURE__ */ i(d, { configurationName: e }) : /* @__PURE__ */ i(l, { configurationName: e });
69
- }, le = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), ae = () => /* @__PURE__ */ i("div", { className: "oidc-serviceworker", children: /* @__PURE__ */ E("div", { className: "oidc-serviceworker__container", children: [
70
- /* @__PURE__ */ i("h1", { className: "oidc-serviceworker__title", children: "Unable to authenticate on this browser" }),
71
- /* @__PURE__ */ i("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." })
72
- ] }) }), de = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */ E("div", { className: "oidc-session-lost__container", children: [
73
- /* @__PURE__ */ i("h1", { className: "oidc-session-lost__title", children: "Session timed out" }),
74
- /* @__PURE__ */ i("p", { className: "oidc-session-lost__content", children: "Your session has expired. Please re-authenticate." })
75
- ] }) }), ue = ({ configurationName: t }) => (v(() => {
76
- (async () => {
77
- c.get(t).silentLoginCallbackAsync();
78
- })().catch((e) => {
79
- console.error("Error during silent login callback:", e);
80
- });
81
- }, [t]), null), he = ({ configurationName: t }) => {
82
- const n = Q(window.location.href), e = c.get, s = e(t);
83
- let o = null;
84
- for (const [r, d] of Object.entries(n))
85
- r === "state" || r === "scope" || (o === null && (o = {}), o[r] = d);
86
- return v(() => {
87
- s.tokens || s.loginAsync(null, o, !0, n.scope);
88
- }, []), /* @__PURE__ */ i(m, {});
89
- }, ke = ({
90
- callbackErrorComponent: t,
91
- callbackSuccessComponent: n,
92
- redirect_uri: e,
93
- silent_redirect_uri: s,
94
- silent_login_uri: o,
95
- children: r,
96
- configurationName: d,
97
- withCustomHistory: l = null
98
- }) => {
99
- const a = window ? A(window.location.href) : "", [u, h] = f(a);
100
- v(() => {
101
- const y = () => h(A(window.location.href));
102
- return y(), window.addEventListener("popstate", y, !1), () => window.removeEventListener("popstate", y, !1);
103
- }, []);
104
- const _ = A(e);
105
- return s && u === A(s) ? /* @__PURE__ */ i(ue, { configurationName: d }) : o && u === A(o) ? /* @__PURE__ */ i(he, { configurationName: d }) : u === _ ? /* @__PURE__ */ i(
106
- ie,
107
- {
108
- callBackError: t,
109
- callBackSuccess: n,
110
- configurationName: d,
111
- withCustomHistory: l
112
- }
113
- ) : /* @__PURE__ */ i(m, { children: r });
114
- }, _e = V.memo(ke), q = { name: "", data: null }, ve = ({
115
- loadingComponent: t,
116
- children: n,
117
- configurationName: e
118
- }) => {
119
- const [s, o] = f(!0), r = c.get, d = r(e);
120
- return v(() => {
121
- let a = !0;
122
- return d && d.tryKeepExistingSessionAsync().then(() => {
123
- a && o(!1);
124
- }), () => {
125
- a = !1;
126
- };
127
- }, [e]), /* @__PURE__ */ i(m, { children: s ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: n }) });
128
- }, O = ({ isLoading: t, loadingComponent: n, children: e, configurationName: s }) => {
129
- const o = n;
130
- return t ? /* @__PURE__ */ i(o, { configurationName: s, children: e }) : /* @__PURE__ */ i(m, { children: e });
131
- }, Oe = ({
132
- children: t,
133
- configuration: n,
134
- configurationName: e = "default",
135
- callbackSuccessComponent: s = W,
136
- authenticatingComponent: o = ne,
137
- loadingComponent: r = le,
138
- serviceWorkerNotSupportedComponent: d = ae,
139
- authenticatingErrorComponent: l = x,
140
- sessionLostComponent: a = de,
141
- onSessionLost: u = null,
142
- onLogoutFromAnotherTab: h = null,
143
- onLogoutFromSameTab: _ = null,
144
- withCustomHistory: y = null,
145
- onEvent: p = null,
146
- getFetch: S = null,
147
- location: U = null
148
- }) => {
149
- if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri)
150
- throw new Error("redirect_uri and silent_redirect_uri must be different");
151
- const w = (L = "default") => c.getOrCreate(S ?? J, U ?? new F())(
152
- n,
153
- L
154
- ), [B, T] = f(q), [z, M] = f(e);
155
- v(() => {
156
- const N = w(e).subscribeEvents((k, g) => {
157
- p && p(e, k, g);
158
- });
159
- return () => {
160
- w(e).removeEventSubscription(N);
161
- };
162
- }, [e, p]), v(() => {
163
- const N = w(e).subscribeEvents((k, g) => {
164
- if (k === c.eventNames.refreshTokensAsync_error || k === c.eventNames.syncTokensAsync_error) {
165
- if (u != null) {
166
- u();
167
- return;
168
- }
169
- T({ name: k, data: g });
170
- } else if (k === c.eventNames.logout_from_another_tab) {
171
- if (h != null) {
172
- h();
173
- return;
174
- }
175
- T({ name: k, data: g });
176
- } else k === c.eventNames.logout_from_same_tab ? _?.() : k === c.eventNames.loginAsync_begin || k === c.eventNames.loginCallbackAsync_end || k === c.eventNames.loginAsync_error || k === c.eventNames.loginCallbackAsync_error ? T({ name: k, data: g }) : k === c.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0 && T({ name: k, data: g });
177
- });
178
- return queueMicrotask(() => {
179
- M(e);
180
- }), () => {
181
- w(e).removeEventSubscription(N), T(q);
182
- };
183
- }, [n, e]), v(() => {
184
- M(e);
185
- }, [e]);
186
- const K = a, $ = o, b = r, G = d, H = l, C = z !== e, P = w(e);
187
- switch (B.name) {
188
- case c.eventNames.service_worker_not_supported_by_browser:
189
- return /* @__PURE__ */ i(
190
- O,
191
- {
192
- loadingComponent: b,
193
- isLoading: C,
194
- configurationName: e,
195
- children: /* @__PURE__ */ i(G, { configurationName: e })
196
- }
197
- );
198
- case c.eventNames.loginAsync_begin:
199
- return /* @__PURE__ */ i(
200
- O,
201
- {
202
- loadingComponent: b,
203
- isLoading: C,
204
- configurationName: e,
205
- children: /* @__PURE__ */ i($, { configurationName: e })
206
- }
207
- );
208
- case c.eventNames.loginAsync_error:
209
- case c.eventNames.loginCallbackAsync_error:
210
- return /* @__PURE__ */ i(
211
- O,
212
- {
213
- loadingComponent: b,
214
- isLoading: C,
215
- configurationName: e,
216
- children: /* @__PURE__ */ i(H, { configurationName: e })
217
- }
218
- );
219
- case c.eventNames.refreshTokensAsync_error:
220
- case c.eventNames.syncTokensAsync_error:
221
- case c.eventNames.logout_from_another_tab:
222
- return /* @__PURE__ */ i(
223
- O,
224
- {
225
- loadingComponent: b,
226
- isLoading: C,
227
- configurationName: e,
228
- children: /* @__PURE__ */ i(K, { configurationName: e })
229
- }
230
- );
231
- default:
232
- return /* @__PURE__ */ i(
233
- O,
234
- {
235
- loadingComponent: b,
236
- isLoading: C,
237
- configurationName: e,
238
- children: /* @__PURE__ */ i(
239
- _e,
240
- {
241
- redirect_uri: P.configuration.redirect_uri,
242
- silent_redirect_uri: P.configuration.silent_redirect_uri,
243
- silent_login_uri: P.configuration.silent_login_uri,
244
- callbackSuccessComponent: s,
245
- callbackErrorComponent: l,
246
- authenticatingComponent: o,
247
- configurationName: e,
248
- withCustomHistory: y,
249
- location: U ?? new F(),
250
- children: /* @__PURE__ */ i(ve, { loadingComponent: b, configurationName: e, children: t })
251
- }
252
- )
253
- }
254
- );
255
- }
256
- }, fe = ({
257
- children: t,
258
- callbackPath: n = null,
259
- extras: e = null,
260
- configurationName: s = "default"
261
- }) => {
262
- const o = c.get, r = o(s);
263
- return v(() => {
264
- r.tokens || r.loginAsync(n, e);
265
- }, [s, n, e]), r.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
266
- }, Ee = (t, n = null, e = null, s = "default") => (o) => /* @__PURE__ */ i(fe, { callbackPath: n, extras: e, configurationName: s, children: /* @__PURE__ */ i(t, { ...o }) }), I = "default", D = (t, n) => {
267
- let e = !1;
268
- return t(n) && (e = t(n).tokens != null), e;
269
- }, Se = (t = I) => {
270
- const n = c.get, [e, s] = f(
271
- () => D(n, t)
272
- );
273
- return v(() => {
274
- let l = !0;
275
- const a = n(t), u = a.subscribeEvents((h, _) => {
276
- (h === c.eventNames.logout_from_another_tab || h === c.eventNames.logout_from_same_tab || h === c.eventNames.token_acquired) && l && s(D(n, t));
277
- });
278
- return () => {
279
- l = !1, a.removeEventSubscription(u);
280
- };
281
- }, [t]), { login: (l = void 0, a = void 0, u = !1, h = void 0) => n(t).loginAsync(
282
- l,
283
- a,
284
- !1,
285
- h,
286
- u
287
- ), logout: (l = void 0, a = void 0) => n(t).logoutAsync(l, a), renewTokens: async (l = void 0) => {
288
- const a = await n(t).renewTokensAsync(l);
289
- return {
290
- // @ts-ignore
291
- accessToken: a.accessToken,
292
- // @ts-ignore
293
- accessTokenPayload: a.accessTokenPayload,
294
- // @ts-ignore
295
- idToken: a.idToken,
296
- // @ts-ignore
297
- idTokenPayload: a.idTokenPayload
298
- };
299
- }, isAuthenticated: e };
300
- }, Y = { accessToken: null, accessTokenPayload: null }, pe = (t) => {
301
- const n = c.get, e = n(t);
302
- if (e.tokens) {
303
- const s = e.tokens;
304
- return {
305
- accessToken: s.accessToken,
306
- accessTokenPayload: s.accessTokenPayload,
307
- generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, r) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, r) : null
308
- };
309
- }
310
- return Y;
1
+ import { OidcClient as e, OidcClient as t, OidcLocation as n, OidcLocation as r, TokenAutomaticRenewMode as i, TokenRenewMode as a, getFetchDefault as o, getParseQueryStringFromLocation as s, getPath as c } from "@axa-fr/oidc-client";
2
+ import l, { useCallback as u, useEffect as d, useRef as f, useState as p } from "react";
3
+ import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
4
+ //#region src/FetchToken.tsx
5
+ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), y = (e = null, t = _, n = !1) => (r) => (i) => {
6
+ let { fetch: a } = b(e || i.fetch, t, n);
7
+ return /* @__PURE__ */ h(r, {
8
+ ...i,
9
+ fetch: a
10
+ });
11
+ }, b = (e = null, n = _, r = !1) => {
12
+ let i = e || window.fetch, a = t.get;
13
+ return { fetch: u((e, t) => v(i, () => a(n), r)(e, t), [
14
+ i,
15
+ n,
16
+ r
17
+ ]) };
18
+ }, x = () => /* @__PURE__ */ h("div", {
19
+ className: "oidc-authenticating",
20
+ children: /* @__PURE__ */ g("div", {
21
+ className: "oidc-authenticating__container",
22
+ children: [/* @__PURE__ */ h("h1", {
23
+ className: "oidc-authenticating__title",
24
+ children: "Error authentication"
25
+ }), /* @__PURE__ */ h("p", {
26
+ className: "oidc-authenticating__content",
27
+ children: "An error occurred during authentication."
28
+ })]
29
+ })
30
+ }), S = () => /* @__PURE__ */ h("div", {
31
+ className: "oidc-authenticating",
32
+ children: /* @__PURE__ */ g("div", {
33
+ className: "oidc-authenticating__container",
34
+ children: [/* @__PURE__ */ h("h1", {
35
+ className: "oidc-authenticating__title",
36
+ children: "Authentication in progress"
37
+ }), /* @__PURE__ */ h("p", {
38
+ className: "oidc-authenticating__content",
39
+ children: "You will be redirected to the login page."
40
+ })]
41
+ })
42
+ }), C = () => Math.random().toString(36).slice(2, 8), w = (e, t) => (n, r) => {
43
+ if (typeof e.CustomEvent == "function") return new e.CustomEvent(n, r);
44
+ let i = r || {
45
+ bubbles: !1,
46
+ cancelable: !1,
47
+ detail: void 0
48
+ }, a = t.createEvent("CustomEvent");
49
+ return a.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), a.prototype = e.Event.prototype, a;
50
+ }, T = (e, t, n) => ({ replaceState: (r, i) => {
51
+ let a = n(), o = i || e.history.state;
52
+ e.history.replaceState({
53
+ key: a,
54
+ state: o
55
+ }, null, r), e.dispatchEvent(t("popstate"));
56
+ } }), E = () => T(window, w(window, document), C), D = () => /* @__PURE__ */ h("div", {
57
+ className: "oidc-callback",
58
+ children: /* @__PURE__ */ g("div", {
59
+ className: "oidc-callback__container",
60
+ children: [/* @__PURE__ */ h("h1", {
61
+ className: "oidc-callback__title",
62
+ children: "Authentication complete"
63
+ }), /* @__PURE__ */ h("p", {
64
+ className: "oidc-callback__content",
65
+ children: "You will be redirected to your application."
66
+ })]
67
+ })
68
+ }), O = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i }) => {
69
+ let [a, o] = p(!1);
70
+ return d(() => {
71
+ let e = !0;
72
+ return (async () => {
73
+ let n = t.get;
74
+ try {
75
+ let { callbackPath: e } = await n(r).loginCallbackAsync();
76
+ (i ? i() : E()).replaceState(e || "/");
77
+ } catch (t) {
78
+ e && (console.warn(t), o(!0));
79
+ }
80
+ })(), () => {
81
+ e = !1;
82
+ };
83
+ }, []), h(a ? e || x : n || D, { configurationName: r });
84
+ }, k = () => /* @__PURE__ */ h("span", {
85
+ className: "oidc-loading",
86
+ children: "Loading"
87
+ }), A = () => /* @__PURE__ */ h("div", {
88
+ className: "oidc-serviceworker",
89
+ children: /* @__PURE__ */ g("div", {
90
+ className: "oidc-serviceworker__container",
91
+ children: [/* @__PURE__ */ h("h1", {
92
+ className: "oidc-serviceworker__title",
93
+ children: "Unable to authenticate on this browser"
94
+ }), /* @__PURE__ */ h("p", {
95
+ className: "oidc-serviceworker__content",
96
+ children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
97
+ })]
98
+ })
99
+ }), j = () => /* @__PURE__ */ h("div", {
100
+ className: "oidc-session-lost",
101
+ children: /* @__PURE__ */ g("div", {
102
+ className: "oidc-session-lost__container",
103
+ children: [/* @__PURE__ */ h("h1", {
104
+ className: "oidc-session-lost__title",
105
+ children: "Session timed out"
106
+ }), /* @__PURE__ */ h("p", {
107
+ className: "oidc-session-lost__content",
108
+ children: "Your session has expired. Please re-authenticate."
109
+ })]
110
+ })
111
+ }), M = ({ configurationName: e }) => (d(() => {
112
+ (async () => {
113
+ t.get(e).silentLoginCallbackAsync();
114
+ })().catch((e) => {
115
+ console.error("Error during silent login callback:", e);
116
+ });
117
+ }, [e]), null), N = ({ configurationName: e }) => {
118
+ let n = s(window.location.href), r = t.get, i = r(e), a = null;
119
+ for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
120
+ return d(() => {
121
+ i.tokens || i.loginAsync(null, a, !0, n.scope);
122
+ }, []), /* @__PURE__ */ h(m, {});
123
+ }, P = l.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null }) => {
124
+ let [l, u] = p(window ? c(window.location.href) : "");
125
+ d(() => {
126
+ let e = () => u(c(window.location.href));
127
+ return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
128
+ }, []);
129
+ let f = c(n);
130
+ if (r && l === c(r)) return /* @__PURE__ */ h(M, { configurationName: o });
131
+ if (i && l === c(i)) return /* @__PURE__ */ h(N, { configurationName: o });
132
+ switch (l) {
133
+ case f: return /* @__PURE__ */ h(O, {
134
+ callBackError: e,
135
+ callBackSuccess: t,
136
+ configurationName: o,
137
+ withCustomHistory: s
138
+ });
139
+ default: return /* @__PURE__ */ h(m, { children: a });
140
+ }
141
+ }), F = {
142
+ name: "",
143
+ data: null
144
+ }, I = ({ loadingComponent: e, children: n, configurationName: r }) => {
145
+ let [i, a] = p(!0), o = t.get, s = o(r);
146
+ return d(() => {
147
+ let e = !0;
148
+ return s && s.tryKeepExistingSessionAsync().then(() => {
149
+ e && a(!1);
150
+ }), () => {
151
+ e = !1;
152
+ };
153
+ }, [r]), /* @__PURE__ */ h(m, { children: i ? /* @__PURE__ */ h(e, { configurationName: r }) : /* @__PURE__ */ h(m, { children: n }) });
154
+ }, L = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ h(t, {
155
+ configurationName: r,
156
+ children: n
157
+ }) : /* @__PURE__ */ h(m, { children: n }), R = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = D, authenticatingComponent: s = S, loadingComponent: c = k, serviceWorkerNotSupportedComponent: l = A, authenticatingErrorComponent: u = x, sessionLostComponent: f = j, onSessionLost: m = null, onLogoutFromAnotherTab: g = null, onLogoutFromSameTab: _ = null, withCustomHistory: v = null, onEvent: y = null, getFetch: b = null, location: C = null }) => {
158
+ 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 w = (e = "default") => t.getOrCreate(b ?? o, C ?? new r())(n, e), [T, E] = p(F), [O, M] = p(i);
160
+ d(() => {
161
+ let e = w(i).subscribeEvents((e, t) => {
162
+ y && y(i, e, t);
163
+ });
164
+ return () => {
165
+ w(i).removeEventSubscription(e);
166
+ };
167
+ }, [i, y]), d(() => {
168
+ let e = w(i).subscribeEvents((e, r) => {
169
+ if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
170
+ if (m != null) {
171
+ m();
172
+ return;
173
+ }
174
+ E({
175
+ name: e,
176
+ data: r
177
+ });
178
+ } else if (e === t.eventNames.logout_from_another_tab) {
179
+ if (g != null) {
180
+ g();
181
+ return;
182
+ }
183
+ E({
184
+ name: e,
185
+ data: r
186
+ });
187
+ } else e === t.eventNames.logout_from_same_tab ? _?.() : (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) && E({
188
+ name: e,
189
+ data: r
190
+ });
191
+ });
192
+ return queueMicrotask(() => {
193
+ M(i);
194
+ }), () => {
195
+ w(i).removeEventSubscription(e), E(F);
196
+ };
197
+ }, [n, i]);
198
+ let N = f, R = s, z = c, B = l, V = u, H = O !== i, U = w(i);
199
+ switch (T.name) {
200
+ case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(L, {
201
+ loadingComponent: z,
202
+ isLoading: H,
203
+ configurationName: i,
204
+ children: /* @__PURE__ */ h(B, { configurationName: i })
205
+ });
206
+ case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(L, {
207
+ loadingComponent: z,
208
+ isLoading: H,
209
+ configurationName: i,
210
+ children: /* @__PURE__ */ h(R, { configurationName: i })
211
+ });
212
+ case t.eventNames.loginAsync_error:
213
+ case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(L, {
214
+ loadingComponent: z,
215
+ isLoading: H,
216
+ configurationName: i,
217
+ children: /* @__PURE__ */ h(V, { configurationName: i })
218
+ });
219
+ case t.eventNames.refreshTokensAsync_error:
220
+ case t.eventNames.syncTokensAsync_error:
221
+ case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(L, {
222
+ loadingComponent: z,
223
+ isLoading: H,
224
+ configurationName: i,
225
+ children: /* @__PURE__ */ h(N, { configurationName: i })
226
+ });
227
+ default: return /* @__PURE__ */ h(L, {
228
+ loadingComponent: z,
229
+ isLoading: H,
230
+ configurationName: i,
231
+ children: /* @__PURE__ */ h(P, {
232
+ redirect_uri: U.configuration.redirect_uri,
233
+ silent_redirect_uri: U.configuration.silent_redirect_uri,
234
+ silent_login_uri: U.configuration.silent_login_uri,
235
+ callbackSuccessComponent: a,
236
+ callbackErrorComponent: u,
237
+ authenticatingComponent: s,
238
+ configurationName: i,
239
+ withCustomHistory: v,
240
+ location: C ?? new r(),
241
+ children: /* @__PURE__ */ h(I, {
242
+ loadingComponent: z,
243
+ configurationName: i,
244
+ children: e
245
+ })
246
+ })
247
+ });
248
+ }
249
+ }, z = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
250
+ let a = t.get, o = a(i);
251
+ return d(() => {
252
+ o.tokens || o.loginAsync(n, r);
253
+ }, [
254
+ i,
255
+ n,
256
+ r
257
+ ]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
258
+ }, B = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(z, {
259
+ callbackPath: t,
260
+ extras: n,
261
+ configurationName: r,
262
+ children: /* @__PURE__ */ h(e, { ...i })
263
+ }), V = "default", H = (e, t) => {
264
+ let n = !1;
265
+ return e(t) && (n = e(t).tokens != null), n;
266
+ }, U = (e = V) => {
267
+ let n = t.get, [r, i] = p(() => H(n, e));
268
+ return d(() => {
269
+ 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(H(n, e));
271
+ });
272
+ return () => {
273
+ r = !1, a.removeEventSubscription(o);
274
+ };
275
+ }, [e]), {
276
+ login: (t = void 0, r = void 0, i = !1, a = void 0) => n(e).loginAsync(t, r, !1, a, i),
277
+ logout: (t = void 0, r = void 0) => n(e).logoutAsync(t, r),
278
+ renewTokens: async (t = void 0) => {
279
+ let r = await n(e).renewTokensAsync(t);
280
+ return {
281
+ accessToken: r.accessToken,
282
+ accessTokenPayload: r.accessTokenPayload,
283
+ idToken: r.idToken,
284
+ idTokenPayload: r.idTokenPayload
285
+ };
286
+ },
287
+ isAuthenticated: r
288
+ };
289
+ }, W = {
290
+ accessToken: null,
291
+ accessTokenPayload: null
292
+ }, G = (e) => {
293
+ let n = t.get, r = n(e);
294
+ if (r.tokens) {
295
+ let e = r.tokens;
296
+ return {
297
+ accessToken: e.accessToken,
298
+ accessTokenPayload: e.accessTokenPayload,
299
+ generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
300
+ };
301
+ }
302
+ return W;
311
303
  };
312
- function ye(t, n) {
313
- return t.configuration.demonstrating_proof_of_possession ? (e, s, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken, e, s, o) : null;
304
+ function K(e, t) {
305
+ return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
314
306
  }
315
- const Pe = (t = I) => {
316
- const n = c.get, [e, s] = f(() => pe(t));
317
- return v(() => {
318
- let o = !0;
319
- const r = n(t), d = r.subscribeEvents((l, a) => {
320
- if ((l === c.eventNames.token_renewed || l === c.eventNames.token_acquired || l === c.eventNames.logout_from_another_tab || l === c.eventNames.logout_from_same_tab || l === c.eventNames.refreshTokensAsync_error || l === c.eventNames.syncTokensAsync_error) && o) {
321
- const u = r.tokens;
322
- s(
323
- u != null ? {
324
- accessToken: u.accessToken,
325
- accessTokenPayload: u.accessTokenPayload,
326
- generateDemonstrationOfProofOfPossessionAsync: ye(r, u)
327
- } : Y
328
- );
329
- }
330
- });
331
- return () => {
332
- o = !1, r.removeEventSubscription(d);
333
- };
334
- }, [t]), e;
335
- }, j = { idToken: null, idTokenPayload: null }, be = (t) => {
336
- const n = c.get, e = n(t);
337
- if (e.tokens) {
338
- const s = e.tokens;
339
- return { idToken: s.idToken, idTokenPayload: s.idTokenPayload };
340
- }
341
- return j;
342
- }, Le = (t = I) => {
343
- const n = c.get, [e, s] = f(() => be(t));
344
- return v(() => {
345
- let o = !0;
346
- const r = n(t), d = r.subscribeEvents((l, a) => {
347
- if ((l === c.eventNames.token_renewed || l === c.eventNames.token_acquired || l === c.eventNames.logout_from_another_tab || l === c.eventNames.logout_from_same_tab || l === c.eventNames.refreshTokensAsync_error || l === c.eventNames.syncTokensAsync_error) && o) {
348
- const u = r.tokens;
349
- s(
350
- u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : j
351
- );
352
- }
353
- });
354
- return () => {
355
- o = !1, r.removeEventSubscription(d);
356
- };
357
- }, [t]), e;
358
- };
359
- var ge = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(ge || {});
360
- const Ne = (t = "default", n = !1) => {
361
- const s = c.get(t).userInfo(), [o, r] = f({
362
- user: s,
363
- status: s ? "User loaded" : "Unauthenticated"
364
- /* Unauthenticated */
365
- }), [d, l] = f(s ? 1 : 0), a = Z(s ? 1 : 0);
366
- v(() => {
367
- const h = c.get(t);
368
- let _ = !0;
369
- if (h && h.tokens) {
370
- const p = d === a.current;
371
- if (p && h.userInfo())
372
- return;
373
- a.current = d, queueMicrotask(() => {
374
- _ && r({
375
- ...o,
376
- status: "Loading user"
377
- /* Loading */
378
- });
379
- }), h.userInfoAsync(!p, n).then((S) => {
380
- _ && r({
381
- user: S,
382
- status: "User loaded"
383
- /* Loaded */
384
- });
385
- }).catch(() => r({
386
- ...o,
387
- status: "Error loading user"
388
- /* LoadingError */
389
- }));
390
- } else
391
- queueMicrotask(() => {
392
- _ && r({
393
- user: null,
394
- status: "Unauthenticated"
395
- /* Unauthenticated */
396
- });
397
- });
398
- const y = h.subscribeEvents((p) => {
399
- (p === c.eventNames.logout_from_another_tab || p === c.eventNames.logout_from_same_tab) && _ && r({
400
- user: null,
401
- status: "Unauthenticated"
402
- /* Unauthenticated */
403
- });
404
- });
405
- return () => {
406
- _ = !1, h.removeEventSubscription(y);
407
- };
408
- }, [d, t, n]);
409
- const u = () => {
410
- l(d + 1);
411
- };
412
- return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: u };
413
- };
414
- export {
415
- Me as OidcClient,
416
- Fe as OidcLocation,
417
- Oe as OidcProvider,
418
- fe as OidcSecure,
419
- ge as OidcUserStatus,
420
- qe as TokenAutomaticRenewMode,
421
- De as TokenRenewMode,
422
- Se as useOidc,
423
- Pe as useOidcAccessToken,
424
- te as useOidcFetch,
425
- Le as useOidcIdToken,
426
- Ne as useOidcUser,
427
- Ae as withOidcFetch,
428
- Ee as withOidcSecure
307
+ var q = (e = V) => {
308
+ let n = t.get, [r, i] = p(() => G(e));
309
+ return d(() => {
310
+ let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
311
+ 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
+ let e = a.tokens;
313
+ i(e == null ? W : {
314
+ accessToken: e.accessToken,
315
+ accessTokenPayload: e.accessTokenPayload,
316
+ generateDemonstrationOfProofOfPossessionAsync: K(a, e)
317
+ });
318
+ }
319
+ });
320
+ return () => {
321
+ r = !1, a.removeEventSubscription(o);
322
+ };
323
+ }, [e]), r;
324
+ }, J = {
325
+ idToken: null,
326
+ idTokenPayload: null
327
+ }, Y = (e) => {
328
+ let n = t.get, r = n(e);
329
+ if (r.tokens) {
330
+ let e = r.tokens;
331
+ return {
332
+ idToken: e.idToken,
333
+ idTokenPayload: e.idTokenPayload
334
+ };
335
+ }
336
+ return J;
337
+ }, X = (e = V) => {
338
+ let n = t.get, [r, i] = p(() => Y(e));
339
+ return d(() => {
340
+ let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
341
+ 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
+ let e = a.tokens;
343
+ i(e == null ? J : {
344
+ idToken: e.idToken,
345
+ idTokenPayload: e.idTokenPayload
346
+ });
347
+ }
348
+ });
349
+ return () => {
350
+ r = !1, a.removeEventSubscription(o);
351
+ };
352
+ }, [e]), r;
353
+ }, Z = /* @__PURE__ */ function(e) {
354
+ return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
355
+ }({}), Q = (e = "default", n = !1) => {
356
+ let r = t.get(e).userInfo(), [i, a] = p({
357
+ user: r,
358
+ status: r ? Z.Loaded : Z.Unauthenticated
359
+ }), [o, s] = p(+!!r), c = f(+!!r);
360
+ return d(() => {
361
+ let r = t.get(e), s = !0;
362
+ if (r && r.tokens) {
363
+ let e = o === c.current;
364
+ if (e && r.userInfo()) return;
365
+ c.current = o, queueMicrotask(() => {
366
+ s && a({
367
+ ...i,
368
+ status: Z.Loading
369
+ });
370
+ }), r.userInfoAsync(!e, n).then((e) => {
371
+ s && a({
372
+ user: e,
373
+ status: Z.Loaded
374
+ });
375
+ }).catch(() => a({
376
+ ...i,
377
+ status: Z.LoadingError
378
+ }));
379
+ } else queueMicrotask(() => {
380
+ s && a({
381
+ user: null,
382
+ status: Z.Unauthenticated
383
+ });
384
+ });
385
+ let l = r.subscribeEvents((e) => {
386
+ (e === t.eventNames.logout_from_another_tab || e === t.eventNames.logout_from_same_tab) && s && a({
387
+ user: null,
388
+ status: Z.Unauthenticated
389
+ });
390
+ });
391
+ return () => {
392
+ s = !1, r.removeEventSubscription(l);
393
+ };
394
+ }, [
395
+ o,
396
+ e,
397
+ n
398
+ ]), {
399
+ oidcUser: i.user,
400
+ oidcUserLoadingState: i.status,
401
+ reloadOidcUser: () => {
402
+ s(o + 1);
403
+ }
404
+ };
429
405
  };
406
+ //#endregion
407
+ export { e as OidcClient, n as OidcLocation, R as OidcProvider, z as OidcSecure, Z as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, U as useOidc, q as useOidcAccessToken, b as useOidcFetch, X as useOidcIdToken, Q as useOidcUser, y as withOidcFetch, B as withOidcSecure };
@@ -1 +1 @@
1
- (function(f,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,(function(f,c,s,d){"use strict";const N="default",z=(t,n,e=!1)=>async(...o)=>await n().fetchWithTokens(t,e)(...o),K=(t=null,n=N,e=!1)=>o=>r=>{const{fetch:i}=F(t||r.fetch,n,e);return c.jsx(o,{...r,fetch:i})},F=(t=null,n=N,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:d.useCallback((u,a)=>z(o,()=>r(n),e)(u,a),[o,n,e])}},I=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),c.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),c.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),G=()=>Math.random().toString(36).slice(2,8),H=(t,n)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=n.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},Q=(t,n,e)=>({replaceState:(o,r)=>{const i=e(),u=r||t.history.state;t.history.replaceState({key:i,state:u},null,o),t.dispatchEvent(n("popstate"))}}),J=()=>Q(window,H(window,document),G),m=()=>c.jsx("div",{className:"oidc-callback",children:c.jsxs("div",{className:"oidc-callback__container",children:[c.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),c.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),V=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:o})=>{const[r,i]=d.useState(!1);d.useEffect(()=>{let l=!0;return(async()=>{const k=s.OidcClient.get;try{const{callbackPath:O}=await k(e).loginCallbackAsync();(o?o():J()).replaceState(O||"/")}catch(O){l&&(console.warn(O),i(!0))}})(),()=>{l=!1}},[]);const u=t||I,a=n||m;return r?c.jsx(u,{configurationName:e}):c.jsx(a,{configurationName:e})},X=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),Z=()=>c.jsx("div",{className:"oidc-serviceworker",children:c.jsxs("div",{className:"oidc-serviceworker__container",children:[c.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),c.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."})]})}),x=()=>c.jsx("div",{className:"oidc-session-lost",children:c.jsxs("div",{className:"oidc-session-lost__container",children:[c.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),c.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),R=({configurationName:t})=>(d.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),ee=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,u]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=u);return d.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,n.scope)},[]),c.jsx(c.Fragment,{})},te=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:u,withCustomHistory:a=null})=>{const l=window?s.getPath(window.location.href):"",[h,k]=d.useState(l);d.useEffect(()=>{const y=()=>k(s.getPath(window.location.href));return y(),window.addEventListener("popstate",y,!1),()=>window.removeEventListener("popstate",y,!1)},[]);const O=s.getPath(e);return o&&h===s.getPath(o)?c.jsx(R,{configurationName:u}):r&&h===s.getPath(r)?c.jsx(ee,{configurationName:u}):h===O?c.jsx(V,{callBackError:t,callBackSuccess:n,configurationName:u,withCustomHistory:a}):c.jsx(c.Fragment,{children:i})},se=d.memo(te),M={name:"",data:null},ne=({loadingComponent:t,children:n,configurationName:e})=>{const[o,r]=d.useState(!0),i=s.OidcClient.get,u=i(e);d.useEffect(()=>{let l=!0;return u&&u.tryKeepExistingSessionAsync().then(()=>{l&&r(!1)}),()=>{l=!1}},[e]);const a=t;return c.jsx(c.Fragment,{children:o?c.jsx(a,{configurationName:e}):c.jsx(c.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:o})=>{const r=n;return t?c.jsx(r,{configurationName:o,children:e}):c.jsx(c.Fragment,{children:e})},ce=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:o=m,authenticatingComponent:r=$,loadingComponent:i=X,serviceWorkerNotSupportedComponent:u=Z,authenticatingErrorComponent:a=I,sessionLostComponent:l=x,onSessionLost:h=null,onLogoutFromAnotherTab:k=null,onLogoutFromSameTab:O=null,withCustomHistory:y=null,onEvent:v=null,getFetch:S=null,location:Y=null})=>{if(n&&n.redirect_uri&&n.silent_redirect_uri&&n.redirect_uri===n.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const w=(C="default")=>s.OidcClient.getOrCreate(S??s.getFetchDefault,Y??new s.OidcLocation)(n,C),[fe,T]=d.useState(M),[ke,B]=d.useState(e);d.useEffect(()=>{const L=w(e).subscribeEvents((_,g)=>{v&&v(e,_,g)});return()=>{w(e).removeEventSubscription(L)}},[e,v]),d.useEffect(()=>{const L=w(e).subscribeEvents((_,g)=>{if(_===s.OidcClient.eventNames.refreshTokensAsync_error||_===s.OidcClient.eventNames.syncTokensAsync_error){if(h!=null){h();return}T({name:_,data:g})}else if(_===s.OidcClient.eventNames.logout_from_another_tab){if(k!=null){k();return}T({name:_,data:g})}else _===s.OidcClient.eventNames.logout_from_same_tab?O?.():_===s.OidcClient.eventNames.loginAsync_begin||_===s.OidcClient.eventNames.loginCallbackAsync_end||_===s.OidcClient.eventNames.loginAsync_error||_===s.OidcClient.eventNames.loginCallbackAsync_error?T({name:_,data:g}):_===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&T({name:_,data:g})});return queueMicrotask(()=>{B(e)}),()=>{w(e).removeEventSubscription(L),T(M)}},[n,e]),d.useEffect(()=>{B(e)},[e]);const _e=l,Oe=r,b=i,ve=u,ye=a,A=ke!==e,P=w(e);switch(fe.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(Oe,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(_e,{configurationName:e})});default:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(se,{redirect_uri:P.configuration.redirect_uri,silent_redirect_uri:P.configuration.silent_redirect_uri,silent_login_uri:P.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:y,location:Y??new s.OidcLocation,children:c.jsx(ne,{loadingComponent:b,configurationName:e,children:t})})})}},U=({children:t,callbackPath:n=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return d.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[o,n,e]),i.tokens?c.jsx(c.Fragment,{children:t}):null},oe=(t,n=null,e=null,o="default")=>r=>c.jsx(U,{callbackPath:n,extras:e,configurationName:o,children:c.jsx(t,{...r})}),E="default",q=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},re=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>q(n,t));return d.useEffect(()=>{let a=!0;const l=n(t),h=l.subscribeEvents((k,O)=>{(k===s.OidcClient.eventNames.logout_from_another_tab||k===s.OidcClient.eventNames.logout_from_same_tab||k===s.OidcClient.eventNames.token_acquired)&&a&&o(q(n,t))});return()=>{a=!1,l.removeEventSubscription(h)}},[t]),{login:(a=void 0,l=void 0,h=!1,k=void 0)=>n(t).loginAsync(a,l,!1,k,h),logout:(a=void 0,l=void 0)=>n(t).logoutAsync(a,l),renewTokens:async(a=void 0)=>{const l=await n(t).renewTokensAsync(a);return{accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload,idToken:l.idToken,idTokenPayload:l.idTokenPayload}},isAuthenticated:e}},D={accessToken:null,accessTokenPayload:null},ie=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,i):null}}return D};function ae(t,n){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,o,r):null}const le=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>ie(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const h=i.tokens;o(h!=null?{accessToken:h.accessToken,accessTokenPayload:h.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(i,h)}:D)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e},W={idToken:null,idTokenPayload:null},de=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return W},ue=(t=E)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>de(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const h=i.tokens;o(h!=null?{idToken:h.idToken,idTokenPayload:h.idTokenPayload}:W)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e};var j=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(j||{});const he=(t="default",n=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=d.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[u,a]=d.useState(o?1:0),l=d.useRef(o?1:0);d.useEffect(()=>{const k=s.OidcClient.get(t);let O=!0;if(k&&k.tokens){const v=u===l.current;if(v&&k.userInfo())return;l.current=u,queueMicrotask(()=>{O&&i({...r,status:"Loading user"})}),k.userInfoAsync(!v,n).then(S=>{O&&i({user:S,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{O&&i({user:null,status:"Unauthenticated"})});const y=k.subscribeEvents(v=>{(v===s.OidcClient.eventNames.logout_from_another_tab||v===s.OidcClient.eventNames.logout_from_same_tab)&&O&&i({user:null,status:"Unauthenticated"})});return()=>{O=!1,k.removeEventSubscription(y)}},[u,t,n]);const h=()=>{a(u+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:h}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),f.OidcProvider=ce,f.OidcSecure=U,f.OidcUserStatus=j,f.useOidc=re,f.useOidcAccessToken=le,f.useOidcFetch=F,f.useOidcIdToken=ue,f.useOidcUser=he,f.withOidcFetch=K,f.withOidcSecure=oe,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
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?G.Loaded:G.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:G.Loading})}),n.userInfoAsync(!e,r).then(e=>{i&&o({user:e,status:G.Loaded})}).catch(()=>o({...a,status:G.LoadingError}))}else queueMicrotask(()=>{i&&o({user:null,status:G.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:G.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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.27.3",
3
+ "version": "7.27.4",
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-service-worker": "7.27.3",
44
- "@axa-fr/oidc-client": "7.27.3"
43
+ "@axa-fr/oidc-client": "7.27.4",
44
+ "@axa-fr/oidc-client-service-worker": "7.27.4"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
@@ -50,21 +50,21 @@
50
50
  "@testing-library/jest-dom": "6.9.1",
51
51
  "@testing-library/react": "16.3.2",
52
52
  "@testing-library/user-event": "14.6.1",
53
- "@types/react": "19.2.10",
54
- "@vitejs/plugin-react": "5.1.2",
55
- "@vitest/coverage-v8": "4.0.18",
56
- "cpy": "12.1.0",
57
- "cpy-cli": "^6.0.0",
53
+ "@types/react": "19.2.14",
54
+ "@vitejs/plugin-react": "6.0.1",
55
+ "@vitest/coverage-v8": "4.1.5",
56
+ "cpy": "13.2.1",
57
+ "cpy-cli": "^7.0.0",
58
58
  "cross-env": "^10.1.0",
59
- "jsdom": "27.4.0",
60
- "msw": "2.12.7",
61
- "react": "^19.2.4",
62
- "react-dom": "^19.2.4",
63
- "rimraf": "6.1.2",
64
- "typescript": "5.9.3",
65
- "vite": "7.3.1",
59
+ "jsdom": "29.0.2",
60
+ "msw": "2.13.6",
61
+ "react": "^19.2.5",
62
+ "react-dom": "^19.2.5",
63
+ "rimraf": "6.1.3",
64
+ "typescript": "6.0.3",
65
+ "vite": "8.0.10",
66
66
  "vite-plugin-dts": "4.5.4",
67
- "vitest": "4.0.18"
67
+ "vitest": "4.1.5"
68
68
  },
69
69
  "license": "MIT",
70
70
  "publishConfig": {
@@ -181,10 +181,6 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
181
181
  };
182
182
  }, [configuration, configurationName]);
183
183
 
184
- useEffect(() => {
185
- setConfigurationName(configurationName);
186
- }, [configurationName]);
187
-
188
184
  const SessionLostComponent = sessionLostComponent;
189
185
  const AuthenticatingComponent = authenticatingComponent;
190
186
  const LoadingComponent = loadingComponent;