@axa-fr/react-oidc 7.27.13 → 7.27.15

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;AA+DF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA4NjE,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 = (e, n) => e === t.eventNames.token_acquired || e === t.eventNames.token_renewed || e === t.eventNames.loginCallbackAsync_end ? !0 : e === t.eventNames.tryKeepExistingSessionAsync_end ? n?.success === !0 : !1, U = ({ 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(!1), [I, U] = 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) => {
181
- if (e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
203
+ }, [i, C]), d(() => {
204
+ let e = E(i).subscribeEvents((e, r) => {
205
+ if (H(e, r) && F(!0), 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,92 @@ 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
+ U(i);
206
230
  }), () => {
207
- T(i).removeEventSubscription(e), O(I);
231
+ E(i).removeEventSubscription(e), k(R), F(!1);
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 || A || E(i)?.tokens != null || !(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,
242
+ A,
218
243
  i,
219
244
  n
220
245
  ]);
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,
246
+ let W = m, G = s, K = c, q = l, J = u, Y = f, X = I !== i, Z = E(i);
247
+ switch (O.name) {
248
+ case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ h(B, {
249
+ loadingComponent: K,
250
+ isLoading: X,
226
251
  configurationName: i,
227
- children: /* @__PURE__ */ h(W, { configurationName: i })
252
+ children: /* @__PURE__ */ h(J, { configurationName: i })
228
253
  });
229
- case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(R, {
230
- loadingComponent: H,
231
- isLoading: K,
254
+ case t.eventNames.loginAsync_begin: return /* @__PURE__ */ h(B, {
255
+ loadingComponent: K,
256
+ isLoading: X,
232
257
  configurationName: i,
233
- children: /* @__PURE__ */ h(V, { configurationName: i })
258
+ children: /* @__PURE__ */ h(G, { configurationName: i })
234
259
  });
235
- case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ h(R, {
236
- loadingComponent: H,
237
- isLoading: K,
260
+ case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ h(B, {
261
+ loadingComponent: K,
262
+ isLoading: X,
238
263
  configurationName: i,
239
- children: /* @__PURE__ */ h(U, { configurationName: i })
264
+ children: /* @__PURE__ */ h(q, { configurationName: i })
240
265
  });
241
266
  case t.eventNames.loginAsync_error:
242
- case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(R, {
243
- loadingComponent: H,
244
- isLoading: K,
267
+ case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ h(B, {
268
+ loadingComponent: K,
269
+ isLoading: X,
245
270
  configurationName: i,
246
- children: /* @__PURE__ */ h(G, { configurationName: i })
271
+ children: /* @__PURE__ */ h(Y, { configurationName: i })
247
272
  });
248
273
  case t.eventNames.refreshTokensAsync_error:
249
274
  case t.eventNames.syncTokensAsync_error:
250
- case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(R, {
251
- loadingComponent: H,
252
- isLoading: K,
275
+ case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ h(B, {
276
+ loadingComponent: K,
277
+ isLoading: X,
253
278
  configurationName: i,
254
- children: /* @__PURE__ */ h(B, { configurationName: i })
279
+ children: /* @__PURE__ */ h(W, { configurationName: i })
255
280
  });
256
- default: return /* @__PURE__ */ h(R, {
257
- loadingComponent: H,
258
- isLoading: K,
281
+ default: return /* @__PURE__ */ h(B, {
282
+ loadingComponent: K,
283
+ isLoading: X,
259
284
  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,
285
+ children: /* @__PURE__ */ h(L, {
286
+ redirect_uri: Z.configuration.redirect_uri,
287
+ silent_redirect_uri: Z.configuration.silent_redirect_uri,
288
+ silent_login_uri: Z.configuration.silent_login_uri,
264
289
  callbackSuccessComponent: a,
265
290
  callbackErrorComponent: f,
266
291
  authenticatingComponent: s,
267
292
  configurationName: i,
268
293
  withCustomHistory: y,
269
- location: w ?? new r(),
270
- children: /* @__PURE__ */ h(L, {
271
- loadingComponent: H,
294
+ navigateAfterCallback: b,
295
+ location: T ?? new r(),
296
+ children: /* @__PURE__ */ h(z, {
297
+ loadingComponent: K,
272
298
  configurationName: i,
273
299
  children: e
274
300
  })
275
301
  })
276
302
  });
277
303
  }
278
- }, V = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
304
+ }, W = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
279
305
  let a = t.get, o = a(i);
280
306
  return d(() => {
281
307
  o.tokens || o.loginAsync(n, r);
@@ -284,19 +310,19 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
284
310
  n,
285
311
  r
286
312
  ]), o.tokens ? /* @__PURE__ */ h(m, { children: e }) : null;
287
- }, H = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(V, {
313
+ }, G = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ h(W, {
288
314
  callbackPath: t,
289
315
  extras: n,
290
316
  configurationName: r,
291
317
  children: /* @__PURE__ */ h(e, { ...i })
292
- }), U = "default", W = (e, t) => {
318
+ }), K = "default", q = (e, t) => {
293
319
  let n = !1;
294
320
  return e(t) && (n = e(t).tokens != null), n;
295
- }, G = (e = U) => {
296
- let n = t.get, [r, i] = p(() => W(n, e));
321
+ }, J = (e = K) => {
322
+ let n = t.get, [r, i] = p(() => q(n, e));
297
323
  return d(() => {
298
324
  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));
325
+ (a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(q(n, e));
300
326
  });
301
327
  return () => {
302
328
  r = !1, a.removeEventSubscription(o);
@@ -315,10 +341,10 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
315
341
  },
316
342
  isAuthenticated: r
317
343
  };
318
- }, K = {
344
+ }, Y = {
319
345
  accessToken: null,
320
346
  accessTokenPayload: null
321
- }, q = (e) => {
347
+ }, X = (e) => {
322
348
  let n = t.get, r = n(e);
323
349
  if (r.tokens) {
324
350
  let e = r.tokens;
@@ -328,21 +354,21 @@ var _ = "default", v = (e, t, n = !1) => async (...r) => await t().fetchWithToke
328
354
  generateDemonstrationOfProofOfPossessionAsync: r.configuration.demonstrating_proof_of_possession ? (t, n) => r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken, t, n) : null
329
355
  };
330
356
  }
331
- return K;
357
+ return Y;
332
358
  };
333
- function J(e, t) {
359
+ function Z(e, t) {
334
360
  return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
335
361
  }
336
- var Y = (e = U) => {
337
- let n = t.get, [r, i] = p(() => q(e));
362
+ var Q = (e = K) => {
363
+ let n = t.get, [r, i] = p(() => X(e));
338
364
  return d(() => {
339
365
  let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
340
366
  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
367
  let e = a.tokens;
342
- i(e == null ? K : {
368
+ i(e == null ? Y : {
343
369
  accessToken: e.accessToken,
344
370
  accessTokenPayload: e.accessTokenPayload,
345
- generateDemonstrationOfProofOfPossessionAsync: J(a, e)
371
+ generateDemonstrationOfProofOfPossessionAsync: Z(a, e)
346
372
  });
347
373
  }
348
374
  });
@@ -350,10 +376,10 @@ var Y = (e = U) => {
350
376
  r = !1, a.removeEventSubscription(o);
351
377
  };
352
378
  }, [e]), r;
353
- }, X = {
379
+ }, $ = {
354
380
  idToken: null,
355
381
  idTokenPayload: null
356
- }, Z = (e) => {
382
+ }, ee = (e) => {
357
383
  let n = t.get, r = n(e);
358
384
  if (r.tokens) {
359
385
  let e = r.tokens;
@@ -362,14 +388,14 @@ var Y = (e = U) => {
362
388
  idTokenPayload: e.idTokenPayload
363
389
  };
364
390
  }
365
- return X;
366
- }, Q = (e = U) => {
367
- let n = t.get, [r, i] = p(() => Z(e));
391
+ return $;
392
+ }, te = (e = K) => {
393
+ let n = t.get, [r, i] = p(() => ee(e));
368
394
  return d(() => {
369
395
  let r = !0, a = n(e), o = a.subscribeEvents((e, n) => {
370
396
  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
397
  let e = a.tokens;
372
- i(e == null ? X : {
398
+ i(e == null ? $ : {
373
399
  idToken: e.idToken,
374
400
  idTokenPayload: e.idTokenPayload
375
401
  });
@@ -379,9 +405,9 @@ var Y = (e = U) => {
379
405
  r = !1, a.removeEventSubscription(o);
380
406
  };
381
407
  }, [e]), r;
382
- }, $ = /* @__PURE__ */ function(e) {
408
+ }, ne = /* @__PURE__ */ function(e) {
383
409
  return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
384
- }({}), ee = (e = "default", n = !1) => {
410
+ }({}), re = (e = "default", n = !1) => {
385
411
  let r = t.get(e).userInfo(), [i, a] = p({
386
412
  user: r,
387
413
  status: r ? "User loaded" : "Unauthenticated"
@@ -433,4 +459,4 @@ var Y = (e = U) => {
433
459
  };
434
460
  };
435
461
  //#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 };
462
+ export { e as OidcClient, n as OidcLocation, U as OidcProvider, W as OidcSecure, ne as OidcUserStatus, i as TokenAutomaticRenewMode, a as TokenRenewMode, J as useOidc, Q as useOidcAccessToken, b as useOidcFetch, te as useOidcIdToken, re as useOidcUser, y as withOidcFetch, G as withOidcSecure };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?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=(e,n)=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end?!0:e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end?n?.success===!0:!1,L=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=T,loadingTimeoutComponent:l=E,serviceWorkerNotSupportedComponent:u=D,authenticatingErrorComponent:d=h,sessionLostComponent:f=O,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:b=null,getFetch:S=null,location:C=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let w=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,A]=(0,n.useState)(M),[L,R]=(0,n.useState)(!1),[z,B]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,t)=>{b&&b(a,e,t)});return()=>{w(a).removeEventSubscription(e)}},[a,b]),(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,n)=>{if(I(e,n)&&R(!0),e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}A({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}A({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?_?.():(e===t.OidcClient.eventNames.loadingTimeout_error||e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&A({name:e,data:n})});return queueMicrotask(()=>{B(a)}),()=>{w(a).removeEventSubscription(e),A(M),R(!1)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||L||w(a)?.tokens!=null||!(k.name===``||k.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{w(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,navigateAfterCallback:y,location:C??new t.OidcLocation,children:(0,r.jsx)(N,{loadingComponent:U,configurationName:a,children:e})})})}},R=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.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},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=`default`,V=(e,t)=>{let n=!1;return e(t)&&(n=e(t).tokens!=null),n},H=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>V(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(V(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}},U={accessToken:null,accessTokenPayload:null},W=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 U};function G(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var K=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>W(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?U:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:G(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},q={idToken:null,idTokenPayload:null},J=e=>{let n=t.OidcClient.get,r=n(e);if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return q},Y=(e=B)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>J(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?q:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},X=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=L,e.OidcSecure=R,e.OidcUserStatus=X,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),e.useOidc=H,e.useOidcAccessToken=K,e.useOidcFetch=m,e.useOidcIdToken=Y,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=z});
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.15",
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.15",
44
+ "@axa-fr/oidc-client-service-worker": "7.27.15"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
@@ -14,30 +14,30 @@ const mockRemoveEventSubscription = vi.fn(id => {
14
14
  mockEventSubscribers = mockEventSubscribers.filter(e => e.id !== id);
15
15
  });
16
16
 
17
+ const mockOidcInstance: {
18
+ subscribeEvents: typeof mockSubscribeEvents;
19
+ removeEventSubscription: typeof mockRemoveEventSubscription;
20
+ publishEvent: typeof mockPublishEvent;
21
+ configuration: Record<string, string>;
22
+ tryKeepExistingSessionAsync: ReturnType<typeof vi.fn>;
23
+ tokens: unknown;
24
+ } = {
25
+ subscribeEvents: mockSubscribeEvents,
26
+ removeEventSubscription: mockRemoveEventSubscription,
27
+ publishEvent: mockPublishEvent,
28
+ configuration: {
29
+ redirect_uri: 'http://localhost/callback',
30
+ silent_redirect_uri: 'http://localhost/silent-callback',
31
+ silent_login_uri: 'http://localhost/silent-login',
32
+ },
33
+ tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
34
+ tokens: null,
35
+ };
36
+
17
37
  vi.mock('@axa-fr/oidc-client', () => ({
18
38
  OidcClient: {
19
- getOrCreate: vi.fn(() => () => ({
20
- subscribeEvents: mockSubscribeEvents,
21
- removeEventSubscription: mockRemoveEventSubscription,
22
- publishEvent: mockPublishEvent,
23
- configuration: {
24
- redirect_uri: 'http://localhost/callback',
25
- silent_redirect_uri: 'http://localhost/silent-callback',
26
- silent_login_uri: 'http://localhost/silent-login',
27
- },
28
- tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
29
- })),
30
- get: vi.fn(() => ({
31
- subscribeEvents: mockSubscribeEvents,
32
- removeEventSubscription: mockRemoveEventSubscription,
33
- publishEvent: mockPublishEvent,
34
- configuration: {
35
- redirect_uri: 'http://localhost/callback',
36
- silent_redirect_uri: 'http://localhost/silent-callback',
37
- silent_login_uri: 'http://localhost/silent-login',
38
- },
39
- tryKeepExistingSessionAsync: vi.fn().mockResolvedValue(true),
40
- })),
39
+ getOrCreate: vi.fn(() => () => mockOidcInstance),
40
+ get: vi.fn(() => mockOidcInstance),
41
41
  eventNames: {
42
42
  service_worker_not_supported_by_browser: 'service_worker_not_supported_by_browser',
43
43
  token_acquired: 'token_acquired',
@@ -97,6 +97,7 @@ describe('OidcProvider loading timeout', () => {
97
97
  vi.useFakeTimers();
98
98
  vi.clearAllMocks();
99
99
  mockEventSubscribers = [];
100
+ mockOidcInstance.tokens = null;
100
101
  });
101
102
 
102
103
  afterEach(() => {
@@ -257,6 +258,126 @@ describe('OidcProvider loading timeout', () => {
257
258
  expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 30_000 });
258
259
  });
259
260
 
261
+ it('should NOT fire loadingTimeout_error after a silent session restore when authenticated', async () => {
262
+ render(
263
+ <OidcProvider
264
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 500 }}
265
+ configurationName="default"
266
+ >
267
+ <div>App</div>
268
+ </OidcProvider>,
269
+ );
270
+
271
+ act(() => {
272
+ vi.advanceTimersByTime(100);
273
+ });
274
+
275
+ // Simulate a successful silent session restore (no loginCallbackAsync_end is emitted).
276
+ act(() => {
277
+ mockEventSubscribers.forEach(sub =>
278
+ sub.func('tryKeepExistingSessionAsync_end', { success: true }),
279
+ );
280
+ });
281
+
282
+ mockPublishEvent.mockClear();
283
+
284
+ act(() => {
285
+ vi.advanceTimersByTime(10_000);
286
+ });
287
+
288
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
289
+ });
290
+
291
+ it('should still fire loadingTimeout_error when silent session restore reports no existing session', async () => {
292
+ render(
293
+ <OidcProvider
294
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 300 }}
295
+ configurationName="default"
296
+ >
297
+ <div>App</div>
298
+ </OidcProvider>,
299
+ );
300
+
301
+ act(() => {
302
+ mockEventSubscribers.forEach(sub =>
303
+ sub.func('tryKeepExistingSessionAsync_end', { success: false }),
304
+ );
305
+ });
306
+
307
+ mockPublishEvent.mockClear();
308
+
309
+ act(() => {
310
+ vi.advanceTimersByTime(300);
311
+ });
312
+
313
+ expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 300 });
314
+ });
315
+
316
+ it('should NOT fire loadingTimeout_error when token_acquired fires before the deadline', async () => {
317
+ render(
318
+ <OidcProvider
319
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 400 }}
320
+ configurationName="default"
321
+ >
322
+ <div>App</div>
323
+ </OidcProvider>,
324
+ );
325
+
326
+ act(() => {
327
+ mockEventSubscribers.forEach(sub => sub.func('token_acquired', {}));
328
+ });
329
+
330
+ mockPublishEvent.mockClear();
331
+
332
+ act(() => {
333
+ vi.advanceTimersByTime(10_000);
334
+ });
335
+
336
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
337
+ });
338
+
339
+ it('should NOT fire loadingTimeout_error when token_renewed fires before the deadline', async () => {
340
+ render(
341
+ <OidcProvider
342
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 400 }}
343
+ configurationName="default"
344
+ >
345
+ <div>App</div>
346
+ </OidcProvider>,
347
+ );
348
+
349
+ act(() => {
350
+ mockEventSubscribers.forEach(sub => sub.func('token_renewed', {}));
351
+ });
352
+
353
+ mockPublishEvent.mockClear();
354
+
355
+ act(() => {
356
+ vi.advanceTimersByTime(10_000);
357
+ });
358
+
359
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
360
+ });
361
+
362
+ it('should NOT arm the watchdog when the OIDC client mounts already authenticated', async () => {
363
+ mockOidcInstance.tokens = { accessToken: 'existing-token' };
364
+
365
+ render(
366
+ <OidcProvider
367
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 100 }}
368
+ configurationName="default"
369
+ >
370
+ <div>App</div>
371
+ </OidcProvider>,
372
+ );
373
+
374
+ act(() => {
375
+ vi.advanceTimersByTime(60_000);
376
+ });
377
+
378
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
379
+ });
380
+
260
381
  it('should propagate loadingTimeout_error through onEvent callback', async () => {
261
382
  const onEvent = vi.fn();
262
383
 
@@ -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;
@@ -88,6 +89,30 @@ const Switch = ({ isLoading, loadingComponent, children, configurationName }) =>
88
89
 
89
90
  const DEFAULT_LOADING_TIMEOUT_MS = 30_000;
90
91
 
92
+ /**
93
+ * Returns true when an event signals that the OIDC client has reached an
94
+ * authenticated, idle state and the loading watchdog should be disarmed.
95
+ *
96
+ * The default `event.name === ''` state in {@link OidcProvider} is overloaded:
97
+ * it represents both "not started yet" and "done and idle". A silent session
98
+ * restore via `tryKeepExistingSessionAsync` does not emit
99
+ * `loginCallbackAsync_end`, so without these explicit ready signals the
100
+ * watchdog would fire against a fully authenticated app.
101
+ */
102
+ const isReadySignal = (name: string, data: unknown): boolean => {
103
+ if (
104
+ name === OidcClient.eventNames.token_acquired ||
105
+ name === OidcClient.eventNames.token_renewed ||
106
+ name === OidcClient.eventNames.loginCallbackAsync_end
107
+ ) {
108
+ return true;
109
+ }
110
+ if (name === OidcClient.eventNames.tryKeepExistingSessionAsync_end) {
111
+ return (data as { success?: boolean } | null)?.success === true;
112
+ }
113
+ return false;
114
+ };
115
+
91
116
  export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
92
117
  children,
93
118
  configuration,
@@ -103,6 +128,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
103
128
  onLogoutFromAnotherTab = null,
104
129
  onLogoutFromSameTab = null,
105
130
  withCustomHistory = null,
131
+ navigateAfterCallback = null,
106
132
  onEvent = null,
107
133
  getFetch = null,
108
134
  location = null,
@@ -122,6 +148,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
122
148
 
123
149
  const loading = false;
124
150
  const [event, setEvent] = useState(defaultEventState);
151
+ const [isAuthenticatedAndIdle, setIsAuthenticatedAndIdle] = useState<boolean>(false);
125
152
  const [currentConfigurationName, setConfigurationName] = useState(configurationName);
126
153
 
127
154
  useEffect(() => {
@@ -140,6 +167,9 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
140
167
  useEffect(() => {
141
168
  const oidc = getOidc(configurationName);
142
169
  const newSubscriptionId = oidc.subscribeEvents((name, data) => {
170
+ if (isReadySignal(name, data)) {
171
+ setIsAuthenticatedAndIdle(true);
172
+ }
143
173
  if (
144
174
  name === OidcClient.eventNames.refreshTokensAsync_error ||
145
175
  name === OidcClient.eventNames.syncTokensAsync_error
@@ -185,6 +215,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
185
215
  const previousOidc = getOidc(configurationName);
186
216
  previousOidc.removeEventSubscription(newSubscriptionId);
187
217
  setEvent(defaultEventState);
218
+ setIsAuthenticatedAndIdle(false);
188
219
  };
189
220
  }, [configuration, configurationName]);
190
221
 
@@ -193,16 +224,24 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
193
224
  if (timeoutMs <= 0) {
194
225
  return;
195
226
  }
227
+ if (isAuthenticatedAndIdle) {
228
+ return;
229
+ }
230
+ const oidcInstance = getOidc(configurationName);
231
+ if (oidcInstance?.tokens != null) {
232
+ return;
233
+ }
196
234
  const isStuck = event.name === '' || event.name === OidcClient.eventNames.loginAsync_begin;
197
235
  if (!isStuck) {
198
236
  return;
199
237
  }
200
238
  const timeoutId = setTimeout(() => {
201
- const oidcInstance = getOidc(configurationName);
202
- oidcInstance.publishEvent(OidcClient.eventNames.loadingTimeout_error, { timeoutMs });
239
+ getOidc(configurationName).publishEvent(OidcClient.eventNames.loadingTimeout_error, {
240
+ timeoutMs,
241
+ });
203
242
  }, timeoutMs);
204
243
  return () => clearTimeout(timeoutId);
205
- }, [event.name, configurationName, configuration]);
244
+ }, [event.name, isAuthenticatedAndIdle, configurationName, configuration]);
206
245
 
207
246
  const SessionLostComponent = sessionLostComponent;
208
247
  const AuthenticatingComponent = authenticatingComponent;
@@ -284,6 +323,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
284
323
  authenticatingComponent={authenticatingComponent}
285
324
  configurationName={configurationName}
286
325
  withCustomHistory={withCustomHistory}
326
+ navigateAfterCallback={navigateAfterCallback}
287
327
  location={location ?? new OidcLocation()}
288
328
  >
289
329
  <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';