@axa-fr/react-oidc 7.29.4 → 7.29.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/FetchToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,qBAAqB,CAAC;AAGxD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAgBD,eAAO,MAAM,aAAa,GAEtB,QAAO,KAAY,EACnB,0BAA4C,EAC5C,iCAAgC,OAAe,MAEjD,qBAAgB,MACf,OAAO,2BAA2B,gCAOlC,CAAC;AAEJ,eAAO,MAAM,YAAY,GACvB,QAAO,KAAY,EACnB,0BAA4C,EAC5C,iCAAgC,OAAe;mBAQrC,WAAW,GAAG,GAAG,SAAS,WAAW;CAYhD,CAAC"}
1
+ {"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/FetchToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,qBAAqB,CAAC;AAGxD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAID,eAAO,MAAM,aAAa,GAEtB,QAAO,KAAY,EACnB,0BAA4C,EAC5C,iCAAgC,OAAe,MAEjD,qBAAgB,MACf,OAAO,2BAA2B,gCAOlC,CAAC;AAEJ,eAAO,MAAM,YAAY,GACvB,QAAO,KAAY,EACnB,0BAA4C,EAC5C,iCAAgC,OAAe;mBAQ/B,WAAW,GAAG,GAAG,SAAS,WAAW,KAAG,OAAO,CAAC,QAAQ,CAAC;CAW1E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAoBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;2BAkClD,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM,KACZ,OAAO,CAAC,OAAO,CAAC;4BASH,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,IAAI,CAAC;2BASN,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAoB1C,CAAC;AAyBF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACrD,CAAC;AASF,eAAO,MAAM,kBAAkB,GAAI,0BAA4C,oBA2C9E,CAAC;AAkBF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0BAA4C,gBAsC1E,CAAC"}
1
+ {"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAwBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;2BAkClD,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM,KACZ,OAAO,CAAC,OAAO,CAAC;4BASH,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,IAAI,CAAC;2BASN,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAoB1C,CAAC;AAyBF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACrD,CAAC;AASF,eAAO,MAAM,kBAAkB,GAAI,0BAA4C,oBAoC9E,CAAC;AAkBF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0BAA4C,gBA+B1E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SilentLogin.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/SilentLogin.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAa,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,WAAW,EAAE,aAAa,CAAC,GAAG,CAyBnC,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"SilentLogin.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/SilentLogin.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAa,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,WAAW,EAAE,aAAa,CAAC,GAAG,CAuBnC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -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,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;;AAuDF,wBAAsC"}
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;;AAiDF,wBAAsC"}
package/dist/index.js CHANGED
@@ -2,20 +2,20 @@ import { OidcClient as e, OidcClient as t, OidcError as n, OidcErrorCode as r, O
2
2
  import v, { useCallback as y, useEffect as b, useRef as x, useState as S } from "react";
3
3
  import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
4
4
  //#region src/FetchToken.tsx
5
- var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), O = (e = null, t = E, n = !1) => (r) => (i) => {
6
- let { fetch: a } = k(e || i.fetch, t, n);
5
+ var E = "default", D = (e = null, t = E, n = !1) => (r) => (i) => {
6
+ let { fetch: a } = O(e || i.fetch, t, n);
7
7
  return /* @__PURE__ */ w(r, {
8
8
  ...i,
9
9
  fetch: a
10
10
  });
11
- }, k = (e = null, n = E, r = !1) => {
11
+ }, O = (e = null, n = E, r = !1) => {
12
12
  let i = e || window.fetch, a = t.getOrThrow;
13
- return { fetch: y((e, t) => D(i, () => a(n), r)(e, t), [
13
+ return { fetch: y(async (e, t) => await a(n).fetchWithTokens(i, r)(e, t), [
14
14
  i,
15
15
  n,
16
16
  r
17
17
  ]) };
18
- }, A = () => /* @__PURE__ */ w("div", {
18
+ }, k = () => /* @__PURE__ */ w("div", {
19
19
  className: "oidc-authenticating",
20
20
  children: /* @__PURE__ */ T("div", {
21
21
  className: "oidc-authenticating__container",
@@ -39,7 +39,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
39
39
  children: "You will be redirected to the login page."
40
40
  })]
41
41
  })
42
- }), j = () => Math.random().toString(36).slice(2, 8), M = (e, t) => (n, r) => {
42
+ }), A = () => Math.random().toString(36).slice(2, 8), j = (e, t) => (n, r) => {
43
43
  if (typeof e.CustomEvent == "function") return new e.CustomEvent(n, r);
44
44
  let i = r || {
45
45
  bubbles: !1,
@@ -47,13 +47,13 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
47
47
  detail: void 0
48
48
  }, a = t.createEvent("CustomEvent");
49
49
  return a.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), a.prototype = e.Event.prototype, a;
50
- }, N = (e, t, n) => ({ replaceState: (r, i) => {
50
+ }, M = (e, t, n) => ({ replaceState: (r, i) => {
51
51
  let a = n(), o = i || e.history.state;
52
52
  e.history.replaceState({
53
53
  key: a,
54
54
  state: o
55
55
  }, null, r), e.dispatchEvent(t("popstate"));
56
- } }), P = () => N(window, M(window, document), j), F = () => /* @__PURE__ */ w("div", {
56
+ } }), N = () => M(window, j(window, document), A), P = () => /* @__PURE__ */ w("div", {
57
57
  className: "oidc-callback",
58
58
  children: /* @__PURE__ */ T("div", {
59
59
  className: "oidc-callback__container",
@@ -65,7 +65,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
65
65
  children: "You will be redirected to your application."
66
66
  })]
67
67
  })
68
- }), I = 200, L = (e, t = window) => t.location.pathname === e || e === "/", R = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
68
+ }), F = 200, I = (e, t = window) => t.location.pathname === e || e === "/", L = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
69
69
  let [o, s] = S(!1);
70
70
  return b(() => {
71
71
  let e = !0;
@@ -85,11 +85,11 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
85
85
  error: n
86
86
  }), e && (console.warn(n), s(!0));
87
87
  }
88
- else (i ? i() : P()).replaceState(l), await new Promise((e) => {
88
+ else (i ? i() : N()).replaceState(l), await new Promise((e) => {
89
89
  setTimeout(() => {
90
90
  e();
91
- }, I);
92
- }), e && (L(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
91
+ }, F);
92
+ }), e && (I(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
93
93
  configurationName: r,
94
94
  callbackPath: l
95
95
  }) : (o.publishEvent(t.eventNames.loginCallbackAsync_navigation_error, {
@@ -103,11 +103,11 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
103
103
  })(), () => {
104
104
  e = !1;
105
105
  };
106
- }, []), w(o ? e || A : n || F, { configurationName: r });
107
- }, te = () => /* @__PURE__ */ w("span", {
106
+ }, []), w(o ? e || k : n || P, { configurationName: r });
107
+ }, R = () => /* @__PURE__ */ w("span", {
108
108
  className: "oidc-loading",
109
109
  children: "Loading"
110
- }), ne = () => /* @__PURE__ */ w("div", {
110
+ }), te = () => /* @__PURE__ */ w("div", {
111
111
  className: "oidc-loading-timeout",
112
112
  children: /* @__PURE__ */ T("div", {
113
113
  className: "oidc-loading-timeout__container",
@@ -119,7 +119,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
119
119
  children: "Authentication is taking longer than expected. Please try refreshing the page."
120
120
  })]
121
121
  })
122
- }), re = () => /* @__PURE__ */ w("div", {
122
+ }), ne = () => /* @__PURE__ */ w("div", {
123
123
  className: "oidc-serviceworker",
124
124
  children: /* @__PURE__ */ T("div", {
125
125
  className: "oidc-serviceworker__container",
@@ -131,7 +131,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
131
131
  children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
132
132
  })]
133
133
  })
134
- }), z = () => /* @__PURE__ */ w("div", {
134
+ }), re = () => /* @__PURE__ */ w("div", {
135
135
  className: "oidc-session-lost",
136
136
  children: /* @__PURE__ */ T("div", {
137
137
  className: "oidc-session-lost__container",
@@ -143,15 +143,15 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
143
143
  children: "Your session has expired. Please re-authenticate."
144
144
  })]
145
145
  })
146
- }), B = ({ configurationName: e }) => (b(() => {
146
+ }), z = ({ configurationName: e }) => (b(() => {
147
147
  (async () => {
148
148
  t.getOrThrow(e).silentLoginCallbackAsync();
149
149
  })().catch((e) => {
150
150
  console.error("Error during silent login callback:", e);
151
151
  });
152
- }, [e]), null), V = ({ configurationName: e }) => {
152
+ }, [e]), null), B = ({ configurationName: e }) => {
153
153
  let n = p(window.location.href), r = t.getOrThrow, i = r(e), a = null;
154
- for (let [e, t] of Object.entries(n)) e !== "state" && e !== "scope" && (a === null && (a = {}), a[e] = t);
154
+ for (let [e, t] of Object.entries(n)) e !== "state" && e !== "scope" && (a ??= {}, a[e] = t);
155
155
  return b(() => {
156
156
  i.tokens || i.loginAsync(null, a, !0, n.scope);
157
157
  }, []), /* @__PURE__ */ w(C, {});
@@ -162,19 +162,14 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
162
162
  return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
163
163
  }, []);
164
164
  let f = m(n);
165
- if (r && u === m(r)) return /* @__PURE__ */ w(B, { configurationName: o });
166
- if (i && u === m(i)) return /* @__PURE__ */ w(V, { configurationName: o });
167
- switch (u) {
168
- case f: return /* @__PURE__ */ w(R, {
169
- callBackError: e,
170
- callBackSuccess: t,
171
- configurationName: o,
172
- withCustomHistory: s,
173
- navigateAfterCallback: c
174
- });
175
- default: return /* @__PURE__ */ w(C, { children: a });
176
- }
177
- }), H = {
165
+ return r && u === m(r) ? /* @__PURE__ */ w(z, { configurationName: o }) : i && u === m(i) ? /* @__PURE__ */ w(B, { configurationName: o }) : u === f ? /* @__PURE__ */ w(L, {
166
+ callBackError: e,
167
+ callBackSuccess: t,
168
+ configurationName: o,
169
+ withCustomHistory: s,
170
+ navigateAfterCallback: c
171
+ }) : /* @__PURE__ */ w(C, { children: a });
172
+ }), V = {
178
173
  name: "",
179
174
  data: null
180
175
  }, ae = ({ loadingComponent: e, children: n, configurationName: r }) => {
@@ -187,12 +182,12 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
187
182
  e = !1;
188
183
  };
189
184
  }, [r]), /* @__PURE__ */ w(C, { children: i ? /* @__PURE__ */ w(e, { configurationName: r }) : /* @__PURE__ */ w(C, { children: n }) });
190
- }, U = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ w(t, {
185
+ }, H = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ w(t, {
191
186
  configurationName: r,
192
187
  children: n
193
- }) : /* @__PURE__ */ w(C, { children: n }), oe = 3e4, W = (e) => e === t.eventNames.token_acquired || e === t.eventNames.token_renewed || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_error, G = ({ children: e, configuration: n, configurationName: r = "default", callbackSuccessComponent: i = F, authenticatingComponent: o = ee, loadingComponent: s = te, loadingTimeoutComponent: c = ne, serviceWorkerNotSupportedComponent: l = re, authenticatingErrorComponent: u = A, sessionLostComponent: d = z, onSessionLost: p = null, onLogoutFromAnotherTab: m = null, onLogoutFromSameTab: h = null, withCustomHistory: g = null, navigateAfterCallback: _ = null, onEvent: v = null, getFetch: y = null, location: x = null }) => {
188
+ }) : /* @__PURE__ */ w(C, { children: n }), oe = 3e4, se = (e) => e === t.eventNames.token_acquired || e === t.eventNames.token_renewed || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_error, U = ({ children: e, configuration: n, configurationName: r = "default", callbackSuccessComponent: i = P, authenticatingComponent: o = ee, loadingComponent: s = R, loadingTimeoutComponent: c = te, serviceWorkerNotSupportedComponent: l = ne, authenticatingErrorComponent: u = k, sessionLostComponent: d = re, onSessionLost: p = null, onLogoutFromAnotherTab: m = null, onLogoutFromSameTab: h = null, withCustomHistory: g = null, navigateAfterCallback: _ = null, onEvent: v = null, getFetch: y = null, location: x = null }) => {
194
189
  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");
195
- let C = (e = "default") => t.getOrCreate(y ?? f, x ?? new a())(n, e), [T, E] = S(H), [D, O] = S(!0), [k, j] = S(r);
190
+ let C = (e = "default") => t.getOrCreate(y ?? f, x ?? new a())(n, e), [T, E] = S(V), [D, O] = S(!0), [A, j] = S(r);
196
191
  b(() => {
197
192
  let e = C(r).subscribeEvents((e, t) => {
198
193
  v && v(r, e, t);
@@ -202,7 +197,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
202
197
  };
203
198
  }, [r, v]), b(() => {
204
199
  let e = C(r).subscribeEvents((e, r) => {
205
- if (e === t.eventNames.loginAsync_begin ? O(!0) : W(e) && O(!1), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
200
+ if (e === t.eventNames.loginAsync_begin ? O(!0) : se(e) && O(!1), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
206
201
  if (p != null) {
207
202
  p();
208
203
  return;
@@ -228,7 +223,7 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
228
223
  return queueMicrotask(() => {
229
224
  j(r);
230
225
  }), () => {
231
- C(r).removeEventSubscription(e), E(H), O(!0);
226
+ C(r).removeEventSubscription(e), E(V), O(!0);
232
227
  };
233
228
  }, [n, r]), b(() => {
234
229
  let e = n?.loading_timeout_ms ?? oe;
@@ -243,49 +238,49 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
243
238
  r,
244
239
  n
245
240
  ]);
246
- let M = d, N = o, P = s, I = c, L = l, R = u, B = k !== r, V = C(r);
241
+ let M = d, N = o, F = s, I = c, L = l, z = u, B = A !== r, U = C(r);
247
242
  switch (T.name) {
248
- case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ w(U, {
249
- loadingComponent: P,
243
+ case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ w(H, {
244
+ loadingComponent: F,
250
245
  isLoading: B,
251
246
  configurationName: r,
252
247
  children: /* @__PURE__ */ w(L, { configurationName: r })
253
248
  });
254
- case t.eventNames.loginAsync_begin: return /* @__PURE__ */ w(U, {
255
- loadingComponent: P,
249
+ case t.eventNames.loginAsync_begin: return /* @__PURE__ */ w(H, {
250
+ loadingComponent: F,
256
251
  isLoading: B,
257
252
  configurationName: r,
258
253
  children: /* @__PURE__ */ w(N, { configurationName: r })
259
254
  });
260
- case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ w(U, {
261
- loadingComponent: P,
255
+ case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ w(H, {
256
+ loadingComponent: F,
262
257
  isLoading: B,
263
258
  configurationName: r,
264
259
  children: /* @__PURE__ */ w(I, { configurationName: r })
265
260
  });
266
261
  case t.eventNames.loginAsync_error:
267
- case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ w(U, {
268
- loadingComponent: P,
262
+ case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ w(H, {
263
+ loadingComponent: F,
269
264
  isLoading: B,
270
265
  configurationName: r,
271
- children: /* @__PURE__ */ w(R, { configurationName: r })
266
+ children: /* @__PURE__ */ w(z, { configurationName: r })
272
267
  });
273
268
  case t.eventNames.refreshTokensAsync_error:
274
269
  case t.eventNames.syncTokensAsync_error:
275
- case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ w(U, {
276
- loadingComponent: P,
270
+ case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ w(H, {
271
+ loadingComponent: F,
277
272
  isLoading: B,
278
273
  configurationName: r,
279
274
  children: /* @__PURE__ */ w(M, { configurationName: r })
280
275
  });
281
- default: return /* @__PURE__ */ w(U, {
282
- loadingComponent: P,
276
+ default: return /* @__PURE__ */ w(H, {
277
+ loadingComponent: F,
283
278
  isLoading: B,
284
279
  configurationName: r,
285
280
  children: /* @__PURE__ */ w(ie, {
286
- redirect_uri: V.configuration.redirect_uri,
287
- silent_redirect_uri: V.configuration.silent_redirect_uri,
288
- silent_login_uri: V.configuration.silent_login_uri,
281
+ redirect_uri: U.configuration.redirect_uri,
282
+ silent_redirect_uri: U.configuration.silent_redirect_uri,
283
+ silent_login_uri: U.configuration.silent_login_uri,
289
284
  callbackSuccessComponent: i,
290
285
  callbackErrorComponent: u,
291
286
  authenticatingComponent: o,
@@ -294,14 +289,14 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
294
289
  navigateAfterCallback: _,
295
290
  location: x ?? new a(),
296
291
  children: /* @__PURE__ */ w(ae, {
297
- loadingComponent: P,
292
+ loadingComponent: F,
298
293
  configurationName: r,
299
294
  children: e
300
295
  })
301
296
  })
302
297
  });
303
298
  }
304
- }, K = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
299
+ }, W = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
305
300
  let a = t.getOrThrow, o = a(i);
306
301
  return b(() => {
307
302
  !o.tokens && !o.isLoggingOut && o.loginAsync(n, r);
@@ -310,26 +305,26 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
310
305
  n,
311
306
  r
312
307
  ]), o.tokens ? /* @__PURE__ */ w(C, { children: e }) : null;
313
- }, se = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ w(K, {
308
+ }, G = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ w(W, {
314
309
  callbackPath: t,
315
310
  extras: n,
316
311
  configurationName: r,
317
312
  children: /* @__PURE__ */ w(e, { ...i })
318
- }), q = /* @__PURE__ */ new Set(), J = (e) => {
319
- q.has(e) || (q.add(e), console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`));
320
- }, Y = "default", X = (e, t) => {
321
- let n = !1, r = e(t);
322
- return r && (n = r.tokens != null), n;
323
- }, ce = (e = Y) => {
324
- let n = t.get, [r, i] = S(() => X(n, e));
313
+ }), K = /* @__PURE__ */ new Set(), q = (e) => {
314
+ K.has(e) || (K.add(e), console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`));
315
+ }, J = "default", Y = (e, t) => {
316
+ let n = e(t);
317
+ return n ? n.tokens != null : !1;
318
+ }, X = (e) => 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, ce = (e = J) => {
319
+ let n = t.get, [r, i] = S(() => Y(n, e));
325
320
  return b(() => {
326
321
  let r = !0, a = n(e);
327
322
  if (!a) {
328
- J(e);
323
+ q(e);
329
324
  return;
330
325
  }
331
326
  let o = a.subscribeEvents((a, o) => {
332
- (a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(X(n, e));
327
+ (a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(Y(n, e));
333
328
  });
334
329
  return () => {
335
330
  r = !1, a.removeEventSubscription(o);
@@ -337,15 +332,15 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
337
332
  }, [e]), {
338
333
  login: (t = void 0, r = void 0, i = !1, a = void 0) => {
339
334
  let o = n(e);
340
- return o ? o.loginAsync(t, r, !1, a, i) : (J(e), Promise.resolve());
335
+ return o ? o.loginAsync(t, r, !1, a, i) : (q(e), Promise.resolve());
341
336
  },
342
337
  logout: (t = void 0, r = void 0) => {
343
338
  let i = n(e);
344
- return i ? i.logoutAsync(t, r) : (J(e), Promise.resolve());
339
+ return i ? i.logoutAsync(t, r) : (q(e), Promise.resolve());
345
340
  },
346
341
  renewTokens: async (t = void 0) => {
347
342
  let r = n(e);
348
- if (!r) return J(e), {
343
+ if (!r) return q(e), {
349
344
  accessToken: null,
350
345
  accessTokenPayload: null,
351
346
  idToken: null,
@@ -380,26 +375,26 @@ var E = "default", D = (e, t, n = !1) => async (...r) => await t().fetchWithToke
380
375
  function le(e, t) {
381
376
  return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
382
377
  }
383
- var ue = (e = Y) => {
378
+ var ue = (e = J) => {
384
379
  let n = t.get, [r, i] = S(() => Q(e));
385
380
  return b(() => {
386
- let r = !0, a = n(e);
387
- if (!a) {
388
- J(e);
381
+ let t = !0, r = n(e);
382
+ if (!r) {
383
+ q(e);
389
384
  return;
390
385
  }
391
- let o = a.subscribeEvents((e, n) => {
392
- 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) {
393
- let e = a.tokens;
386
+ let a = r.subscribeEvents((e, n) => {
387
+ if (X(e) && t) {
388
+ let e = r.tokens;
394
389
  i(e == null ? Z : {
395
390
  accessToken: e.accessToken,
396
391
  accessTokenPayload: e.accessTokenPayload,
397
- generateDemonstrationOfProofOfPossessionAsync: le(a, e)
392
+ generateDemonstrationOfProofOfPossessionAsync: le(r, e)
398
393
  });
399
394
  }
400
395
  });
401
396
  return () => {
402
- r = !1, a.removeEventSubscription(o);
397
+ t = !1, r.removeEventSubscription(a);
403
398
  };
404
399
  }, [e]), r;
405
400
  }, $ = {
@@ -416,17 +411,17 @@ var ue = (e = Y) => {
416
411
  };
417
412
  }
418
413
  return $;
419
- }, fe = (e = Y) => {
414
+ }, fe = (e = J) => {
420
415
  let n = t.get, [r, i] = S(() => de(e));
421
416
  return b(() => {
422
- let r = !0, a = n(e);
423
- if (!a) {
424
- J(e);
417
+ let t = !0, r = n(e);
418
+ if (!r) {
419
+ q(e);
425
420
  return;
426
421
  }
427
- let o = a.subscribeEvents((e, n) => {
428
- 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) {
429
- let e = a.tokens;
422
+ let a = r.subscribeEvents((e, n) => {
423
+ if (X(e) && t) {
424
+ let e = r.tokens;
430
425
  i(e == null ? $ : {
431
426
  idToken: e.idToken,
432
427
  idTokenPayload: e.idTokenPayload
@@ -434,7 +429,7 @@ var ue = (e = Y) => {
434
429
  }
435
430
  });
436
431
  return () => {
437
- r = !1, a.removeEventSubscription(o);
432
+ t = !1, r.removeEventSubscription(a);
438
433
  };
439
434
  }, [e]), r;
440
435
  }, pe = /* @__PURE__ */ function(e) {
@@ -447,7 +442,7 @@ var ue = (e = Y) => {
447
442
  return b(() => {
448
443
  let r = t.get(e), i = !0;
449
444
  if (!r) {
450
- J(e);
445
+ q(e);
451
446
  return;
452
447
  }
453
448
  if (r.tokens) {
@@ -495,4 +490,4 @@ var ue = (e = Y) => {
495
490
  };
496
491
  };
497
492
  //#endregion
498
- export { e as OidcClient, n as OidcError, r as OidcErrorCode, i as OidcLocation, G as OidcProvider, K as OidcSecure, o as OidcStateError, s as OidcStateErrorCode, pe as OidcUserStatus, c as PushedAuthorizationRequestError, l as PushedAuthorizationRequestErrorCode, u as TokenAutomaticRenewMode, d as TokenRenewMode, h as isOidcError, g as isOidcStateError, _ as isPushedAuthorizationRequestError, ce as useOidc, ue as useOidcAccessToken, k as useOidcFetch, fe as useOidcIdToken, me as useOidcUser, O as withOidcFetch, se as withOidcSecure };
493
+ export { e as OidcClient, n as OidcError, r as OidcErrorCode, i as OidcLocation, U as OidcProvider, W as OidcSecure, o as OidcStateError, s as OidcStateErrorCode, pe as OidcUserStatus, c as PushedAuthorizationRequestError, l as PushedAuthorizationRequestErrorCode, u as TokenAutomaticRenewMode, d as TokenRenewMode, h as isOidcError, g as isOidcStateError, _ as isPushedAuthorizationRequestError, ce as useOidc, ue as useOidcAccessToken, O as useOidcFetch, fe as useOidcIdToken, me as useOidcUser, D as withOidcFetch, G as withOidcSecure };
@@ -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||!l.call(e,`default`)?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.getOrThrow;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.getOrThrow;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.getOrThrow(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.getOrThrow,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=window?(0,t.getPath)(window.location.href):``,[p,m]=(0,n.useState)(f);(0,n.useEffect)(()=>{let e=()=>m((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let h=(0,t.getPath)(a);if(o&&p===(0,t.getPath)(o))return(0,r.jsx)(k,{configurationName:l});if(s&&p===(0,t.getPath)(s))return(0,r.jsx)(A,{configurationName:l});switch(p){case h: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=e=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_error,L=({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),[L,R]=(0,n.useState)(!0),[z,B]=(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.loginAsync_begin?R(!0):I(e)&&R(!1),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(()=>{B(a)}),()=>{w(a).removeEventSubscription(e),A(M),R(!0)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||!L||w(a)?.tokens!=null||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,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{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:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.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:U,configurationName:a,children:e})})})}},R=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=new Set,V=e=>{B.has(e)||(B.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},H=`default`,U=(e,t)=>{let n=!1,r=e(t);return r&&(n=r.tokens!=null),n},W=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let 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(U(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(V(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(V(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return V(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;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 G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let 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?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let 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?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Q=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,"OidcError",{enumerable:!0,get:function(){return t.OidcError}}),Object.defineProperty(e,"OidcErrorCode",{enumerable:!0,get:function(){return t.OidcErrorCode}}),Object.defineProperty(e,"OidcLocation",{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=L,e.OidcSecure=R,Object.defineProperty(e,"OidcStateError",{enumerable:!0,get:function(){return t.OidcStateError}}),Object.defineProperty(e,"OidcStateErrorCode",{enumerable:!0,get:function(){return t.OidcStateErrorCode}}),e.OidcUserStatus=Q,Object.defineProperty(e,"PushedAuthorizationRequestError",{enumerable:!0,get:function(){return t.PushedAuthorizationRequestError}}),Object.defineProperty(e,"PushedAuthorizationRequestErrorCode",{enumerable:!0,get:function(){return t.PushedAuthorizationRequestErrorCode}}),Object.defineProperty(e,"TokenAutomaticRenewMode",{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,"TokenRenewMode",{enumerable:!0,get:function(){return t.TokenRenewMode}}),Object.defineProperty(e,"isOidcError",{enumerable:!0,get:function(){return t.isOidcError}}),Object.defineProperty(e,"isOidcStateError",{enumerable:!0,get:function(){return t.isOidcStateError}}),Object.defineProperty(e,"isPushedAuthorizationRequestError",{enumerable:!0,get:function(){return t.isPushedAuthorizationRequestError}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=m,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){V(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=p,e.withOidcSecure=z});
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||!l.call(e,`default`)?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=p(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},p=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.getOrThrow;return{fetch:(0,n.useCallback)(async(e,t)=>await o(r).fetchWithTokens(a,i)(e,t),[a,r,i])}},m=()=>(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.`})]})}),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:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),g=()=>Math.random().toString(36).slice(2,8),_=(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},v=(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`))}}),y=()=>v(window,_(window,document),g),b=()=>(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.`})]})}),x=200,S=(e,t=window)=>t.location.pathname===e||e===`/`,C=({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.getOrThrow;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():y()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},x)}),e&&(S(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||m,d=i||b;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},w=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),T=()=>(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.`})]})}),E=()=>(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.`})]})}),D=()=>(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.`})]})}),O=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.getOrThrow(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),k=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.getOrThrow,o=a(e),s=null;for(let[e,t]of Object.entries(i))e!==`state`&&e!==`scope`&&(s??={},s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},A=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=window?(0,t.getPath)(window.location.href):``,[p,m]=(0,n.useState)(f);(0,n.useEffect)(()=>{let e=()=>m((0,t.getPath)(window.location.href));return e(),window.addEventListener(`popstate`,e,!1),()=>window.removeEventListener(`popstate`,e,!1)},[]);let h=(0,t.getPath)(a);return o&&p===(0,t.getPath)(o)?(0,r.jsx)(O,{configurationName:l}):s&&p===(0,t.getPath)(s)?(0,r.jsx)(k,{configurationName:l}):p===h?(0,r.jsx)(C,{callBackError:e,callBackSuccess:i,configurationName:l,withCustomHistory:u,navigateAfterCallback:d}):(0,r.jsx)(r.Fragment,{children:c})}),j={name:``,data:null},M=({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})})},N=({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})},P=3e4,F=e=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_error,I=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=b,authenticatingComponent:s=h,loadingComponent:c=w,loadingTimeoutComponent:l=T,serviceWorkerNotSupportedComponent:u=E,authenticatingErrorComponent:d=m,sessionLostComponent:f=D,onSessionLost:p=null,onLogoutFromAnotherTab:g=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:x=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 O=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,I]=(0,n.useState)(j),[L,R]=(0,n.useState)(!0),[z,B]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=O(a).subscribeEvents((e,t)=>{x&&x(a,e,t)});return()=>{O(a).removeEventSubscription(e)}},[a,x]),(0,n.useEffect)(()=>{let e=O(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.loginAsync_begin?R(!0):F(e)&&R(!1),e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}I({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(g!=null){g();return}I({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)&&I({name:e,data:n})});return queueMicrotask(()=>{B(a)}),()=>{O(a).removeEventSubscription(e),I(j),R(!0)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??P;if(e<=0||!L||O(a)?.tokens!=null||k.name!==``&&k.name!==t.OidcClient.eventNames.loginAsync_begin)return;let n=setTimeout(()=>{O(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=O(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{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)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(N,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(A,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.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)(M,{loadingComponent:U,configurationName:a,children:e})})})}},L=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&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=new Set,B=e=>{z.has(e)||(z.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},V=`default`,H=(e,t)=>{let n=e(t);return n?n.tokens!=null:!1},U=e=>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,W=(e=V)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>H(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){B(e);return}let 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(H(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(B(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(B(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return B(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;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 G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=V)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let t=!0,n=r(e);if(!n){B(e);return}let i=n.subscribeEvents((e,r)=>{if(U(e)&&t){let e=n.tokens;a(e==null?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(n,e)})}});return()=>{t=!1,n.removeEventSubscription(i)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=V)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let t=!0,n=r(e);if(!n){B(e);return}let i=n.subscribeEvents((e,r)=>{if(U(e)&&t){let e=n.tokens;a(e==null?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{t=!1,n.removeEventSubscription(i)}},[e]),i},Q=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,"OidcError",{enumerable:!0,get:function(){return t.OidcError}}),Object.defineProperty(e,"OidcErrorCode",{enumerable:!0,get:function(){return t.OidcErrorCode}}),Object.defineProperty(e,"OidcLocation",{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=I,e.OidcSecure=L,Object.defineProperty(e,"OidcStateError",{enumerable:!0,get:function(){return t.OidcStateError}}),Object.defineProperty(e,"OidcStateErrorCode",{enumerable:!0,get:function(){return t.OidcStateErrorCode}}),e.OidcUserStatus=Q,Object.defineProperty(e,"PushedAuthorizationRequestError",{enumerable:!0,get:function(){return t.PushedAuthorizationRequestError}}),Object.defineProperty(e,"PushedAuthorizationRequestErrorCode",{enumerable:!0,get:function(){return t.PushedAuthorizationRequestErrorCode}}),Object.defineProperty(e,"TokenAutomaticRenewMode",{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,"TokenRenewMode",{enumerable:!0,get:function(){return t.TokenRenewMode}}),Object.defineProperty(e,"isOidcError",{enumerable:!0,get:function(){return t.isOidcError}}),Object.defineProperty(e,"isOidcStateError",{enumerable:!0,get:function(){return t.isOidcStateError}}),Object.defineProperty(e,"isPushedAuthorizationRequestError",{enumerable:!0,get:function(){return t.isPushedAuthorizationRequestError}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=p,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){B(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=f,e.withOidcSecure=R});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.29.4",
3
+ "version": "7.29.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -39,8 +39,8 @@
39
39
  "lint": "eslint src"
40
40
  },
41
41
  "dependencies": {
42
- "@axa-fr/oidc-client": "7.29.4",
43
- "@axa-fr/oidc-client-service-worker": "7.29.4"
42
+ "@axa-fr/oidc-client": "7.29.5",
43
+ "@axa-fr/oidc-client-service-worker": "7.29.5"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"