@axa-fr/react-oidc 7.27.13 → 7.27.14

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