@axa-fr/react-oidc 7.26.0 → 7.26.3

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":"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,CA6KjE,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,CAgLjE,CAAC;AAEF,eAAe,YAAY,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;AAkBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;2BA6BlD,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM;4BAWC,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS;2BAKrB,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAe1C,CAAC;AAsBF,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,oBA6C9E,CAAC;AAeF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0BAA4C,gBAqC1E,CAAC"}
1
+ {"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO,GAAI,0BAA4C;2BA4BlD,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM;4BAWC,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS;2BAKrB,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAe1C,CAAC;AAsBF,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,oBAsC9E,CAAC;AAeF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,0BAA4C,gBAiC1E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../src/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGpE,oBAAY,cAAc;IACxB,eAAe,oBAAoB;IACnC,OAAO,iBAAiB;IACxB,MAAM,gBAAgB;IACtB,YAAY,uBAAuB;CACpC;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAC5D,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,YAAY,GAAG,YAAY,EAC/D,0BAA6B,EAC7B,2CAAyC;;;;CAsD1C,CAAC"}
1
+ {"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../src/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGpE,oBAAY,cAAc;IACxB,eAAe,oBAAoB;IACnC,OAAO,iBAAiB;IACxB,MAAM,gBAAgB;IACtB,YAAY,uBAAuB;CACpC;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAC5D,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,YAAY,GAAG,YAAY,EAC/D,0BAA6B,EAC7B,2CAAyC;;;;CA+D1C,CAAC"}
package/dist/index.js CHANGED
@@ -1,89 +1,89 @@
1
- import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime";
2
- import { OidcClient as r, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
3
- import { OidcClient as Me, OidcLocation as De, TokenAutomaticRenewMode as xe, TokenRenewMode as We } from "@axa-fr/oidc-client";
4
- import Z, { useCallback as ee, useState as v, useEffect as f } from "react";
5
- const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithTokens(t, e)(...s), Oe = (t = null, n = x, e = !1) => (s) => (o) => {
6
- const { fetch: c } = ne(
1
+ import { jsx as i, jsxs as S, Fragment as m } from "react/jsx-runtime";
2
+ import { OidcClient as c, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
3
+ import { OidcClient as Fe, OidcLocation as qe, TokenAutomaticRenewMode as De, TokenRenewMode as xe } from "@axa-fr/oidc-client";
4
+ import Z, { useCallback as ee, useState as f, useEffect as p } from "react";
5
+ const D = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithTokens(t, e)(...s), Oe = (t = null, n = D, e = !1) => (s) => (o) => {
6
+ const { fetch: r } = ne(
7
7
  t || o.fetch,
8
8
  n,
9
9
  e
10
10
  );
11
- return /* @__PURE__ */ i(s, { ...o, fetch: c });
12
- }, ne = (t = null, n = x, e = !1) => {
13
- const s = t || window.fetch, o = r.get;
11
+ return /* @__PURE__ */ i(s, { ...o, fetch: r });
12
+ }, ne = (t = null, n = D, e = !1) => {
13
+ const s = t || window.fetch, o = c.get;
14
14
  return { fetch: ee(
15
- (l, a) => te(
15
+ (a, l) => te(
16
16
  s,
17
17
  () => o(n),
18
18
  e
19
- )(l, a),
20
- [s, n]
19
+ )(a, l),
20
+ [s, n, e]
21
21
  ) };
22
- }, W = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
22
+ }, x = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ S("div", { className: "oidc-authenticating__container", children: [
23
23
  /* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Error authentication" }),
24
24
  /* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "An error occurred during authentication." })
25
- ] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
25
+ ] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ S("div", { className: "oidc-authenticating__container", children: [
26
26
  /* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Authentication in progress" }),
27
27
  /* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "You will be redirected to the login page." })
28
28
  ] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t, n) => (e, s) => {
29
29
  if (typeof t.CustomEvent == "function")
30
30
  return new t.CustomEvent(e, s);
31
- const o = s || { bubbles: !1, cancelable: !1, detail: void 0 }, c = n.createEvent("CustomEvent");
32
- return c.initCustomEvent(
31
+ const o = s || { bubbles: !1, cancelable: !1, detail: void 0 }, r = n.createEvent("CustomEvent");
32
+ return r.initCustomEvent(
33
33
  e,
34
34
  o.bubbles,
35
35
  o.cancelable,
36
36
  o.detail
37
- ), c.prototype = t.Event.prototype, c;
37
+ ), r.prototype = t.Event.prototype, r;
38
38
  }, re = (t, n, e) => ({
39
39
  replaceState: (s, o) => {
40
- const c = e(), l = o || t.history.state;
41
- t.history.replaceState({ key: c, state: l }, null, s), t.dispatchEvent(n("popstate"));
40
+ const r = e(), a = o || t.history.state;
41
+ t.history.replaceState({ key: r, state: a }, null, s), t.dispatchEvent(n("popstate"));
42
42
  }
43
- }), ie = () => re(window, ce(window, document), oe), R = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ E("div", { className: "oidc-callback__container", children: [
43
+ }), ie = () => re(window, ce(window, document), oe), W = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ S("div", { className: "oidc-callback__container", children: [
44
44
  /* @__PURE__ */ i("h1", { className: "oidc-callback__title", children: "Authentication complete" }),
45
45
  /* @__PURE__ */ i("p", { className: "oidc-callback__content", children: "You will be redirected to your application." })
46
- ] }) }), ae = ({
46
+ ] }) }), le = ({
47
47
  callBackError: t,
48
48
  callBackSuccess: n,
49
49
  configurationName: e,
50
50
  withCustomHistory: s
51
51
  }) => {
52
- const [o, c] = v(!1);
53
- f(() => {
52
+ const [o, r] = f(!1);
53
+ p(() => {
54
54
  let d = !0;
55
55
  return (async () => {
56
- const _ = r.get;
56
+ const _ = c.get;
57
57
  try {
58
- const { callbackPath: h } = await _(e).loginCallbackAsync();
59
- (s ? s() : ie()).replaceState(h || "/");
60
- } catch (h) {
61
- d && (console.warn(h), c(!0));
58
+ const { callbackPath: k } = await _(e).loginCallbackAsync();
59
+ (s ? s() : ie()).replaceState(k || "/");
60
+ } catch (k) {
61
+ d && (console.warn(k), r(!0));
62
62
  }
63
63
  })(), () => {
64
64
  d = !1;
65
65
  };
66
66
  }, []);
67
- const l = t || W, a = n || R;
68
- return o ? /* @__PURE__ */ i(l, { configurationName: e }) : /* @__PURE__ */ i(a, { configurationName: e });
69
- }, le = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), de = () => /* @__PURE__ */ i("div", { className: "oidc-serviceworker", children: /* @__PURE__ */ E("div", { className: "oidc-serviceworker__container", children: [
67
+ const a = t || x, l = n || W;
68
+ return o ? /* @__PURE__ */ i(a, { configurationName: e }) : /* @__PURE__ */ i(l, { configurationName: e });
69
+ }, ae = () => /* @__PURE__ */ i("span", { className: "oidc-loading", children: "Loading" }), de = () => /* @__PURE__ */ i("div", { className: "oidc-serviceworker", children: /* @__PURE__ */ S("div", { className: "oidc-serviceworker__container", children: [
70
70
  /* @__PURE__ */ i("h1", { className: "oidc-serviceworker__title", children: "Unable to authenticate on this browser" }),
71
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
- ] }) }), ue = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */ E("div", { className: "oidc-session-lost__container", children: [
72
+ ] }) }), ue = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */ S("div", { className: "oidc-session-lost__container", children: [
73
73
  /* @__PURE__ */ i("h1", { className: "oidc-session-lost__title", children: "Session timed out" }),
74
74
  /* @__PURE__ */ i("p", { className: "oidc-session-lost__content", children: "Your session has expired. Please re-authenticate." })
75
- ] }) }), ke = ({ configurationName: t }) => (f(() => {
75
+ ] }) }), he = ({ configurationName: t }) => (p(() => {
76
76
  (async () => {
77
- r.get(t).silentLoginCallbackAsync();
77
+ c.get(t).silentLoginCallbackAsync();
78
78
  })().catch((e) => {
79
79
  console.error("Error during silent login callback:", e);
80
80
  });
81
- }, [t]), null), he = ({ configurationName: t }) => {
82
- const n = V(window.location.href), e = r.get, s = e(t);
81
+ }, [t]), null), ke = ({ configurationName: t }) => {
82
+ const n = V(window.location.href), e = c.get, s = e(t);
83
83
  let o = null;
84
- for (const [c, l] of Object.entries(n))
85
- c === "state" || c === "scope" || (o === null && (o = {}), o[c] = l);
86
- return f(() => {
84
+ for (const [r, a] of Object.entries(n))
85
+ r === "state" || r === "scope" || (o === null && (o = {}), o[r] = a);
86
+ return p(() => {
87
87
  s.tokens || s.loginAsync(null, o, !0, n.scope);
88
88
  }, []), /* @__PURE__ */ i(m, {});
89
89
  }, _e = ({
@@ -92,142 +92,135 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
92
92
  redirect_uri: e,
93
93
  silent_redirect_uri: s,
94
94
  silent_login_uri: o,
95
- children: c,
96
- configurationName: l,
97
- withCustomHistory: a = null
95
+ children: r,
96
+ configurationName: a,
97
+ withCustomHistory: l = null
98
98
  }) => {
99
- const d = window ? O(window.location.href) : "", [u, _] = v(d);
100
- f(() => {
101
- const p = () => _(O(window.location.href));
102
- return p(), window.addEventListener("popstate", p, !1), () => window.removeEventListener("popstate", p, !1);
99
+ const d = window ? O(window.location.href) : "", [u, _] = f(d);
100
+ p(() => {
101
+ const v = () => _(O(window.location.href));
102
+ return v(), window.addEventListener("popstate", v, !1), () => window.removeEventListener("popstate", v, !1);
103
103
  }, []);
104
- const h = O(e);
105
- if (s && u === O(s))
106
- return /* @__PURE__ */ i(ke, { configurationName: l });
107
- if (o && u === O(o))
108
- return /* @__PURE__ */ i(he, { configurationName: l });
109
- switch (u) {
110
- case h:
111
- return /* @__PURE__ */ i(
112
- ae,
113
- {
114
- callBackError: t,
115
- callBackSuccess: n,
116
- configurationName: l,
117
- withCustomHistory: a
118
- }
119
- );
120
- default:
121
- return /* @__PURE__ */ i(m, { children: c });
122
- }
123
- }, ve = Z.memo(_e), D = { name: "", data: null }, fe = ({
104
+ const k = O(e);
105
+ return s && u === O(s) ? /* @__PURE__ */ i(he, { configurationName: a }) : o && u === O(o) ? /* @__PURE__ */ i(ke, { configurationName: a }) : u === k ? /* @__PURE__ */ i(
106
+ le,
107
+ {
108
+ callBackError: t,
109
+ callBackSuccess: n,
110
+ configurationName: a,
111
+ withCustomHistory: l
112
+ }
113
+ ) : /* @__PURE__ */ i(m, { children: r });
114
+ }, ve = Z.memo(_e), F = { name: "", data: null }, fe = ({
124
115
  loadingComponent: t,
125
116
  children: n,
126
117
  configurationName: e
127
118
  }) => {
128
- const [s, o] = v(!0), c = r.get, l = c(e);
129
- return f(() => {
119
+ const [s, o] = f(!0), r = c.get, a = r(e);
120
+ return p(() => {
130
121
  let d = !0;
131
- return l && l.tryKeepExistingSessionAsync().then(() => {
122
+ return a && a.tryKeepExistingSessionAsync().then(() => {
132
123
  d && o(!1);
133
124
  }), () => {
134
125
  d = !1;
135
126
  };
136
127
  }, [e]), /* @__PURE__ */ i(m, { children: s ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: n }) });
137
- }, P = ({ isLoading: t, loadingComponent: n, children: e, configurationName: s }) => {
128
+ }, E = ({ isLoading: t, loadingComponent: n, children: e, configurationName: s }) => {
138
129
  const o = n;
139
130
  return t ? /* @__PURE__ */ i(o, { configurationName: s, children: e }) : /* @__PURE__ */ i(m, { children: e });
140
- }, Pe = ({
131
+ }, Ee = ({
141
132
  children: t,
142
133
  configuration: n,
143
134
  configurationName: e = "default",
144
- callbackSuccessComponent: s = R,
135
+ callbackSuccessComponent: s = W,
145
136
  authenticatingComponent: o = se,
146
- loadingComponent: c = le,
147
- serviceWorkerNotSupportedComponent: l = de,
148
- authenticatingErrorComponent: a = W,
137
+ loadingComponent: r = ae,
138
+ serviceWorkerNotSupportedComponent: a = de,
139
+ authenticatingErrorComponent: l = x,
149
140
  sessionLostComponent: d = ue,
150
141
  onSessionLost: u = null,
151
142
  onLogoutFromAnotherTab: _ = null,
152
- onLogoutFromSameTab: h = null,
153
- withCustomHistory: p = null,
154
- onEvent: T = null,
143
+ onLogoutFromSameTab: k = null,
144
+ withCustomHistory: v = null,
145
+ onEvent: w = null,
155
146
  getFetch: y = null,
156
- location: S = null
147
+ location: P = null
157
148
  }) => {
158
149
  if (n && n.redirect_uri && n.silent_redirect_uri && n.redirect_uri === n.silent_redirect_uri)
159
150
  throw new Error("redirect_uri and silent_redirect_uri must be different");
160
- const w = (L = "default") => r.getOrCreate(y ?? X, S ?? new M())(
151
+ const T = (L = "default") => c.getOrCreate(y ?? X, P ?? new M())(
161
152
  n,
162
153
  L
163
- ), [j, B] = v(!0), [z, C] = v(D), [K, $] = v("default");
164
- f(() => {
165
- const I = w(e).subscribeEvents((k, b) => {
166
- T && T(e, k, b);
154
+ ), [j, B] = f(!0), [z, C] = f(F), [K, $] = f(e);
155
+ p(() => {
156
+ const I = T(e).subscribeEvents((h, g) => {
157
+ w && w(e, h, g);
167
158
  });
168
159
  return () => {
169
- w(e).removeEventSubscription(I);
160
+ T(e).removeEventSubscription(I);
170
161
  };
171
- }, [e, T]), f(() => {
172
- const I = w(e).subscribeEvents((k, b) => {
173
- if (k === r.eventNames.refreshTokensAsync_error || k === r.eventNames.syncTokensAsync_error) {
162
+ }, [e, w]), p(() => {
163
+ const I = T(e).subscribeEvents((h, g) => {
164
+ if (h === c.eventNames.refreshTokensAsync_error || h === c.eventNames.syncTokensAsync_error) {
174
165
  if (u != null) {
175
166
  u();
176
167
  return;
177
168
  }
178
- C({ name: k, data: b });
179
- } else if (k === r.eventNames.logout_from_another_tab) {
169
+ C({ name: h, data: g });
170
+ } else if (h === c.eventNames.logout_from_another_tab) {
180
171
  if (_ != null) {
181
172
  _();
182
173
  return;
183
174
  }
184
- C({ name: k, data: b });
185
- } else k === r.eventNames.logout_from_same_tab ? h != null && h() : k === r.eventNames.loginAsync_begin || k === r.eventNames.loginCallbackAsync_end || k === r.eventNames.loginAsync_error || k === r.eventNames.loginCallbackAsync_error ? C({ name: k, data: b }) : k === r.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0 && C({ name: k, data: b });
175
+ C({ name: h, data: g });
176
+ } else h === c.eventNames.logout_from_same_tab ? k?.() : h === c.eventNames.loginAsync_begin || h === c.eventNames.loginCallbackAsync_end || h === c.eventNames.loginAsync_error || h === c.eventNames.loginCallbackAsync_error ? C({ name: h, data: g }) : h === c.eventNames.service_worker_not_supported_by_browser && n.service_worker_only === !0 && C({ name: h, data: g });
186
177
  });
187
- return $(e), B(!1), () => {
188
- w(e).removeEventSubscription(I), C(D);
178
+ return queueMicrotask(() => {
179
+ $(e), B(!1);
180
+ }), () => {
181
+ T(e).removeEventSubscription(I), C(F);
189
182
  };
190
183
  }, [n, e]);
191
- const G = d, H = o, g = c, Q = l, J = a, A = j || K !== e, N = w(e);
184
+ const G = d, H = o, b = r, Q = a, J = l, A = j || K !== e, N = T(e);
192
185
  switch (z.name) {
193
- case r.eventNames.service_worker_not_supported_by_browser:
186
+ case c.eventNames.service_worker_not_supported_by_browser:
194
187
  return /* @__PURE__ */ i(
195
- P,
188
+ E,
196
189
  {
197
- loadingComponent: g,
190
+ loadingComponent: b,
198
191
  isLoading: A,
199
192
  configurationName: e,
200
193
  children: /* @__PURE__ */ i(Q, { configurationName: e })
201
194
  }
202
195
  );
203
- case r.eventNames.loginAsync_begin:
196
+ case c.eventNames.loginAsync_begin:
204
197
  return /* @__PURE__ */ i(
205
- P,
198
+ E,
206
199
  {
207
- loadingComponent: g,
200
+ loadingComponent: b,
208
201
  isLoading: A,
209
202
  configurationName: e,
210
203
  children: /* @__PURE__ */ i(H, { configurationName: e })
211
204
  }
212
205
  );
213
- case r.eventNames.loginAsync_error:
214
- case r.eventNames.loginCallbackAsync_error:
206
+ case c.eventNames.loginAsync_error:
207
+ case c.eventNames.loginCallbackAsync_error:
215
208
  return /* @__PURE__ */ i(
216
- P,
209
+ E,
217
210
  {
218
- loadingComponent: g,
211
+ loadingComponent: b,
219
212
  isLoading: A,
220
213
  configurationName: e,
221
214
  children: /* @__PURE__ */ i(J, { configurationName: e })
222
215
  }
223
216
  );
224
- case r.eventNames.refreshTokensAsync_error:
225
- case r.eventNames.syncTokensAsync_error:
226
- case r.eventNames.logout_from_another_tab:
217
+ case c.eventNames.refreshTokensAsync_error:
218
+ case c.eventNames.syncTokensAsync_error:
219
+ case c.eventNames.logout_from_another_tab:
227
220
  return /* @__PURE__ */ i(
228
- P,
221
+ E,
229
222
  {
230
- loadingComponent: g,
223
+ loadingComponent: b,
231
224
  isLoading: A,
232
225
  configurationName: e,
233
226
  children: /* @__PURE__ */ i(G, { configurationName: e })
@@ -235,9 +228,9 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
235
228
  );
236
229
  default:
237
230
  return /* @__PURE__ */ i(
238
- P,
231
+ E,
239
232
  {
240
- loadingComponent: g,
233
+ loadingComponent: b,
241
234
  isLoading: A,
242
235
  configurationName: e,
243
236
  children: /* @__PURE__ */ i(
@@ -247,12 +240,12 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
247
240
  silent_redirect_uri: N.configuration.silent_redirect_uri,
248
241
  silent_login_uri: N.configuration.silent_login_uri,
249
242
  callbackSuccessComponent: s,
250
- callbackErrorComponent: a,
243
+ callbackErrorComponent: l,
251
244
  authenticatingComponent: o,
252
245
  configurationName: e,
253
- withCustomHistory: p,
254
- location: S ?? new M(),
255
- children: /* @__PURE__ */ i(fe, { loadingComponent: g, configurationName: e, children: t })
246
+ withCustomHistory: v,
247
+ location: P ?? new M(),
248
+ children: /* @__PURE__ */ i(fe, { loadingComponent: b, configurationName: e, children: t })
256
249
  }
257
250
  )
258
251
  }
@@ -264,35 +257,33 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
264
257
  extras: e = null,
265
258
  configurationName: s = "default"
266
259
  }) => {
267
- const o = r.get, c = o(s);
268
- return f(() => {
269
- c.tokens || c.loginAsync(n, e);
270
- }, [s, n, e]), c.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
271
- }, Ee = (t, n = null, e = null, s = "default") => (o) => /* @__PURE__ */ i(pe, { callbackPath: n, extras: e, configurationName: s, children: /* @__PURE__ */ i(t, { ...o }) }), F = "default", U = (t, n) => {
260
+ const o = c.get, r = o(s);
261
+ return p(() => {
262
+ r.tokens || r.loginAsync(n, e);
263
+ }, [s, n, e]), r.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
264
+ }, Se = (t, n = null, e = null, s = "default") => (o) => /* @__PURE__ */ i(pe, { callbackPath: n, extras: e, configurationName: s, children: /* @__PURE__ */ i(t, { ...o }) }), U = "default", q = (t, n) => {
272
265
  let e = !1;
273
266
  return t(n) && (e = t(n).tokens != null), e;
274
- }, Se = (t = F) => {
275
- const n = r.get, [e, s] = v(
276
- U(n, t)
267
+ }, Pe = (t = U) => {
268
+ const n = c.get, [e, s] = f(
269
+ q(n, t)
277
270
  );
278
- return f(() => {
279
- let a = !0;
280
- const d = n(t);
281
- s(U(n, t));
282
- const u = d.subscribeEvents((_, h) => {
283
- (_ === r.eventNames.logout_from_another_tab || _ === r.eventNames.logout_from_same_tab || _ === r.eventNames.token_acquired) && a && s(U(n, t));
271
+ return p(() => {
272
+ let l = !0;
273
+ const d = n(t), u = d.subscribeEvents((_, k) => {
274
+ (_ === c.eventNames.logout_from_another_tab || _ === c.eventNames.logout_from_same_tab || _ === c.eventNames.token_acquired) && l && s(q(n, t));
284
275
  });
285
276
  return () => {
286
- a = !1, d.removeEventSubscription(u);
277
+ l = !1, d.removeEventSubscription(u);
287
278
  };
288
- }, [t]), { login: (a = void 0, d = void 0, u = !1, _ = void 0) => n(t).loginAsync(
289
- a,
279
+ }, [t]), { login: (l = void 0, d = void 0, u = !1, _ = void 0) => n(t).loginAsync(
280
+ l,
290
281
  d,
291
282
  !1,
292
283
  _,
293
284
  u
294
- ), logout: (a = void 0, d = void 0) => n(t).logoutAsync(a, d), renewTokens: async (a = void 0) => {
295
- const d = await n(t).renewTokensAsync(a);
285
+ ), logout: (l = void 0, d = void 0) => n(t).logoutAsync(l, d), renewTokens: async (l = void 0) => {
286
+ const d = await n(t).renewTokensAsync(l);
296
287
  return {
297
288
  // @ts-ignore
298
289
  accessToken: d.accessToken,
@@ -304,142 +295,133 @@ const x = "default", te = (t, n, e = !1) => async (...s) => await n().fetchWithT
304
295
  idTokenPayload: d.idTokenPayload
305
296
  };
306
297
  }, isAuthenticated: e };
307
- }, q = { accessToken: null, accessTokenPayload: null }, ye = (t) => {
308
- const n = r.get, e = n(t);
298
+ }, R = { accessToken: null, accessTokenPayload: null }, ye = (t) => {
299
+ const n = c.get, e = n(t);
309
300
  if (e.tokens) {
310
301
  const s = e.tokens;
311
302
  return {
312
303
  accessToken: s.accessToken,
313
304
  accessTokenPayload: s.accessTokenPayload,
314
- generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, c) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, c) : null
305
+ generateDemonstrationOfProofOfPossessionAsync: e.configuration.demonstrating_proof_of_possession ? (o, r) => e.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, o, r) : null
315
306
  };
316
307
  }
317
- return q;
308
+ return R;
318
309
  };
319
- function ge(t, n) {
310
+ function be(t, n) {
320
311
  return t.configuration.demonstrating_proof_of_possession ? (e, s, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken, e, s, o) : null;
321
312
  }
322
- const Ne = (t = F) => {
323
- const n = r.get, [e, s] = v(ye(t));
324
- return f(() => {
313
+ const Ne = (t = U) => {
314
+ const n = c.get, [e, s] = f(() => ye(t));
315
+ return p(() => {
325
316
  let o = !0;
326
- const c = n(t);
327
- if (c.tokens) {
328
- const a = c.tokens;
329
- s({
330
- accessToken: a.accessToken,
331
- accessTokenPayload: a.accessTokenPayload
332
- });
333
- }
334
- const l = c.subscribeEvents((a, d) => {
335
- if ((a === r.eventNames.token_renewed || a === r.eventNames.token_acquired || a === r.eventNames.logout_from_another_tab || a === r.eventNames.logout_from_same_tab || a === r.eventNames.refreshTokensAsync_error || a === r.eventNames.syncTokensAsync_error) && o) {
336
- const u = c.tokens;
317
+ const r = n(t), a = r.subscribeEvents((l, d) => {
318
+ 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) {
319
+ const u = r.tokens;
337
320
  s(
338
321
  u != null ? {
339
322
  accessToken: u.accessToken,
340
323
  accessTokenPayload: u.accessTokenPayload,
341
- generateDemonstrationOfProofOfPossessionAsync: ge(c, u)
342
- } : q
324
+ generateDemonstrationOfProofOfPossessionAsync: be(r, u)
325
+ } : R
343
326
  );
344
327
  }
345
328
  });
346
329
  return () => {
347
- o = !1, c.removeEventSubscription(l);
330
+ o = !1, r.removeEventSubscription(a);
348
331
  };
349
332
  }, [t]), e;
350
- }, Y = { idToken: null, idTokenPayload: null }, be = (t) => {
351
- const n = r.get, e = n(t);
333
+ }, Y = { idToken: null, idTokenPayload: null }, ge = (t) => {
334
+ const n = c.get, e = n(t);
352
335
  if (e.tokens) {
353
336
  const s = e.tokens;
354
337
  return { idToken: s.idToken, idTokenPayload: s.idTokenPayload };
355
338
  }
356
339
  return Y;
357
- }, Le = (t = F) => {
358
- const n = r.get, [e, s] = v(be(t));
359
- return f(() => {
340
+ }, Le = (t = U) => {
341
+ const n = c.get, [e, s] = f(() => ge(t));
342
+ return p(() => {
360
343
  let o = !0;
361
- const c = n(t);
362
- if (c.tokens) {
363
- const a = c.tokens;
364
- s({ idToken: a.idToken, idTokenPayload: a.idTokenPayload });
365
- }
366
- const l = c.subscribeEvents((a, d) => {
367
- if ((a === r.eventNames.token_renewed || a === r.eventNames.token_acquired || a === r.eventNames.logout_from_another_tab || a === r.eventNames.logout_from_same_tab || a === r.eventNames.refreshTokensAsync_error || a === r.eventNames.syncTokensAsync_error) && o) {
368
- const u = c.tokens;
344
+ const r = n(t), a = r.subscribeEvents((l, d) => {
345
+ 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) {
346
+ const u = r.tokens;
369
347
  s(
370
348
  u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y
371
349
  );
372
350
  }
373
351
  });
374
352
  return () => {
375
- o = !1, c.removeEventSubscription(l);
353
+ o = !1, r.removeEventSubscription(a);
376
354
  };
377
355
  }, [t]), e;
378
356
  };
379
357
  var me = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(me || {});
380
358
  const Ie = (t = "default", n = !1) => {
381
- const s = r.get(t).userInfo(), [o, c] = v({
359
+ const s = c.get(t).userInfo(), [o, r] = f({
382
360
  user: s,
383
361
  status: s ? "User loaded" : "Unauthenticated"
384
362
  /* Unauthenticated */
385
- }), [l, a] = v(s ? 1 : 0), [d, u] = v(s ? 1 : 0);
386
- f(() => {
387
- const h = r.get(t);
388
- let p = !0;
389
- if (h && h.tokens) {
390
- const y = l === d;
391
- if (y && h.userInfo())
363
+ }), [a, l] = f(s ? 1 : 0), [d, u] = f(s ? 1 : 0);
364
+ p(() => {
365
+ const k = c.get(t);
366
+ let v = !0;
367
+ if (k && k.tokens) {
368
+ const y = a === d;
369
+ if (y && k.userInfo())
392
370
  return;
393
- c({
394
- ...o,
395
- status: "Loading user"
396
- /* Loading */
397
- }), h.userInfoAsync(!y, n).then((S) => {
398
- p && c({
399
- user: S,
371
+ queueMicrotask(() => {
372
+ v && (r({
373
+ ...o,
374
+ status: "Loading user"
375
+ /* Loading */
376
+ }), u(a));
377
+ }), k.userInfoAsync(!y, n).then((P) => {
378
+ v && r({
379
+ user: P,
400
380
  status: "User loaded"
401
381
  /* Loaded */
402
382
  });
403
- }).catch(() => c({
383
+ }).catch(() => r({
404
384
  ...o,
405
385
  status: "Error loading user"
406
386
  /* LoadingError */
407
- })), u(l);
387
+ }));
408
388
  } else
409
- c({
410
- user: null,
411
- status: "Unauthenticated"
412
- /* Unauthenticated */
389
+ queueMicrotask(() => {
390
+ v && r({
391
+ user: null,
392
+ status: "Unauthenticated"
393
+ /* Unauthenticated */
394
+ });
413
395
  });
414
- const T = h.subscribeEvents((y) => {
415
- (y === r.eventNames.logout_from_another_tab || y === r.eventNames.logout_from_same_tab) && p && c({
396
+ const w = k.subscribeEvents((y) => {
397
+ (y === c.eventNames.logout_from_another_tab || y === c.eventNames.logout_from_same_tab) && v && r({
416
398
  user: null,
417
399
  status: "Unauthenticated"
418
400
  /* Unauthenticated */
419
401
  });
420
402
  });
421
403
  return () => {
422
- p = !1, h.removeEventSubscription(T);
404
+ v = !1, k.removeEventSubscription(w);
423
405
  };
424
- }, [l]);
406
+ }, [a]);
425
407
  const _ = () => {
426
- a(l + 1);
408
+ l(a + 1);
427
409
  };
428
410
  return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: _ };
429
411
  };
430
412
  export {
431
- Me as OidcClient,
432
- De as OidcLocation,
433
- Pe as OidcProvider,
413
+ Fe as OidcClient,
414
+ qe as OidcLocation,
415
+ Ee as OidcProvider,
434
416
  pe as OidcSecure,
435
417
  me as OidcUserStatus,
436
- xe as TokenAutomaticRenewMode,
437
- We as TokenRenewMode,
438
- Se as useOidc,
418
+ De as TokenAutomaticRenewMode,
419
+ xe as TokenRenewMode,
420
+ Pe as useOidc,
439
421
  Ne as useOidcAccessToken,
440
422
  ne as useOidcFetch,
441
423
  Le as useOidcIdToken,
442
424
  Ie as useOidcUser,
443
425
  Oe as withOidcFetch,
444
- Ee as withOidcSecure
426
+ Se as withOidcSecure
445
427
  };
@@ -1 +1 @@
1
- (function(h,o){typeof exports=="object"&&typeof module<"u"?o(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"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h["react-oidc"]={},h.jsxRuntime,h.oidcClient,h.React))})(this,function(h,o,s,l){"use strict";const F="default",B=(t,n,e=!1)=>async(...c)=>await n().fetchWithTokens(t,e)(...c),z=(t=null,n=F,e=!1)=>c=>r=>{const{fetch:i}=I(t||r.fetch,n,e);return o.jsx(c,{...r,fetch:i})},I=(t=null,n=F,e=!1)=>{const c=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(c,()=>r(n),e)(d,a),[c,n])}},U=()=>o.jsx("div",{className:"oidc-authenticating",children:o.jsxs("div",{className:"oidc-authenticating__container",children:[o.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),o.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>o.jsx("div",{className:"oidc-authenticating",children:o.jsxs("div",{className:"oidc-authenticating__container",children:[o.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),o.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,n)=>(e,c)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,c);const r=c||{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},H=(t,n,e)=>({replaceState:(c,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,c),t.dispatchEvent(n("popstate"))}}),Q=()=>H(window,G(window,document),$),M=()=>o.jsx("div",{className:"oidc-callback",children:o.jsxs("div",{className:"oidc-callback__container",children:[o.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),o.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:c})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(c?c():Q()).replaceState(_||"/")}catch(_){u&&(console.warn(_),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=n||M;return r?o.jsx(d,{configurationName:e}):o.jsx(a,{configurationName:e})},V=()=>o.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>o.jsx("div",{className:"oidc-serviceworker",children:o.jsxs("div",{className:"oidc-serviceworker__container",children:[o.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),o.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."})]})}),Z=()=>o.jsx("div",{className:"oidc-session-lost",children:o.jsxs("div",{className:"oidc-session-lost__container",children:[o.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),o.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,c=e(t);let r=null;for(const[i,d]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{c.tokens||c.loginAsync(null,r,!0,n.scope)},[]),o.jsx(o.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:c,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,O]=l.useState(u);l.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);if(c&&f===s.getPath(c))return o.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return o.jsx(R,{configurationName:d});switch(f){case _:return o.jsx(J,{callBackError:t,callBackSuccess:n,configurationName:d,withCustomHistory:a});default:return o.jsx(o.Fragment,{children:i})}},te=l.memo(ee),q={name:"",data:null},se=({loadingComponent:t,children:n,configurationName:e})=>{const[c,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return o.jsx(o.Fragment,{children:c?o.jsx(a,{configurationName:e}):o.jsx(o.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:c})=>{const r=n;return t?o.jsx(r,{configurationName:c,children:e}):o.jsx(o.Fragment,{children:e})},ne=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:c=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:T=null,getFetch:y=null,location:P=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=(N="default")=>s.OidcClient.getOrCreate(y??s.getFetchDefault,P??new s.OidcLocation)(n,N),[fe,he]=l.useState(!0),[ke,S]=l.useState(q),[_e,Oe]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((k,b)=>{T&&T(e,k,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((k,b)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:k,data:b})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:b})}else k===s.OidcClient.eventNames.logout_from_same_tab?_!=null&&_():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:b}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&S({name:k,data:b})});return Oe(e),he(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[n,e]);const ve=u,ye=r,g=i,ge=d,be=a,A=fe||_e!==e,L=w(e);switch(ke.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ge,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(ve,{configurationName:e})});default:return o.jsx(p,{loadingComponent:g,isLoading:A,configurationName:e,children:o.jsx(te,{redirect_uri:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:c,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:P??new s.OidcLocation,children:o.jsx(se,{loadingComponent:g,configurationName:e,children:t})})})}},D=({children:t,callbackPath:n=null,extras:e=null,configurationName:c="default"})=>{const r=s.OidcClient.get,i=r(c);return l.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[c,n,e]),i.tokens?o.jsx(o.Fragment,{children:t}):null},oe=(t,n=null,e=null,c="default")=>r=>o.jsx(D,{callbackPath:n,extras:e,configurationName:c,children:o.jsx(t,{...r})}),E="default",C=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},ce=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(C(n,t));return l.useEffect(()=>{let a=!0;const u=n(t);c(C(n,t));const f=u.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&c(C(n,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,O=void 0)=>n(t).loginAsync(a,u,!1,O,f),logout:(a=void 0,u=void 0)=>n(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await n(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const c=e.tokens;return{accessToken:c.accessToken,accessTokenPayload:c.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,r,i):null}}return W};function ie(t,n){return t.configuration.demonstrating_proof_of_possession?(e,c,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,c,r):null}const ae=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=n(t);if(i.tokens){const a=i.tokens;c({accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload})}const d=i.subscribeEvents((a,u)=>{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 f=i.tokens;c(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const c=e.tokens;return{idToken:c.idToken,idTokenPayload:c.idTokenPayload}}return j},de=(t=E)=>{const n=s.OidcClient.get,[e,c]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=n(t);if(i.tokens){const a=i.tokens;c({idToken:a.idToken,idTokenPayload:a.idTokenPayload})}const d=i.subscribeEvents((a,u)=>{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 f=i.tokens;c(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",n=!1)=>{const c=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:c,status:c?"User loaded":"Unauthenticated"}),[d,a]=l.useState(c?1:0),[u,f]=l.useState(c?1:0);l.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const y=d===u;if(y&&_.userInfo())return;i({...r,status:"Loading user"}),_.userInfoAsync(!y,n).then(P=>{v&&i({user:P,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"})),f(d)}else i({user:null,status:"Unauthenticated"});const T=_.subscribeEvents(y=>{(y===s.OidcClient.eventNames.logout_from_another_tab||y===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(T)}},[d]);const O=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(h,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(h,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(h,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(h,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),h.OidcProvider=ne,h.OidcSecure=D,h.OidcUserStatus=Y,h.useOidc=ce,h.useOidcAccessToken=ae,h.useOidcFetch=I,h.useOidcIdToken=de,h.useOidcUser=ue,h.withOidcFetch=z,h.withOidcSecure=oe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,n){typeof exports=="object"&&typeof module<"u"?n(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"],n):(h=typeof globalThis<"u"?globalThis:h||self,n(h["react-oidc"]={},h.jsxRuntime,h.oidcClient,h.React))})(this,(function(h,n,s,l){"use strict";const m="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=m,e=!1)=>o=>r=>{const{fetch:i}=F(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},F=(t=null,c=m,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(o,()=>r(c),e)(d,a),[o,c,e])}},I=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),n.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),n.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,c)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=c.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},H=(t,c,e)=>({replaceState:(o,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,o),t.dispatchEvent(c("popstate"))}}),Q=()=>H(window,G(window,document),$),U=()=>n.jsx("div",{className:"oidc-callback",children:n.jsxs("div",{className:"oidc-callback__container",children:[n.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),n.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:c,configurationName:e,withCustomHistory:o})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(o?o():Q()).replaceState(_||"/")}catch(_){u&&(console.warn(_),i(!0))}})(),()=>{u=!1}},[]);const d=t||I,a=c||U;return r?n.jsx(d,{configurationName:e}):n.jsx(a,{configurationName:e})},V=()=>n.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>n.jsx("div",{className:"oidc-serviceworker",children:n.jsxs("div",{className:"oidc-serviceworker__container",children:[n.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),n.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."})]})}),Z=()=>n.jsx("div",{className:"oidc-session-lost",children:n.jsxs("div",{className:"oidc-session-lost__container",children:[n.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),n.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const c=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,d]of Object.entries(c))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,c.scope)},[]),n.jsx(n.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:c,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,O]=l.useState(u);l.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);return o&&f===s.getPath(o)?n.jsx(x,{configurationName:d}):r&&f===s.getPath(r)?n.jsx(R,{configurationName:d}):f===_?n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a}):n.jsx(n.Fragment,{children:i})},te=l.memo(ee),M={name:"",data:null},se=({loadingComponent:t,children:c,configurationName:e})=>{const[o,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return n.jsx(n.Fragment,{children:o?n.jsx(a,{configurationName:e}):n.jsx(n.Fragment,{children:c})})},p=({isLoading:t,loadingComponent:c,children:e,configurationName:o})=>{const r=c;return t?n.jsx(r,{configurationName:o,children:e}):n.jsx(n.Fragment,{children:e})},ne=({children:t,configuration:c,configurationName:e="default",callbackSuccessComponent:o=U,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=I,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:w=null,getFetch:g=null,location:E=null})=>{if(c&&c.redirect_uri&&c.silent_redirect_uri&&c.redirect_uri===c.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const T=(L="default")=>s.OidcClient.getOrCreate(g??s.getFetchDefault,E??new s.OidcLocation)(c,L),[fe,he]=l.useState(!0),[ke,S]=l.useState(M),[_e,Oe]=l.useState(e);l.useEffect(()=>{const N=T(e).subscribeEvents((k,b)=>{w&&w(e,k,b)});return()=>{T(e).removeEventSubscription(N)}},[e,w]),l.useEffect(()=>{const N=T(e).subscribeEvents((k,b)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:k,data:b})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:b})}else k===s.OidcClient.eventNames.logout_from_same_tab?_?.():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:b}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:k,data:b})});return queueMicrotask(()=>{Oe(e),he(!1)}),()=>{T(e).removeEventSubscription(N),S(M)}},[c,e]);const ve=u,ge=r,y=i,ye=d,be=a,A=fe||_e!==e,C=T(e);switch(ke.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ge,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ve,{configurationName:e})});default:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(te,{redirect_uri:C.configuration.redirect_uri,silent_redirect_uri:C.configuration.silent_redirect_uri,silent_login_uri:C.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:E??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},q=({children:t,callbackPath:c=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return l.useEffect(()=>{i.tokens||i.loginAsync(c,e)},[o,c,e]),i.tokens?n.jsx(n.Fragment,{children:t}):null},ce=(t,c=null,e=null,o="default")=>r=>n.jsx(q,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),P="default",D=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},oe=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(D(c,t));return l.useEffect(()=>{let a=!0;const u=c(t),f=u.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&o(D(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,O=void 0)=>c(t).loginAsync(a,u,!1,O,f),logout:(a=void 0,u=void 0)=>c(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await c(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const c=s.OidcClient.get,e=c(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 W};function ie(t,c){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,e,o,r):null}const ae=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(()=>re(t));return l.useEffect(()=>{let r=!0;const i=c(t),d=i.subscribeEvents((a,u)=>{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 f=i.tokens;o(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},de=(t=P)=>{const c=s.OidcClient.get,[e,o]=l.useState(()=>le(t));return l.useEffect(()=>{let r=!0;const i=c(t),d=i.subscribeEvents((a,u)=>{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 f=i.tokens;o(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",c=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[d,a]=l.useState(o?1:0),[u,f]=l.useState(o?1:0);l.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const g=d===u;if(g&&_.userInfo())return;queueMicrotask(()=>{v&&(i({...r,status:"Loading user"}),f(d))}),_.userInfoAsync(!g,c).then(E=>{v&&i({user:E,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{v&&i({user:null,status:"Unauthenticated"})});const w=_.subscribeEvents(g=>{(g===s.OidcClient.eventNames.logout_from_another_tab||g===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(w)}},[d]);const O=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(h,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(h,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(h,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(h,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),h.OidcProvider=ne,h.OidcSecure=q,h.OidcUserStatus=Y,h.useOidc=oe,h.useOidcAccessToken=ae,h.useOidcFetch=F,h.useOidcIdToken=de,h.useOidcUser=ue,h.withOidcFetch=z,h.withOidcSecure=ce,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.26.0",
3
+ "version": "7.26.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -40,31 +40,31 @@
40
40
  "lint": "eslint src"
41
41
  },
42
42
  "dependencies": {
43
- "@axa-fr/oidc-client-service-worker": "7.26.0",
44
- "@axa-fr/oidc-client": "7.26.0"
43
+ "@axa-fr/oidc-client-service-worker": "7.26.3",
44
+ "@axa-fr/oidc-client": "7.26.3"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@testing-library/jest-dom": "6.6.3",
51
- "@testing-library/react": "16.3.0",
50
+ "@testing-library/jest-dom": "6.9.1",
51
+ "@testing-library/react": "16.3.2",
52
52
  "@testing-library/user-event": "14.6.1",
53
- "@types/react": "19.1.2",
54
- "@vitejs/plugin-react": "4.4.1",
55
- "@vitest/coverage-v8": "3.1.3",
56
- "cpy": "11.1.0",
57
- "cpy-cli": "^5.0.0",
58
- "cross-env": "^7.0.3",
59
- "jsdom": "26.1.0",
60
- "msw": "2.7.6",
61
- "react": "^19.1.0",
62
- "react-dom": "^19.1.0",
63
- "rimraf": "6.0.1",
64
- "typescript": "5.8.3",
65
- "vite": "6.3.5",
66
- "vite-plugin-dts": "4.5.3",
67
- "vitest": "3.1.3"
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",
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",
66
+ "vite-plugin-dts": "4.5.4",
67
+ "vitest": "4.0.18"
68
68
  },
69
69
  "license": "MIT",
70
70
  "publishConfig": {
@@ -53,7 +53,7 @@ export const useOidcFetch = (
53
53
  );
54
54
  return newFetch(input, init);
55
55
  },
56
- [previousFetch, configurationName],
56
+ [previousFetch, configurationName, demonstratingProofOfPossession],
57
57
  );
58
58
  return { fetch: memoizedFetchCallback };
59
59
  };
@@ -117,7 +117,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
117
117
 
118
118
  const [loading, setLoading] = useState(true);
119
119
  const [event, setEvent] = useState(defaultEventState);
120
- const [currentConfigurationName, setConfigurationName] = useState('default');
120
+ const [currentConfigurationName, setConfigurationName] = useState(configurationName);
121
121
 
122
122
  useEffect(() => {
123
123
  const oidc = getOidc(configurationName);
@@ -170,8 +170,11 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
170
170
  }
171
171
  });
172
172
 
173
- setConfigurationName(configurationName);
174
- setLoading(false);
173
+ queueMicrotask(() => {
174
+ setConfigurationName(configurationName);
175
+ setLoading(false);
176
+ });
177
+
175
178
  return () => {
176
179
  const previousOidc = getOidc(configurationName);
177
180
  previousOidc.removeEventSubscription(newSubscriptionId);
package/src/ReactOidc.tsx CHANGED
@@ -25,7 +25,6 @@ export const useOidc = (configurationName = defaultConfigurationName) => {
25
25
  useEffect(() => {
26
26
  let isMounted = true;
27
27
  const oidc = getOidc(configurationName);
28
- setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
29
28
 
30
29
  const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
31
30
  if (
@@ -118,18 +117,11 @@ function getGenerateDemonstrationOfProofOfPossessionAsync(oidc: OidcClient, toke
118
117
 
119
118
  export const useOidcAccessToken = (configurationName = defaultConfigurationName) => {
120
119
  const getOidc = OidcClient.get;
121
- const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
120
+ const [state, setAccessToken] = useState<OidcAccessToken>(() => initTokens(configurationName));
122
121
 
123
122
  useEffect(() => {
124
123
  let isMounted = true;
125
124
  const oidc = getOidc(configurationName);
126
- if (oidc.tokens) {
127
- const tokens = oidc.tokens;
128
- setAccessToken({
129
- accessToken: tokens.accessToken,
130
- accessTokenPayload: tokens.accessTokenPayload,
131
- });
132
- }
133
125
 
134
126
  const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
135
127
  if (
@@ -183,15 +175,11 @@ export type OidcIdToken = {
183
175
 
184
176
  export const useOidcIdToken = (configurationName = defaultConfigurationName) => {
185
177
  const getOidc = OidcClient.get;
186
- const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
178
+ const [state, setIDToken] = useState<OidcIdToken>(() => initIdToken(configurationName));
187
179
 
188
180
  useEffect(() => {
189
181
  let isMounted = true;
190
182
  const oidc = getOidc(configurationName);
191
- if (oidc.tokens) {
192
- const tokens = oidc.tokens;
193
- setIDToken({ idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload });
194
- }
195
183
 
196
184
  const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
197
185
  if (
package/src/User.ts CHANGED
@@ -34,7 +34,13 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
34
34
  if (isCache && oidc.userInfo<T>()) {
35
35
  return;
36
36
  }
37
- setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading });
37
+ // Use queueMicrotask to defer setState to avoid synchronous call in effect
38
+ queueMicrotask(() => {
39
+ if (isMounted) {
40
+ setOidcUser({ ...oidcUser, status: OidcUserStatus.Loading });
41
+ setPreviousOidcUserId(oidcUserId);
42
+ }
43
+ });
38
44
  oidc
39
45
  .userInfoAsync(!isCache, demonstrating_proof_of_possession)
40
46
  .then(info => {
@@ -44,9 +50,12 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(
44
50
  }
45
51
  })
46
52
  .catch(() => setOidcUser({ ...oidcUser, status: OidcUserStatus.LoadingError }));
47
- setPreviousOidcUserId(oidcUserId);
48
53
  } else {
49
- setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
54
+ queueMicrotask(() => {
55
+ if (isMounted) {
56
+ setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
57
+ }
58
+ });
50
59
  }
51
60
  const newSubscriptionId = oidc.subscribeEvents((name: string) => {
52
61
  if (
@@ -1,16 +1,30 @@
1
1
  import { render } from '@testing-library/react';
2
2
  import React from 'react';
3
- import { describe, expect, it } from 'vitest';
3
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
5
5
  import OidcRoutes from './OidcRoutes';
6
6
 
7
7
  describe('Authenticating test suite', () => {
8
+ beforeEach(() => {
9
+ // Mock window.location
10
+ delete (window as any).location;
11
+ window.location = { href: 'http://example.com:3000/' } as any;
12
+
13
+ // Mock window event listeners
14
+ window.addEventListener = vi.fn();
15
+ window.removeEventListener = vi.fn();
16
+ });
17
+
8
18
  it('renders correctly', () => {
9
19
  const props = {
10
20
  children: 'http://url.com',
11
- callbackComponent: () => <div>tcallback component</div>,
12
21
  redirect_uri: 'http://example.com:3000/authentication/callback',
13
22
  configurationName: '',
23
+ location: {
24
+ pathname: '/',
25
+ search: '',
26
+ hash: '',
27
+ },
14
28
  };
15
29
  const { asFragment } = render(<OidcRoutes {...props} />);
16
30
  expect(asFragment()).toMatchSnapshot();
@@ -5,9 +5,3 @@ exports[`Authenticating test suite > renders correctly 1`] = `
5
5
  http://url.com
6
6
  </DocumentFragment>
7
7
  `;
8
-
9
- exports[`Authenticating test suite renders correctly 1`] = `
10
- <DocumentFragment>
11
- http://url.com
12
- </DocumentFragment>
13
- `;
@@ -7,7 +7,7 @@ describe('WithRouter test Suite', () => {
7
7
  beforeEach(() => {});
8
8
  it('should CreateEvent return correct Event if not on IE', () => {
9
9
  const windowMock = {
10
- CustomEvent: vi.fn().mockImplementation((event, params) => {
10
+ CustomEvent: vi.fn(function (event, params) {
11
11
  return { event, params };
12
12
  }),
13
13
  };