@axa-fr/react-oidc 7.22.18 → 7.22.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +87 -114
  2. package/bin/copy-service-worker-files.mjs +24 -17
  3. package/dist/FetchToken.d.ts.map +1 -1
  4. package/dist/OidcProvider.d.ts +1 -1
  5. package/dist/OidcProvider.d.ts.map +1 -1
  6. package/dist/OidcSecure.d.ts.map +1 -1
  7. package/dist/OidcTrustedDomains.js +13 -10
  8. package/dist/ReactOidc.d.ts.map +1 -1
  9. package/dist/User.d.ts.map +1 -1
  10. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  11. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  12. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  13. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  14. package/dist/core/default-component/SilentCallback.component.d.ts +5 -2
  15. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  16. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  17. package/dist/core/routes/withRouter.d.ts.map +1 -1
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +165 -72
  21. package/dist/index.umd.cjs +1 -1
  22. package/package.json +3 -3
  23. package/src/FetchToken.tsx +36 -13
  24. package/src/OidcProvider.tsx +222 -176
  25. package/src/OidcSecure.tsx +34 -23
  26. package/src/ReactOidc.tsx +181 -142
  27. package/src/User.ts +60 -50
  28. package/src/core/default-component/Authenticating.component.tsx +1 -1
  29. package/src/core/default-component/Callback.component.tsx +18 -11
  30. package/src/core/default-component/Loading.component.tsx +1 -5
  31. package/src/core/default-component/ServiceWorkerNotSupported.component.tsx +5 -2
  32. package/src/core/default-component/SessionLost.component.tsx +1 -1
  33. package/src/core/default-component/SilentCallback.component.tsx +17 -11
  34. package/src/core/default-component/SilentLogin.component.tsx +18 -18
  35. package/src/core/routes/OidcRoutes.spec.tsx +2 -2
  36. package/src/core/routes/OidcRoutes.tsx +12 -5
  37. package/src/core/routes/withRouter.spec.tsx +5 -6
  38. package/src/core/routes/withRouter.tsx +21 -19
  39. package/src/index.ts +8 -3
@@ -1 +1 @@
1
- {"version":3,"file":"SilentCallback.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/SilentCallback.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAa,MAAM,OAAO,CAAC;AAEjD,QAAA,MAAM,qBAAqB,EAAE,aAAa,CAAC,GAAG,CAW7C,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"SilentCallback.component.d.ts","sourceRoot":"","sources":["../../../src/core/default-component/SilentCallback.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,QAAA,MAAM,qBAAqB,EAAE,EAAE,CAAC,mBAAmB,CAalD,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"OidcRoutes.d.ts","sourceRoot":"","sources":["../../../src/core/routes/OidcRoutes.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,EAAE,aAAa,EAA8C,MAAM,OAAO,CAAC;AAKzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,KAAK,eAAe,GAAG;IACrB,wBAAwB,CAAC,EAAE,aAAa,CAAC;IACzC,sBAAsB,CAAC,EAAE,aAAa,CAAC;IACvC,uBAAuB,CAAC,EAAE,aAAa,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;;AA8CF,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,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;;AAqDF,wBAAsC"}
@@ -1 +1 @@
1
- {"version":3,"file":"withRouter.d.ts","sourceRoot":"","sources":["../../../src/core/routes/withRouter.tsx"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7F,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB,CAAC;AAMF,KAAK,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC;CACX,CAAC;AAGF,eAAO,MAAM,WAAW,mBAAoB,cAAc,oBAAoB,QAAQ,aAC7E,MAAM,UACL,qBAAqB,KAC5B,WASF,CAAC;AAEF,KAAK,kBAAkB,GAAG,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAChF;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC5E,CAAA;AAiBD,eAAO,MAAM,gBAAgB,qBAAuE,CAAC"}
1
+ {"version":3,"file":"withRouter.d.ts","sourceRoot":"","sources":["../../../src/core/routes/withRouter.tsx"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IACpC,WAAW,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7F,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB,CAAC;AAMF,KAAK,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC;CACX,CAAC;AAGF,eAAO,MAAM,WAAW,mBACL,cAAc,oBAAoB,QAAQ,aACnD,MAAM,UAAU,qBAAqB,KAAG,WAc/C,CAAC;AAEJ,KAAK,kBAAkB,GAAG,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAChF;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC5E,CAAC;AAiBF,eAAO,MAAM,gBAAgB,qBACmC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { OidcProvider } from './OidcProvider.js';
3
3
  export { OidcSecure, withOidcSecure } from './OidcSecure.js';
4
4
  export { useOidc, useOidcAccessToken, useOidcIdToken } from './ReactOidc.js';
5
5
  export { OidcUserStatus, useOidcUser } from './User.js';
6
- export type { AuthorityConfiguration, Fetch, OidcConfiguration, StringMap, ILOidcLocation } from '@axa-fr/oidc-client';
7
- export { TokenRenewMode, OidcClient, TokenAutomaticRenewMode, OidcLocation } from '@axa-fr/oidc-client';
6
+ export type { AuthorityConfiguration, Fetch, ILOidcLocation, OidcConfiguration, StringMap, } from '@axa-fr/oidc-client';
8
7
  export type { OidcUserInfo } from '@axa-fr/oidc-client';
8
+ export { OidcClient, OidcLocation, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxG,YAAY,EAAG,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxD,YAAY,EACV,sBAAsB,EACtB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,22 @@
1
- import { jsx as i, jsxs as E, Fragment as b } from "react/jsx-runtime";
1
+ import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime";
2
2
  import { OidcClient as r, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
3
3
  import { OidcClient as Me, OidcLocation as De, TokenAutomaticRenewMode as xe, TokenRenewMode as We } from "@axa-fr/oidc-client";
4
4
  import Z, { useCallback as ee, useState as f, useEffect as v } from "react";
5
5
  const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithTokens(t, e)(...n), Oe = (t = null, s = x, e = !1) => (n) => (o) => {
6
- const { fetch: c } = ne(t || o.fetch, s, e);
6
+ const { fetch: c } = ne(
7
+ t || o.fetch,
8
+ s,
9
+ e
10
+ );
7
11
  return /* @__PURE__ */ i(n, { ...o, fetch: c });
8
12
  }, ne = (t = null, s = x, e = !1) => {
9
13
  const n = t || window.fetch, o = r.get;
10
14
  return { fetch: ee(
11
- (l, a) => te(n, () => o(s), e)(l, a),
15
+ (l, a) => te(
16
+ n,
17
+ () => o(s),
18
+ e
19
+ )(l, a),
12
20
  [n, s]
13
21
  ) };
14
22
  }, W = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
@@ -17,11 +25,16 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
17
25
  ] }) }), se = () => /* @__PURE__ */ i("div", { className: "oidc-authenticating", children: /* @__PURE__ */ E("div", { className: "oidc-authenticating__container", children: [
18
26
  /* @__PURE__ */ i("h1", { className: "oidc-authenticating__title", children: "Authentication in progress" }),
19
27
  /* @__PURE__ */ i("p", { className: "oidc-authenticating__content", children: "You will be redirected to the login page." })
20
- ] }) }), oe = () => Math.random().toString(36).substr(2, 6), ce = (t, s) => (e, n) => {
28
+ ] }) }), oe = () => Math.random().toString(36).slice(2, 8), ce = (t, s) => (e, n) => {
21
29
  if (typeof t.CustomEvent == "function")
22
30
  return new t.CustomEvent(e, n);
23
31
  const o = n || { bubbles: !1, cancelable: !1, detail: void 0 }, c = s.createEvent("CustomEvent");
24
- return c.initCustomEvent(e, o.bubbles, o.cancelable, o.detail), c.prototype = t.Event.prototype, c;
32
+ return c.initCustomEvent(
33
+ e,
34
+ o.bubbles,
35
+ o.cancelable,
36
+ o.detail
37
+ ), c.prototype = t.Event.prototype, c;
25
38
  }, re = (t, s, e) => ({
26
39
  replaceState: (n, o) => {
27
40
  const c = e(), l = o || t.history.state;
@@ -30,7 +43,12 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
30
43
  }), ie = () => re(window, ce(window, document), oe), R = () => /* @__PURE__ */ i("div", { className: "oidc-callback", children: /* @__PURE__ */ E("div", { className: "oidc-callback__container", children: [
31
44
  /* @__PURE__ */ i("h1", { className: "oidc-callback__title", children: "Authentication complete" }),
32
45
  /* @__PURE__ */ i("p", { className: "oidc-callback__content", children: "You will be redirected to your application." })
33
- ] }) }), ae = ({ callBackError: t, callBackSuccess: s, configurationName: e, withCustomHistory: n }) => {
46
+ ] }) }), ae = ({
47
+ callBackError: t,
48
+ callBackSuccess: s,
49
+ configurationName: e,
50
+ withCustomHistory: n
51
+ }) => {
34
52
  const [o, c] = f(!1);
35
53
  v(() => {
36
54
  let d = !0;
@@ -56,17 +74,18 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
56
74
  /* @__PURE__ */ i("p", { className: "oidc-session-lost__content", children: "Your session has expired. Please re-authenticate." })
57
75
  ] }) }), ke = ({ configurationName: t }) => (v(() => {
58
76
  (async () => {
59
- const e = r.get;
60
- e(t).silentLoginCallbackAsync();
61
- })();
62
- }, []), /* @__PURE__ */ i(b, {})), he = ({ configurationName: t }) => {
77
+ r.get(t).silentLoginCallbackAsync();
78
+ })().catch((e) => {
79
+ console.error("Error during silent login callback:", e);
80
+ });
81
+ }, [t]), null), he = ({ configurationName: t }) => {
63
82
  const s = V(window.location.href), e = r.get, n = e(t);
64
83
  let o = null;
65
84
  for (const [c, l] of Object.entries(s))
66
85
  c === "state" || c === "scope" || (o === null && (o = {}), o[c] = l);
67
86
  return v(() => {
68
87
  n.tokens || n.loginAsync(null, o, !0, s.scope);
69
- }, []), /* @__PURE__ */ i(b, {});
88
+ }, []), /* @__PURE__ */ i(m, {});
70
89
  }, _e = ({
71
90
  callbackErrorComponent: t,
72
91
  callbackSuccessComponent: s,
@@ -75,26 +94,37 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
75
94
  silent_login_uri: o,
76
95
  children: c,
77
96
  configurationName: l,
78
- withCustomHistory: a = null,
79
- location: d
97
+ withCustomHistory: a = null
80
98
  }) => {
81
- const u = window ? O(window.location.href) : "", [_, h] = f(u);
99
+ const d = window ? O(window.location.href) : "", [u, _] = f(d);
82
100
  v(() => {
83
- const g = () => h(O(window.location.href));
101
+ const g = () => _(O(window.location.href));
84
102
  return g(), window.addEventListener("popstate", g, !1), () => window.removeEventListener("popstate", g, !1);
85
103
  }, []);
86
- const p = O(e);
87
- if (n && _ === O(n))
104
+ const h = O(e);
105
+ if (n && u === O(n))
88
106
  return /* @__PURE__ */ i(ke, { configurationName: l });
89
- if (o && _ === O(o))
107
+ if (o && u === O(o))
90
108
  return /* @__PURE__ */ i(he, { configurationName: l });
91
- switch (_) {
92
- case p:
93
- return /* @__PURE__ */ i(ae, { callBackError: t, callBackSuccess: s, configurationName: l, withCustomHistory: a });
109
+ switch (u) {
110
+ case h:
111
+ return /* @__PURE__ */ i(
112
+ ae,
113
+ {
114
+ callBackError: t,
115
+ callBackSuccess: s,
116
+ configurationName: l,
117
+ withCustomHistory: a
118
+ }
119
+ );
94
120
  default:
95
- return /* @__PURE__ */ i(b, { children: c });
121
+ return /* @__PURE__ */ i(m, { children: c });
96
122
  }
97
- }, fe = Z.memo(_e), D = { name: "", data: null }, ve = ({ loadingComponent: t, children: s, configurationName: e }) => {
123
+ }, fe = Z.memo(_e), D = { name: "", data: null }, ve = ({
124
+ loadingComponent: t,
125
+ children: s,
126
+ configurationName: e
127
+ }) => {
98
128
  const [n, o] = f(!0), c = r.get, l = c(e);
99
129
  return v(() => {
100
130
  let d = !0;
@@ -103,10 +133,10 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
103
133
  }), () => {
104
134
  d = !1;
105
135
  };
106
- }, [e]), /* @__PURE__ */ i(b, { children: n ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(b, { children: s }) });
136
+ }, [e]), /* @__PURE__ */ i(m, { children: n ? /* @__PURE__ */ i(t, { configurationName: e }) : /* @__PURE__ */ i(m, { children: s }) });
107
137
  }, P = ({ isLoading: t, loadingComponent: s, children: e, configurationName: n }) => {
108
138
  const o = s;
109
- return t ? /* @__PURE__ */ i(o, { configurationName: n, children: e }) : /* @__PURE__ */ i(b, { children: e });
139
+ return t ? /* @__PURE__ */ i(o, { configurationName: n, children: e }) : /* @__PURE__ */ i(m, { children: e });
110
140
  }, Pe = ({
111
141
  children: t,
112
142
  configuration: s,
@@ -120,80 +150,130 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
120
150
  onSessionLost: u = null,
121
151
  onLogoutFromAnotherTab: _ = null,
122
152
  onLogoutFromSameTab: h = null,
123
- withCustomHistory: p = null,
124
- onEvent: g = null,
125
- getFetch: y = null,
153
+ withCustomHistory: g = null,
154
+ onEvent: T = null,
155
+ getFetch: p = null,
126
156
  location: S = null
127
157
  }) => {
128
- const w = (L = "default") => r.getOrCreate(y ?? X, S ?? new M())(s, L), [j, B] = f(!0), [z, C] = f(D), [K, $] = f("default");
158
+ const w = (L = "default") => r.getOrCreate(p ?? X, S ?? new M())(
159
+ s,
160
+ L
161
+ ), [j, B] = f(!0), [z, C] = f(D), [K, $] = f("default");
129
162
  v(() => {
130
- const I = w(e).subscribeEvents((k, T) => {
131
- g && g(e, k, T);
163
+ const I = w(e).subscribeEvents((k, b) => {
164
+ T && T(e, k, b);
132
165
  });
133
166
  return () => {
134
167
  w(e).removeEventSubscription(I);
135
168
  };
136
- }, [e, g]), v(() => {
137
- const I = w(e).subscribeEvents((k, T) => {
169
+ }, [e, T]), v(() => {
170
+ const I = w(e).subscribeEvents((k, b) => {
138
171
  if (k === r.eventNames.refreshTokensAsync_error || k === r.eventNames.syncTokensAsync_error) {
139
172
  if (u != null) {
140
173
  u();
141
174
  return;
142
175
  }
143
- C({ name: k, data: T });
176
+ C({ name: k, data: b });
144
177
  } else if (k === r.eventNames.logout_from_another_tab) {
145
178
  if (_ != null) {
146
179
  _();
147
180
  return;
148
181
  }
149
- C({ name: k, data: T });
182
+ C({ name: k, data: b });
150
183
  } else
151
- 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: T }) : k === r.eventNames.service_worker_not_supported_by_browser && s.service_worker_only === !0 && C({ name: k, data: T });
184
+ 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 && s.service_worker_only === !0 && C({ name: k, data: b });
152
185
  });
153
186
  return $(e), B(!1), () => {
154
187
  w(e).removeEventSubscription(I), C(D);
155
188
  };
156
189
  }, [s, e]);
157
- const G = d, H = o, m = c, Q = l, J = a, A = j || K !== e, N = w(e);
190
+ const G = d, H = o, y = c, Q = l, J = a, A = j || K !== e, N = w(e);
158
191
  switch (z.name) {
159
192
  case r.eventNames.service_worker_not_supported_by_browser:
160
- return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(Q, { configurationName: e }) });
193
+ return /* @__PURE__ */ i(
194
+ P,
195
+ {
196
+ loadingComponent: y,
197
+ isLoading: A,
198
+ configurationName: e,
199
+ children: /* @__PURE__ */ i(Q, { configurationName: e })
200
+ }
201
+ );
161
202
  case r.eventNames.loginAsync_begin:
162
- return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(H, { configurationName: e }) });
203
+ return /* @__PURE__ */ i(
204
+ P,
205
+ {
206
+ loadingComponent: y,
207
+ isLoading: A,
208
+ configurationName: e,
209
+ children: /* @__PURE__ */ i(H, { configurationName: e })
210
+ }
211
+ );
163
212
  case r.eventNames.loginAsync_error:
164
213
  case r.eventNames.loginCallbackAsync_error:
165
- return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(J, { configurationName: e }) });
214
+ return /* @__PURE__ */ i(
215
+ P,
216
+ {
217
+ loadingComponent: y,
218
+ isLoading: A,
219
+ configurationName: e,
220
+ children: /* @__PURE__ */ i(J, { configurationName: e })
221
+ }
222
+ );
166
223
  case r.eventNames.refreshTokensAsync_error:
167
224
  case r.eventNames.syncTokensAsync_error:
168
225
  case r.eventNames.logout_from_another_tab:
169
- return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(G, { configurationName: e }) });
226
+ return /* @__PURE__ */ i(
227
+ P,
228
+ {
229
+ loadingComponent: y,
230
+ isLoading: A,
231
+ configurationName: e,
232
+ children: /* @__PURE__ */ i(G, { configurationName: e })
233
+ }
234
+ );
170
235
  default:
171
- return /* @__PURE__ */ i(P, { loadingComponent: m, isLoading: A, configurationName: e, children: /* @__PURE__ */ i(
172
- fe,
236
+ return /* @__PURE__ */ i(
237
+ P,
173
238
  {
174
- redirect_uri: N.configuration.redirect_uri,
175
- silent_redirect_uri: N.configuration.silent_redirect_uri,
176
- silent_login_uri: N.configuration.silent_login_uri,
177
- callbackSuccessComponent: n,
178
- callbackErrorComponent: a,
179
- authenticatingComponent: o,
239
+ loadingComponent: y,
240
+ isLoading: A,
180
241
  configurationName: e,
181
- withCustomHistory: p,
182
- location: S ?? new M(),
183
- children: /* @__PURE__ */ i(ve, { loadingComponent: m, configurationName: e, children: t })
242
+ children: /* @__PURE__ */ i(
243
+ fe,
244
+ {
245
+ redirect_uri: N.configuration.redirect_uri,
246
+ silent_redirect_uri: N.configuration.silent_redirect_uri,
247
+ silent_login_uri: N.configuration.silent_login_uri,
248
+ callbackSuccessComponent: n,
249
+ callbackErrorComponent: a,
250
+ authenticatingComponent: o,
251
+ configurationName: e,
252
+ withCustomHistory: g,
253
+ location: S ?? new M(),
254
+ children: /* @__PURE__ */ i(ve, { loadingComponent: y, configurationName: e, children: t })
255
+ }
256
+ )
184
257
  }
185
- ) });
258
+ );
186
259
  }
187
- }, ge = ({ children: t, callbackPath: s = null, extras: e = null, configurationName: n = "default" }) => {
260
+ }, ge = ({
261
+ children: t,
262
+ callbackPath: s = null,
263
+ extras: e = null,
264
+ configurationName: n = "default"
265
+ }) => {
188
266
  const o = r.get, c = o(n);
189
267
  return v(() => {
190
268
  c.tokens || c.loginAsync(s, e);
191
- }, [n, s, e]), c.tokens ? /* @__PURE__ */ i(b, { children: t }) : null;
269
+ }, [n, s, e]), c.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
192
270
  }, Ee = (t, s = null, e = null, n = "default") => (o) => /* @__PURE__ */ i(ge, { callbackPath: s, extras: e, configurationName: n, children: /* @__PURE__ */ i(t, { ...o }) }), F = "default", U = (t, s) => {
193
271
  let e = !1;
194
272
  return t(s) && (e = t(s).tokens != null), e;
195
273
  }, Se = (t = F) => {
196
- const s = r.get, [e, n] = f(U(s, t));
274
+ const s = r.get, [e, n] = f(
275
+ U(s, t)
276
+ );
197
277
  return v(() => {
198
278
  let a = !0;
199
279
  const d = s(t);
@@ -204,7 +284,13 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
204
284
  return () => {
205
285
  a = !1, d.removeEventSubscription(u);
206
286
  };
207
- }, [t]), { login: (a = void 0, d = null, u = !1) => s(t).loginAsync(a, d, !1, void 0, u), logout: (a = void 0, d = null) => s(t).logoutAsync(a, d), renewTokens: async (a = null) => {
287
+ }, [t]), { login: (a = void 0, d = null, u = !1) => s(t).loginAsync(
288
+ a,
289
+ d,
290
+ !1,
291
+ void 0,
292
+ u
293
+ ), logout: (a = void 0, d = null) => s(t).logoutAsync(a, d), renewTokens: async (a = null) => {
208
294
  const d = await s(t).renewTokensAsync(a);
209
295
  return {
210
296
  // @ts-ignore
@@ -239,16 +325,21 @@ const Ne = (t = F) => {
239
325
  const c = s(t);
240
326
  if (c.tokens) {
241
327
  const a = c.tokens;
242
- n({ accessToken: a.accessToken, accessTokenPayload: a.accessTokenPayload });
328
+ n({
329
+ accessToken: a.accessToken,
330
+ accessTokenPayload: a.accessTokenPayload
331
+ });
243
332
  }
244
333
  const l = c.subscribeEvents((a, d) => {
245
334
  if ((a === r.eventNames.token_renewed || a === r.eventNames.token_aquired || 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) {
246
335
  const u = c.tokens;
247
- n(u != null ? {
248
- accessToken: u.accessToken,
249
- accessTokenPayload: u.accessTokenPayload,
250
- generateDemonstrationOfProofOfPossessionAsync: ye(c, u)
251
- } : q);
336
+ n(
337
+ u != null ? {
338
+ accessToken: u.accessToken,
339
+ accessTokenPayload: u.accessTokenPayload,
340
+ generateDemonstrationOfProofOfPossessionAsync: ye(c, u)
341
+ } : q
342
+ );
252
343
  }
253
344
  });
254
345
  return () => {
@@ -274,7 +365,9 @@ const Ne = (t = F) => {
274
365
  const l = c.subscribeEvents((a, d) => {
275
366
  if ((a === r.eventNames.token_renewed || a === r.eventNames.token_aquired || 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) {
276
367
  const u = c.tokens;
277
- n(u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y);
368
+ n(
369
+ u != null ? { idToken: u.idToken, idTokenPayload: u.idTokenPayload } : Y
370
+ );
278
371
  }
279
372
  });
280
373
  return () => {
@@ -291,17 +384,17 @@ const Ie = (t = "default", s = !1) => {
291
384
  }), [l, a] = f(n ? 1 : 0), [d, u] = f(n ? 1 : 0);
292
385
  v(() => {
293
386
  const h = r.get(t);
294
- let p = !0;
387
+ let g = !0;
295
388
  if (h && h.tokens) {
296
- const y = l === d;
297
- if (y && h.userInfo())
389
+ const p = l === d;
390
+ if (p && h.userInfo())
298
391
  return;
299
392
  c({
300
393
  ...o,
301
394
  status: "Loading user"
302
395
  /* Loading */
303
- }), h.userInfoAsync(!y, s).then((S) => {
304
- p && c({
396
+ }), h.userInfoAsync(!p, s).then((S) => {
397
+ g && c({
305
398
  user: S,
306
399
  status: "User loaded"
307
400
  /* Loaded */
@@ -317,15 +410,15 @@ const Ie = (t = "default", s = !1) => {
317
410
  status: "Unauthenticated"
318
411
  /* Unauthenticated */
319
412
  });
320
- const g = h.subscribeEvents((y) => {
321
- (y === r.eventNames.logout_from_another_tab || y === r.eventNames.logout_from_same_tab) && p && c({
413
+ const T = h.subscribeEvents((p) => {
414
+ (p === r.eventNames.logout_from_another_tab || p === r.eventNames.logout_from_same_tab) && g && c({
322
415
  user: null,
323
416
  status: "Unauthenticated"
324
417
  /* Unauthenticated */
325
418
  });
326
419
  });
327
420
  return () => {
328
- p = !1, h.removeEventSubscription(g);
421
+ g = !1, h.removeEventSubscription(T);
329
422
  };
330
423
  }, [l]);
331
424
  const _ = () => {
@@ -1 +1 @@
1
- (function(f,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,function(f,s,n,l){"use strict";const F="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=F,e=!1)=>o=>r=>{const{fetch:a}=I(t||r.fetch,c,e);return s.jsx(o,{...r,fetch:a})},I=(t=null,c=F,e=!1)=>{const o=t||window.fetch,r=n.OidcClient.get;return{fetch:l.useCallback((d,i)=>B(o,()=>r(c),e)(d,i),[o,c])}},U=()=>s.jsx("div",{className:"oidc-authenticating",children:s.jsxs("div",{className:"oidc-authenticating__container",children:[s.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),s.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>s.jsx("div",{className:"oidc-authenticating",children:s.jsxs("div",{className:"oidc-authenticating__container",children:[s.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),s.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).substr(2,6),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},a=c.createEvent("CustomEvent");return a.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),a.prototype=t.Event.prototype,a},H=(t,c,e)=>({replaceState:(o,r)=>{const a=e(),d=r||t.history.state;t.history.replaceState({key:a,state:d},null,o),t.dispatchEvent(c("popstate"))}}),Q=()=>H(window,G(window,document),$),M=()=>s.jsx("div",{className:"oidc-callback",children:s.jsxs("div",{className:"oidc-callback__container",children:[s.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),s.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,a]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const _=n.OidcClient.get;try{const{callbackPath:O}=await _(e).loginCallbackAsync();(o?o():Q()).replaceState(O||"/")}catch(O){u&&(console.warn(O),a(!0))}})(),()=>{u=!1}},[]);const d=t||U,i=c||M;return r?s.jsx(d,{configurationName:e}):s.jsx(i,{configurationName:e})},V=()=>s.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>s.jsx("div",{className:"oidc-serviceworker",children:s.jsxs("div",{className:"oidc-serviceworker__container",children:[s.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),s.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=()=>s.jsx("div",{className:"oidc-session-lost",children:s.jsxs("div",{className:"oidc-session-lost__container",children:[s.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),s.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{const e=n.OidcClient.get;e(t).silentLoginCallbackAsync()})()},[]),s.jsx(s.Fragment,{})),R=({configurationName:t})=>{const c=n.getParseQueryStringFromLocation(window.location.href),e=n.OidcClient.get,o=e(t);let r=null;for(const[a,d]of Object.entries(c))a==="state"||a==="scope"||(r===null&&(r={}),r[a]=d);return l.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,c.scope)},[]),s.jsx(s.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:c,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:a,configurationName:d,withCustomHistory:i=null,location:u})=>{const k=window?n.getPath(window.location.href):"",[_,O]=l.useState(k);l.useEffect(()=>{const v=()=>O(n.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const g=n.getPath(e);if(o&&_===n.getPath(o))return s.jsx(x,{configurationName:d});if(r&&_===n.getPath(r))return s.jsx(R,{configurationName:d});switch(_){case g:return s.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:i});default:return s.jsx(s.Fragment,{children:a})}},te=l.memo(ee),q={name:"",data:null},se=({loadingComponent:t,children:c,configurationName:e})=>{const[o,r]=l.useState(!0),a=n.OidcClient.get,d=a(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const i=t;return s.jsx(s.Fragment,{children:o?s.jsx(i,{configurationName:e}):s.jsx(s.Fragment,{children:c})})},T=({isLoading:t,loadingComponent:c,children:e,configurationName:o})=>{const r=c;return t?s.jsx(r,{configurationName:o,children:e}):s.jsx(s.Fragment,{children:e})},ne=({children:t,configuration:c,configurationName:e="default",callbackSuccessComponent:o=M,authenticatingComponent:r=K,loadingComponent:a=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:i=U,sessionLostComponent:u=Z,onSessionLost:k=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:O=null,withCustomHistory:g=null,onEvent:v=null,getFetch:y=null,location:P=null})=>{const w=(L="default")=>n.OidcClient.getOrCreate(y??n.getFetchDefault,P??new n.OidcLocation)(c,L),[fe,ke]=l.useState(!0),[he,S]=l.useState(q),[Oe,_e]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((h,p)=>{v&&v(e,h,p)});return()=>{w(e).removeEventSubscription(m)}},[e,v]),l.useEffect(()=>{const m=w(e).subscribeEvents((h,p)=>{if(h===n.OidcClient.eventNames.refreshTokensAsync_error||h===n.OidcClient.eventNames.syncTokensAsync_error){if(k!=null){k();return}S({name:h,data:p})}else if(h===n.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}S({name:h,data:p})}else h===n.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():h===n.OidcClient.eventNames.loginAsync_begin||h===n.OidcClient.eventNames.loginCallbackAsync_end||h===n.OidcClient.eventNames.loginAsync_error||h===n.OidcClient.eventNames.loginCallbackAsync_error?S({name:h,data:p}):h===n.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:h,data:p})});return _e(e),ke(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[c,e]);const ve=u,ge=r,b=a,ye=d,be=i,A=fe||Oe!==e,N=w(e);switch(he.name){case n.OidcClient.eventNames.service_worker_not_supported_by_browser:return s.jsx(T,{loadingComponent:b,isLoading:A,configurationName:e,children:s.jsx(ye,{configurationName:e})});case n.OidcClient.eventNames.loginAsync_begin:return s.jsx(T,{loadingComponent:b,isLoading:A,configurationName:e,children:s.jsx(ge,{configurationName:e})});case n.OidcClient.eventNames.loginAsync_error:case n.OidcClient.eventNames.loginCallbackAsync_error:return s.jsx(T,{loadingComponent:b,isLoading:A,configurationName:e,children:s.jsx(be,{configurationName:e})});case n.OidcClient.eventNames.refreshTokensAsync_error:case n.OidcClient.eventNames.syncTokensAsync_error:case n.OidcClient.eventNames.logout_from_another_tab:return s.jsx(T,{loadingComponent:b,isLoading:A,configurationName:e,children:s.jsx(ve,{configurationName:e})});default:return s.jsx(T,{loadingComponent:b,isLoading:A,configurationName:e,children:s.jsx(te,{redirect_uri:N.configuration.redirect_uri,silent_redirect_uri:N.configuration.silent_redirect_uri,silent_login_uri:N.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:i,authenticatingComponent:r,configurationName:e,withCustomHistory:g,location:P??new n.OidcLocation,children:s.jsx(se,{loadingComponent:b,configurationName:e,children:t})})})}},D=({children:t,callbackPath:c=null,extras:e=null,configurationName:o="default"})=>{const r=n.OidcClient.get,a=r(o);return l.useEffect(()=>{a.tokens||a.loginAsync(c,e)},[o,c,e]),a.tokens?s.jsx(s.Fragment,{children:t}):null},oe=(t,c=null,e=null,o="default")=>r=>s.jsx(D,{callbackPath:c,extras:e,configurationName:o,children:s.jsx(t,{...r})}),E="default",C=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},ce=(t=E)=>{const c=n.OidcClient.get,[e,o]=l.useState(C(c,t));return l.useEffect(()=>{let i=!0;const u=c(t);o(C(c,t));const k=u.subscribeEvents((_,O)=>{(_===n.OidcClient.eventNames.logout_from_another_tab||_===n.OidcClient.eventNames.logout_from_same_tab||_===n.OidcClient.eventNames.token_aquired)&&i&&o(C(c,t))});return()=>{i=!1,u.removeEventSubscription(k)}},[t]),{login:(i=void 0,u=null,k=!1)=>c(t).loginAsync(i,u,!1,void 0,k),logout:(i=void 0,u=null)=>c(t).logoutAsync(i,u),renewTokens:async(i=null)=>{const u=await c(t).renewTokensAsync(i);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const c=n.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,a)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,a):null}}return W};function ae(t,c){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,e,o,r):null}const ie=(t=E)=>{const c=n.OidcClient.get,[e,o]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const a=c(t);if(a.tokens){const i=a.tokens;o({accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload})}const d=a.subscribeEvents((i,u)=>{if((i===n.OidcClient.eventNames.token_renewed||i===n.OidcClient.eventNames.token_aquired||i===n.OidcClient.eventNames.logout_from_another_tab||i===n.OidcClient.eventNames.logout_from_same_tab||i===n.OidcClient.eventNames.refreshTokensAsync_error||i===n.OidcClient.eventNames.syncTokensAsync_error)&&r){const k=a.tokens;o(k!=null?{accessToken:k.accessToken,accessTokenPayload:k.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(a,k)}:W)}});return()=>{r=!1,a.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const c=n.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},de=(t=E)=>{const c=n.OidcClient.get,[e,o]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const a=c(t);if(a.tokens){const i=a.tokens;o({idToken:i.idToken,idTokenPayload:i.idTokenPayload})}const d=a.subscribeEvents((i,u)=>{if((i===n.OidcClient.eventNames.token_renewed||i===n.OidcClient.eventNames.token_aquired||i===n.OidcClient.eventNames.logout_from_another_tab||i===n.OidcClient.eventNames.logout_from_same_tab||i===n.OidcClient.eventNames.refreshTokensAsync_error||i===n.OidcClient.eventNames.syncTokensAsync_error)&&r){const k=a.tokens;o(k!=null?{idToken:k.idToken,idTokenPayload:k.idTokenPayload}:j)}});return()=>{r=!1,a.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=n.OidcClient.get(t).userInfo(),[r,a]=l.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[d,i]=l.useState(o?1:0),[u,k]=l.useState(o?1:0);l.useEffect(()=>{const O=n.OidcClient.get(t);let g=!0;if(O&&O.tokens){const y=d===u;if(y&&O.userInfo())return;a({...r,status:"Loading user"}),O.userInfoAsync(!y,c).then(P=>{g&&a({user:P,status:"User loaded"})}).catch(()=>a({...r,status:"Error loading user"})),k(d)}else a({user:null,status:"Unauthenticated"});const v=O.subscribeEvents(y=>{(y===n.OidcClient.eventNames.logout_from_another_tab||y===n.OidcClient.eventNames.logout_from_same_tab)&&g&&a({user:null,status:"Unauthenticated"})});return()=>{g=!1,O.removeEventSubscription(v)}},[d]);const _=()=>{i(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:_}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>n.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>n.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>n.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>n.TokenRenewMode}),f.OidcProvider=ne,f.OidcSecure=D,f.OidcUserStatus=Y,f.useOidc=ce,f.useOidcAccessToken=ie,f.useOidcFetch=I,f.useOidcIdToken=de,f.useOidcUser=ue,f.withOidcFetch=z,f.withOidcSecure=oe,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,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):(k=typeof globalThis<"u"?globalThis:k||self,n(k["react-oidc"]={},k.jsxRuntime,k.oidcClient,k.React))})(this,function(k,n,s,l){"use strict";const F="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},I=(t=null,c=F,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])}},U=()=>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),$),M=()=>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 _=s.OidcClient.get;try{const{callbackPath:O}=await _(e).loginCallbackAsync();(o?o():Q()).replaceState(O||"/")}catch(O){u&&(console.warn(O),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=c||M;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,_]=l.useState(u);l.useEffect(()=>{const v=()=>_(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const O=s.getPath(e);if(o&&f===s.getPath(o))return n.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return n.jsx(R,{configurationName:d});switch(f){case O:return n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a});default:return n.jsx(n.Fragment,{children:i})}},te=l.memo(ee),q={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=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:O=null,withCustomHistory:v=null,onEvent:T=null,getFetch:g=null,location:P=null})=>{const w=(N="default")=>s.OidcClient.getOrCreate(g??s.getFetchDefault,P??new s.OidcLocation)(c,N),[fe,ke]=l.useState(!0),[he,S]=l.useState(q),[Oe,_e]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{T&&T(e,h,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{if(h===s.OidcClient.eventNames.refreshTokensAsync_error||h===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:h,data:b})}else if(h===s.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}S({name:h,data:b})}else h===s.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():h===s.OidcClient.eventNames.loginAsync_begin||h===s.OidcClient.eventNames.loginCallbackAsync_end||h===s.OidcClient.eventNames.loginAsync_error||h===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:h,data:b}):h===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:h,data:b})});return _e(e),ke(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[c,e]);const ve=u,ge=r,y=i,ye=d,be=a,A=fe||Oe!==e,L=w(e);switch(he.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:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:P??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},D=({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},oe=(t,c=null,e=null,o="default")=>r=>n.jsx(D,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),E="default",C=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},ce=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(C(c,t));return l.useEffect(()=>{let a=!0;const u=c(t);o(C(c,t));const f=u.subscribeEvents((_,O)=>{(_===s.OidcClient.eventNames.logout_from_another_tab||_===s.OidcClient.eventNames.logout_from_same_tab||_===s.OidcClient.eventNames.token_aquired)&&a&&o(C(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=null,f=!1)=>c(t).loginAsync(a,u,!1,void 0,f),logout:(a=void 0,u=null)=>c(t).logoutAsync(a,u),renewTokens:async(a=null)=>{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=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_aquired||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=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({idToken:a.idToken,idTokenPayload:a.idTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_aquired||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 O=s.OidcClient.get(t);let v=!0;if(O&&O.tokens){const g=d===u;if(g&&O.userInfo())return;i({...r,status:"Loading user"}),O.userInfoAsync(!g,c).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=O.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,O.removeEventSubscription(T)}},[d]);const _=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:_}};Object.defineProperty(k,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(k,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(k,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(k,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),k.OidcProvider=ne,k.OidcSecure=D,k.OidcUserStatus=Y,k.useOidc=ce,k.useOidcAccessToken=ae,k.useOidcFetch=I,k.useOidcIdToken=de,k.useOidcUser=ue,k.withOidcFetch=z,k.withOidcSecure=oe,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.22.18",
3
+ "version": "7.22.19",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -40,8 +40,8 @@
40
40
  "lint": "eslint src"
41
41
  },
42
42
  "dependencies": {
43
- "@axa-fr/oidc-client-service-worker": "7.22.18",
44
- "@axa-fr/oidc-client": "7.22.18"
43
+ "@axa-fr/oidc-client-service-worker": "7.22.19",
44
+ "@axa-fr/oidc-client": "7.22.19"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0"
@@ -7,27 +7,50 @@ export interface ComponentWithOidcFetchProps {
7
7
 
8
8
  const defaultConfigurationName = 'default';
9
9
 
10
- const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => OidcClient | null, demonstrating_proof_of_possession: boolean = false) => async (...params: Parameters<Fetch>) => {
11
- const oidc = getOidcWithConfigurationName();
12
- const newFetch = oidc.fetchWithTokens(fetch, demonstrating_proof_of_possession);
13
- return await newFetch(...params);
14
- };
10
+ const fetchWithToken =
11
+ (
12
+ fetch: Fetch,
13
+ getOidcWithConfigurationName: () => OidcClient | null,
14
+ demonstrating_proof_of_possession: boolean = false,
15
+ ) =>
16
+ async (...params: Parameters<Fetch>) => {
17
+ const oidc = getOidcWithConfigurationName();
18
+ const newFetch = oidc.fetchWithTokens(fetch, demonstrating_proof_of_possession);
19
+ return await newFetch(...params);
20
+ };
15
21
 
16
- export const withOidcFetch = (fetch: Fetch = null, configurationName = defaultConfigurationName, demonstrating_proof_of_possession:boolean=false) => (
17
- WrappedComponent,
18
- ) => (props: ComponentWithOidcFetchProps) => {
19
- const { fetch: newFetch } = useOidcFetch(fetch || props.fetch, configurationName, demonstrating_proof_of_possession);
20
- return <WrappedComponent {...props} fetch={newFetch} />;
21
- };
22
+ export const withOidcFetch =
23
+ (
24
+ fetch: Fetch = null,
25
+ configurationName = defaultConfigurationName,
26
+ demonstrating_proof_of_possession: boolean = false,
27
+ ) =>
28
+ WrappedComponent =>
29
+ (props: ComponentWithOidcFetchProps) => {
30
+ const { fetch: newFetch } = useOidcFetch(
31
+ fetch || props.fetch,
32
+ configurationName,
33
+ demonstrating_proof_of_possession,
34
+ );
35
+ return <WrappedComponent {...props} fetch={newFetch} />;
36
+ };
22
37
 
23
- export const useOidcFetch = (fetch: Fetch = null, configurationName = defaultConfigurationName, demonstrating_proof_of_possession:boolean=false) => {
38
+ export const useOidcFetch = (
39
+ fetch: Fetch = null,
40
+ configurationName = defaultConfigurationName,
41
+ demonstrating_proof_of_possession: boolean = false,
42
+ ) => {
24
43
  const previousFetch = fetch || window.fetch;
25
44
  const getOidc = OidcClient.get;
26
45
 
27
46
  const memoizedFetchCallback = useCallback(
28
47
  (input: RequestInfo | URL, init?: RequestInit) => {
29
48
  const getOidcWithConfigurationName = () => getOidc(configurationName);
30
- const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName, demonstrating_proof_of_possession);
49
+ const newFetch = fetchWithToken(
50
+ previousFetch,
51
+ getOidcWithConfigurationName,
52
+ demonstrating_proof_of_possession,
53
+ );
31
54
  return newFetch(input, init);
32
55
  },
33
56
  [previousFetch, configurationName],