@axa-fr/react-oidc 7.27.19 → 7.29.2

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.
package/README.md CHANGED
@@ -173,6 +173,7 @@ const configuration = {
173
173
  silent_redirect_uri: window.location.origin + '/authentication/silent-callback',
174
174
  scope: 'openid profile email api offline_access', // offline_access scope allow your client to retrieve the refresh_token
175
175
  authority: 'https://demo.duendesoftware.com',
176
+ par: 'auto',
176
177
  service_worker_relative_url: '/OidcServiceWorker.js', // just comment that line to disable service worker mode
177
178
  service_worker_only: false,
178
179
  demonstrating_proof_of_possession: false,
@@ -219,6 +220,8 @@ const configuration = {
219
220
  userinfo_endpoint: String,
220
221
  end_session_endpoint: String,
221
222
  revocation_endpoint: String,
223
+ pushed_authorization_request_endpoint: String,
224
+ require_pushed_authorization_requests: Boolean,
222
225
  check_session_iframe: String,
223
226
  issuer: String,
224
227
  },
@@ -233,6 +236,8 @@ const configuration = {
233
236
  withCustomHistory: Function, // Override history modification, return an instance with replaceState(url, stateHistory) implemented (like History.replaceState())
234
237
  authority_time_cache_wellknowurl_in_second: 60 * 60, // Time to cache in seconds of the openid well-known URL, default is 1 hour
235
238
  authority_timeout_wellknowurl_in_millisecond: 10000, // Timeout in milliseconds of the openid well-known URL, default is 10 seconds, then an error is thrown
239
+ par: 'disabled' | 'auto' | 'required', // Pushed Authorization Requests mode, default is 'disabled'
240
+ par_request_timeout: Number, // PAR endpoint timeout in milliseconds, default is 10000
236
241
  monitor_session: Boolean, // Add OpenID monitor session, default is false (more information https://openid.net/specs/openid-connect-session-1_0.html), if you need to set it to true consider https://infi.nl/nieuws/spa-necromancy/
237
242
  onLogoutFromAnotherTab: Function, // Optional, can be set to override the default behavior, this function is triggered when a user with the same subject is logged out from another tab when session_monitor is active
238
243
  onLogoutFromSameTab: Function, // Optional, can be set to override the default behavior, this function is triggered when a user is logged out from the same tab when session_monitor is active
@@ -279,6 +284,29 @@ const defaultDemonstratingProofOfPossessionConfiguration: DemonstratingProofOfPo
279
284
 
280
285
  ```
281
286
 
287
+ ### Pushed Authorization Requests (PAR)
288
+
289
+ PAR is configured on the nested OIDC `configuration` object:
290
+
291
+ ```tsx
292
+ const configuration = {
293
+ client_id: 'spa-client',
294
+ redirect_uri: `${window.location.origin}/authentication/callback`,
295
+ scope: 'openid profile',
296
+ authority: 'https://issuer.example.com',
297
+ par: 'auto', // 'disabled' (default), 'auto', or 'required'
298
+ };
299
+ ```
300
+
301
+ `auto` uses the discovered `pushed_authorization_request_endpoint` when it is
302
+ available. `required` fails before navigation if no endpoint is available.
303
+ Once PAR is selected, a PAR endpoint error is surfaced and never silently
304
+ downgraded. Browser deployments require the issuer's PAR endpoint to allow
305
+ CORS from the application origin. See the
306
+ [`@axa-fr/oidc-client` PAR documentation](../oidc-client/README.md#pushed-authorization-requests-par)
307
+ for complete mode semantics, custom authority metadata, error handling, and
308
+ security guidance.
309
+
282
310
  ## How to consume
283
311
 
284
312
  > **Note (issue #1679):** `useOidc`, `useOidcUser`, `useOidcAccessToken` and
@@ -663,6 +691,7 @@ const configuration = {
663
691
  silent_redirect_uri: 'http://localhost:3001/#authentication/silent-callback', // Optional activate silent-login that use cookies between OIDC server and client javascript to restore the session
664
692
  scope: 'openid profile email api offline_access',
665
693
  authority: 'https://demo.duendesoftware.com',
694
+ par: 'auto',
666
695
  };
667
696
 
668
697
  const onEvent = (configurationName, eventName, data) => {
@@ -712,6 +741,7 @@ export const configurationIdentityServerWithHash = {
712
741
  silent_redirect_uri: window.location.origin + '#authentication-silent-callback',
713
742
  scope: 'openid profile email api offline_access',
714
743
  authority: 'https://demo.duendesoftware.com',
744
+ par: 'auto',
715
745
  refresh_time_before_tokens_expiration_in_second: 70,
716
746
  service_worker_relative_url: '/OidcServiceWorker.js',
717
747
  service_worker_only: false,
@@ -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,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
+ {"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;AAoDF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CA8NjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { OidcProvider } from './OidcProvider.js';
4
4
  export { OidcSecure, withOidcSecure } from './OidcSecure.js';
5
5
  export { useOidc, useOidcAccessToken, useOidcIdToken } from './ReactOidc.js';
6
6
  export { OidcUserStatus, useOidcUser } from './User.js';
7
- export type { AuthorityConfiguration, Fetch, ILOidcLocation, OidcConfiguration, StringMap, } from '@axa-fr/oidc-client';
7
+ export type { AuthorityConfiguration, Fetch, ILOidcLocation, OidcConfiguration, OidcErrorOptions, OidcErrorPhase, PushedAuthorizationRequestMode, StringMap, } from '@axa-fr/oidc-client';
8
8
  export type { OidcUserInfo } from '@axa-fr/oidc-client';
9
- export { isOidcStateError, OidcClient, OidcLocation, OidcStateError, OidcStateErrorCode, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client';
9
+ export { isOidcError, isOidcStateError, isPushedAuthorizationRequestError, OidcClient, OidcError, OidcErrorCode, OidcLocation, OidcStateError, OidcStateErrorCode, PushedAuthorizationRequestError, PushedAuthorizationRequestErrorCode, TokenAutomaticRenewMode, TokenRenewMode, } from '@axa-fr/oidc-client';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,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,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,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,gBAAgB,EAChB,cAAc,EACd,8BAA8B,EAC9B,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,iCAAiC,EACjC,UAAU,EACV,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,+BAA+B,EAC/B,mCAAmC,EACnC,uBAAuB,EACvB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,45 +1,45 @@
1
- import { OidcClient as e, OidcClient as t, OidcLocation as n, OidcLocation as r, OidcStateError as i, OidcStateErrorCode as a, TokenAutomaticRenewMode as o, TokenRenewMode as s, getFetchDefault as c, getParseQueryStringFromLocation as l, getPath as u, isOidcStateError as d } from "@axa-fr/oidc-client";
2
- import f, { useCallback as p, useEffect as m, useRef as h, useState as g } from "react";
3
- import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
1
+ import { OidcClient as e, OidcClient as t, OidcError as n, OidcErrorCode as r, OidcLocation as i, OidcLocation as a, OidcStateError as o, OidcStateErrorCode as s, PushedAuthorizationRequestError as c, PushedAuthorizationRequestErrorCode as l, TokenAutomaticRenewMode as u, TokenRenewMode as d, getFetchDefault as ee, getParseQueryStringFromLocation as f, getPath as p, isOidcError as m, isOidcStateError as h, isPushedAuthorizationRequestError as g } from "@axa-fr/oidc-client";
2
+ import _, { useCallback as v, useEffect as y, useRef as b, useState as x } from "react";
3
+ import { Fragment as S, jsx as C, jsxs as w } from "react/jsx-runtime";
4
4
  //#region src/FetchToken.tsx
5
- var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), S = (e = null, t = b, n = !1) => (r) => (i) => {
6
- let { fetch: a } = C(e || i.fetch, t, n);
7
- return /* @__PURE__ */ v(r, {
5
+ var T = "default", E = (e, t, n = !1) => async (...r) => await t().fetchWithTokens(e, n)(...r), D = (e = null, t = T, n = !1) => (r) => (i) => {
6
+ let { fetch: a } = O(e || i.fetch, t, n);
7
+ return /* @__PURE__ */ C(r, {
8
8
  ...i,
9
9
  fetch: a
10
10
  });
11
- }, C = (e = null, n = b, r = !1) => {
11
+ }, O = (e = null, n = T, r = !1) => {
12
12
  let i = e || window.fetch, a = t.getOrThrow;
13
- return { fetch: p((e, t) => x(i, () => a(n), r)(e, t), [
13
+ return { fetch: v((e, t) => E(i, () => a(n), r)(e, t), [
14
14
  i,
15
15
  n,
16
16
  r
17
17
  ]) };
18
- }, w = () => /* @__PURE__ */ v("div", {
18
+ }, k = () => /* @__PURE__ */ C("div", {
19
19
  className: "oidc-authenticating",
20
- children: /* @__PURE__ */ y("div", {
20
+ children: /* @__PURE__ */ w("div", {
21
21
  className: "oidc-authenticating__container",
22
- children: [/* @__PURE__ */ v("h1", {
22
+ children: [/* @__PURE__ */ C("h1", {
23
23
  className: "oidc-authenticating__title",
24
24
  children: "Error authentication"
25
- }), /* @__PURE__ */ v("p", {
25
+ }), /* @__PURE__ */ C("p", {
26
26
  className: "oidc-authenticating__content",
27
27
  children: "An error occurred during authentication."
28
28
  })]
29
29
  })
30
- }), T = () => /* @__PURE__ */ v("div", {
30
+ }), te = () => /* @__PURE__ */ C("div", {
31
31
  className: "oidc-authenticating",
32
- children: /* @__PURE__ */ y("div", {
32
+ children: /* @__PURE__ */ w("div", {
33
33
  className: "oidc-authenticating__container",
34
- children: [/* @__PURE__ */ v("h1", {
34
+ children: [/* @__PURE__ */ C("h1", {
35
35
  className: "oidc-authenticating__title",
36
36
  children: "Authentication in progress"
37
- }), /* @__PURE__ */ v("p", {
37
+ }), /* @__PURE__ */ C("p", {
38
38
  className: "oidc-authenticating__content",
39
39
  children: "You will be redirected to the login page."
40
40
  })]
41
41
  })
42
- }), E = () => Math.random().toString(36).slice(2, 8), D = (e, t) => (n, r) => {
42
+ }), A = () => Math.random().toString(36).slice(2, 8), j = (e, t) => (n, r) => {
43
43
  if (typeof e.CustomEvent == "function") return new e.CustomEvent(n, r);
44
44
  let i = r || {
45
45
  bubbles: !1,
@@ -47,27 +47,27 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
47
47
  detail: void 0
48
48
  }, a = t.createEvent("CustomEvent");
49
49
  return a.initCustomEvent(n, i.bubbles, i.cancelable, i.detail), a.prototype = e.Event.prototype, a;
50
- }, O = (e, t, n) => ({ replaceState: (r, i) => {
50
+ }, M = (e, t, n) => ({ replaceState: (r, i) => {
51
51
  let a = n(), o = i || e.history.state;
52
52
  e.history.replaceState({
53
53
  key: a,
54
54
  state: o
55
55
  }, null, r), e.dispatchEvent(t("popstate"));
56
- } }), k = () => O(window, D(window, document), E), A = () => /* @__PURE__ */ v("div", {
56
+ } }), N = () => M(window, j(window, document), A), P = () => /* @__PURE__ */ C("div", {
57
57
  className: "oidc-callback",
58
- children: /* @__PURE__ */ y("div", {
58
+ children: /* @__PURE__ */ w("div", {
59
59
  className: "oidc-callback__container",
60
- children: [/* @__PURE__ */ v("h1", {
60
+ children: [/* @__PURE__ */ C("h1", {
61
61
  className: "oidc-callback__title",
62
62
  children: "Authentication complete"
63
- }), /* @__PURE__ */ v("p", {
63
+ }), /* @__PURE__ */ C("p", {
64
64
  className: "oidc-callback__content",
65
65
  children: "You will be redirected to your application."
66
66
  })]
67
67
  })
68
- }), j = 200, M = (e, t = window) => t.location.pathname === e || e === "/", N = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
69
- let [o, s] = g(!1);
70
- return m(() => {
68
+ }), F = 200, I = (e, t = window) => t.location.pathname === e || e === "/", L = ({ callBackError: e, callBackSuccess: n, configurationName: r, withCustomHistory: i, navigateAfterCallback: a }) => {
69
+ let [o, s] = x(!1);
70
+ return y(() => {
71
71
  let e = !0;
72
72
  return (async () => {
73
73
  let n = t.getOrThrow;
@@ -85,11 +85,11 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
85
85
  error: n
86
86
  }), e && (console.warn(n), s(!0));
87
87
  }
88
- else (i ? i() : k()).replaceState(l), await new Promise((e) => {
88
+ else (i ? i() : N()).replaceState(l), await new Promise((e) => {
89
89
  setTimeout(() => {
90
90
  e();
91
- }, j);
92
- }), e && (M(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
91
+ }, F);
92
+ }), e && (I(l) ? o.publishEvent(t.eventNames.loginCallbackAsync_navigated, {
93
93
  configurationName: r,
94
94
  callbackPath: l
95
95
  }) : (o.publishEvent(t.eventNames.loginCallbackAsync_navigation_error, {
@@ -103,233 +103,233 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
103
103
  })(), () => {
104
104
  e = !1;
105
105
  };
106
- }, []), v(o ? e || w : n || A, { configurationName: r });
107
- }, P = () => /* @__PURE__ */ v("span", {
106
+ }, []), C(o ? e || k : n || P, { configurationName: r });
107
+ }, ne = () => /* @__PURE__ */ C("span", {
108
108
  className: "oidc-loading",
109
109
  children: "Loading"
110
- }), F = () => /* @__PURE__ */ v("div", {
110
+ }), re = () => /* @__PURE__ */ C("div", {
111
111
  className: "oidc-loading-timeout",
112
- children: /* @__PURE__ */ y("div", {
112
+ children: /* @__PURE__ */ w("div", {
113
113
  className: "oidc-loading-timeout__container",
114
- children: [/* @__PURE__ */ v("h1", {
114
+ children: [/* @__PURE__ */ C("h1", {
115
115
  className: "oidc-loading-timeout__title",
116
116
  children: "Loading timeout"
117
- }), /* @__PURE__ */ v("p", {
117
+ }), /* @__PURE__ */ C("p", {
118
118
  className: "oidc-loading-timeout__content",
119
119
  children: "Authentication is taking longer than expected. Please try refreshing the page."
120
120
  })]
121
121
  })
122
- }), ee = () => /* @__PURE__ */ v("div", {
122
+ }), ie = () => /* @__PURE__ */ C("div", {
123
123
  className: "oidc-serviceworker",
124
- children: /* @__PURE__ */ y("div", {
124
+ children: /* @__PURE__ */ w("div", {
125
125
  className: "oidc-serviceworker__container",
126
- children: [/* @__PURE__ */ v("h1", {
126
+ children: [/* @__PURE__ */ C("h1", {
127
127
  className: "oidc-serviceworker__title",
128
128
  children: "Unable to authenticate on this browser"
129
- }), /* @__PURE__ */ v("p", {
129
+ }), /* @__PURE__ */ C("p", {
130
130
  className: "oidc-serviceworker__content",
131
131
  children: "Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."
132
132
  })]
133
133
  })
134
- }), te = () => /* @__PURE__ */ v("div", {
134
+ }), R = () => /* @__PURE__ */ C("div", {
135
135
  className: "oidc-session-lost",
136
- children: /* @__PURE__ */ y("div", {
136
+ children: /* @__PURE__ */ w("div", {
137
137
  className: "oidc-session-lost__container",
138
- children: [/* @__PURE__ */ v("h1", {
138
+ children: [/* @__PURE__ */ C("h1", {
139
139
  className: "oidc-session-lost__title",
140
140
  children: "Session timed out"
141
- }), /* @__PURE__ */ v("p", {
141
+ }), /* @__PURE__ */ C("p", {
142
142
  className: "oidc-session-lost__content",
143
143
  children: "Your session has expired. Please re-authenticate."
144
144
  })]
145
145
  })
146
- }), I = ({ configurationName: e }) => (m(() => {
146
+ }), z = ({ configurationName: e }) => (y(() => {
147
147
  (async () => {
148
148
  t.getOrThrow(e).silentLoginCallbackAsync();
149
149
  })().catch((e) => {
150
150
  console.error("Error during silent login callback:", e);
151
151
  });
152
- }, [e]), null), L = ({ configurationName: e }) => {
153
- let n = l(window.location.href), r = t.getOrThrow, i = r(e), a = null;
152
+ }, [e]), null), B = ({ configurationName: e }) => {
153
+ let n = f(window.location.href), r = t.getOrThrow, i = r(e), a = null;
154
154
  for (let [e, t] of Object.entries(n)) e === "state" || e === "scope" || (a === null && (a = {}), a[e] = t);
155
- return m(() => {
155
+ return y(() => {
156
156
  i.tokens || i.loginAsync(null, a, !0, n.scope);
157
- }, []), /* @__PURE__ */ v(_, {});
158
- }, R = f.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null, navigateAfterCallback: c = null }) => {
159
- let [l, d] = g(window ? u(window.location.href) : "");
160
- m(() => {
161
- let e = () => d(u(window.location.href));
157
+ }, []), /* @__PURE__ */ C(S, {});
158
+ }, V = _.memo(({ callbackErrorComponent: e, callbackSuccessComponent: t, redirect_uri: n, silent_redirect_uri: r, silent_login_uri: i, children: a, configurationName: o, withCustomHistory: s = null, navigateAfterCallback: c = null }) => {
159
+ let [l, u] = x(window ? p(window.location.href) : "");
160
+ y(() => {
161
+ let e = () => u(p(window.location.href));
162
162
  return e(), window.addEventListener("popstate", e, !1), () => window.removeEventListener("popstate", e, !1);
163
163
  }, []);
164
- let f = u(n);
165
- if (r && l === u(r)) return /* @__PURE__ */ v(I, { configurationName: o });
166
- if (i && l === u(i)) return /* @__PURE__ */ v(L, { configurationName: o });
164
+ let d = p(n);
165
+ if (r && l === p(r)) return /* @__PURE__ */ C(z, { configurationName: o });
166
+ if (i && l === p(i)) return /* @__PURE__ */ C(B, { configurationName: o });
167
167
  switch (l) {
168
- case f: return /* @__PURE__ */ v(N, {
168
+ case d: return /* @__PURE__ */ C(L, {
169
169
  callBackError: e,
170
170
  callBackSuccess: t,
171
171
  configurationName: o,
172
172
  withCustomHistory: s,
173
173
  navigateAfterCallback: c
174
174
  });
175
- default: return /* @__PURE__ */ v(_, { children: a });
175
+ default: return /* @__PURE__ */ C(S, { children: a });
176
176
  }
177
- }), z = {
177
+ }), H = {
178
178
  name: "",
179
179
  data: null
180
- }, B = ({ loadingComponent: e, children: n, configurationName: r }) => {
181
- let [i, a] = g(!0), o = t.get, s = o(r);
182
- return m(() => {
180
+ }, ae = ({ loadingComponent: e, children: n, configurationName: r }) => {
181
+ let [i, a] = x(!0), o = t.get, s = o(r);
182
+ return y(() => {
183
183
  let e = !0;
184
184
  return s && s.tryKeepExistingSessionAsync().then(() => {
185
185
  e && a(!1);
186
186
  }), () => {
187
187
  e = !1;
188
188
  };
189
- }, [r]), /* @__PURE__ */ v(_, { children: i ? /* @__PURE__ */ v(e, { configurationName: r }) : /* @__PURE__ */ v(_, { children: n }) });
190
- }, V = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ v(t, {
189
+ }, [r]), /* @__PURE__ */ C(S, { children: i ? /* @__PURE__ */ C(e, { configurationName: r }) : /* @__PURE__ */ C(S, { children: n }) });
190
+ }, U = ({ isLoading: e, loadingComponent: t, children: n, configurationName: r }) => e ? /* @__PURE__ */ C(t, {
191
191
  configurationName: r,
192
192
  children: n
193
- }) : /* @__PURE__ */ v(_, { children: n }), H = 3e4, U = (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, W = ({ children: e, configuration: n, configurationName: i = "default", callbackSuccessComponent: a = A, authenticatingComponent: o = T, loadingComponent: s = P, loadingTimeoutComponent: l = F, serviceWorkerNotSupportedComponent: u = ee, authenticatingErrorComponent: d = w, sessionLostComponent: f = te, onSessionLost: p = null, onLogoutFromAnotherTab: h = null, onLogoutFromSameTab: _ = null, withCustomHistory: y = null, navigateAfterCallback: b = null, onEvent: x = null, getFetch: S = null, location: C = null }) => {
193
+ }) : /* @__PURE__ */ C(S, { children: n }), W = 3e4, G = (e) => e === t.eventNames.token_acquired || e === t.eventNames.token_renewed || e === t.eventNames.loginCallbackAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_end || e === t.eventNames.tryKeepExistingSessionAsync_error, K = ({ children: e, configuration: n, configurationName: r = "default", callbackSuccessComponent: i = P, authenticatingComponent: o = te, loadingComponent: s = ne, loadingTimeoutComponent: c = re, serviceWorkerNotSupportedComponent: l = ie, authenticatingErrorComponent: u = k, sessionLostComponent: d = R, onSessionLost: f = null, onLogoutFromAnotherTab: p = null, onLogoutFromSameTab: m = null, withCustomHistory: h = null, navigateAfterCallback: g = null, onEvent: _ = null, getFetch: v = null, location: b = null }) => {
194
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");
195
- let E = (e = "default") => t.getOrCreate(S ?? c, C ?? new r())(n, e), [D, O] = g(z), [k, j] = g(!1), [M, N] = g(i);
196
- m(() => {
197
- let e = E(i).subscribeEvents((e, t) => {
198
- x && x(i, e, t);
195
+ let S = (e = "default") => t.getOrCreate(v ?? ee, b ?? new a())(n, e), [w, T] = x(H), [E, D] = x(!0), [O, A] = x(r);
196
+ y(() => {
197
+ let e = S(r).subscribeEvents((e, t) => {
198
+ _ && _(r, e, t);
199
199
  });
200
200
  return () => {
201
- E(i).removeEventSubscription(e);
201
+ S(r).removeEventSubscription(e);
202
202
  };
203
- }, [i, x]), m(() => {
204
- let e = E(i).subscribeEvents((e, r) => {
205
- if (U(e, r) && j(!0), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
206
- if (p != null) {
207
- p();
203
+ }, [r, _]), y(() => {
204
+ let e = S(r).subscribeEvents((e, r) => {
205
+ if (e === t.eventNames.loginAsync_begin ? D(!0) : G(e) && D(!1), e === t.eventNames.refreshTokensAsync_error || e === t.eventNames.syncTokensAsync_error) {
206
+ if (f != null) {
207
+ f();
208
208
  return;
209
209
  }
210
- O({
210
+ T({
211
211
  name: e,
212
212
  data: r
213
213
  });
214
214
  } else if (e === t.eventNames.logout_from_another_tab) {
215
- if (h != null) {
216
- h();
215
+ if (p != null) {
216
+ p();
217
217
  return;
218
218
  }
219
- O({
219
+ T({
220
220
  name: e,
221
221
  data: r
222
222
  });
223
- } else e === t.eventNames.logout_from_same_tab ? _?.() : (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 ? m?.() : (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) && T({
224
224
  name: e,
225
225
  data: r
226
226
  });
227
227
  });
228
228
  return queueMicrotask(() => {
229
- N(i);
229
+ A(r);
230
230
  }), () => {
231
- E(i).removeEventSubscription(e), O(z), j(!1);
231
+ S(r).removeEventSubscription(e), T(H), D(!0);
232
232
  };
233
- }, [n, i]), m(() => {
234
- let e = n?.loading_timeout_ms ?? H;
235
- if (e <= 0 || k || E(i)?.tokens != null || !(D.name === "" || D.name === t.eventNames.loginAsync_begin)) return;
236
- let r = setTimeout(() => {
237
- E(i).publishEvent(t.eventNames.loadingTimeout_error, { timeoutMs: e });
233
+ }, [n, r]), y(() => {
234
+ let e = n?.loading_timeout_ms ?? W;
235
+ if (e <= 0 || !E || S(r)?.tokens != null || !(w.name === "" || w.name === t.eventNames.loginAsync_begin)) return;
236
+ let i = setTimeout(() => {
237
+ S(r).publishEvent(t.eventNames.loadingTimeout_error, { timeoutMs: e });
238
238
  }, e);
239
- return () => clearTimeout(r);
239
+ return () => clearTimeout(i);
240
240
  }, [
241
- D.name,
242
- k,
243
- i,
241
+ w.name,
242
+ E,
243
+ r,
244
244
  n
245
245
  ]);
246
- let I = f, L = o, W = s, G = l, K = u, q = d, J = M !== i, Y = E(i);
247
- switch (D.name) {
248
- case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ v(V, {
249
- loadingComponent: W,
250
- isLoading: J,
251
- configurationName: i,
252
- children: /* @__PURE__ */ v(K, { configurationName: i })
246
+ let j = d, M = o, N = s, F = c, I = l, L = u, z = O !== r, B = S(r);
247
+ switch (w.name) {
248
+ case t.eventNames.service_worker_not_supported_by_browser: return /* @__PURE__ */ C(U, {
249
+ loadingComponent: N,
250
+ isLoading: z,
251
+ configurationName: r,
252
+ children: /* @__PURE__ */ C(I, { configurationName: r })
253
253
  });
254
- case t.eventNames.loginAsync_begin: return /* @__PURE__ */ v(V, {
255
- loadingComponent: W,
256
- isLoading: J,
257
- configurationName: i,
258
- children: /* @__PURE__ */ v(L, { configurationName: i })
254
+ case t.eventNames.loginAsync_begin: return /* @__PURE__ */ C(U, {
255
+ loadingComponent: N,
256
+ isLoading: z,
257
+ configurationName: r,
258
+ children: /* @__PURE__ */ C(M, { configurationName: r })
259
259
  });
260
- case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ v(V, {
261
- loadingComponent: W,
262
- isLoading: J,
263
- configurationName: i,
264
- children: /* @__PURE__ */ v(G, { configurationName: i })
260
+ case t.eventNames.loadingTimeout_error: return /* @__PURE__ */ C(U, {
261
+ loadingComponent: N,
262
+ isLoading: z,
263
+ configurationName: r,
264
+ children: /* @__PURE__ */ C(F, { configurationName: r })
265
265
  });
266
266
  case t.eventNames.loginAsync_error:
267
- case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ v(V, {
268
- loadingComponent: W,
269
- isLoading: J,
270
- configurationName: i,
271
- children: /* @__PURE__ */ v(q, { configurationName: i })
267
+ case t.eventNames.loginCallbackAsync_error: return /* @__PURE__ */ C(U, {
268
+ loadingComponent: N,
269
+ isLoading: z,
270
+ configurationName: r,
271
+ children: /* @__PURE__ */ C(L, { configurationName: r })
272
272
  });
273
273
  case t.eventNames.refreshTokensAsync_error:
274
274
  case t.eventNames.syncTokensAsync_error:
275
- case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ v(V, {
276
- loadingComponent: W,
277
- isLoading: J,
278
- configurationName: i,
279
- children: /* @__PURE__ */ v(I, { configurationName: i })
275
+ case t.eventNames.logout_from_another_tab: return /* @__PURE__ */ C(U, {
276
+ loadingComponent: N,
277
+ isLoading: z,
278
+ configurationName: r,
279
+ children: /* @__PURE__ */ C(j, { configurationName: r })
280
280
  });
281
- default: return /* @__PURE__ */ v(V, {
282
- loadingComponent: W,
283
- isLoading: J,
284
- configurationName: i,
285
- children: /* @__PURE__ */ v(R, {
286
- redirect_uri: Y.configuration.redirect_uri,
287
- silent_redirect_uri: Y.configuration.silent_redirect_uri,
288
- silent_login_uri: Y.configuration.silent_login_uri,
289
- callbackSuccessComponent: a,
290
- callbackErrorComponent: d,
281
+ default: return /* @__PURE__ */ C(U, {
282
+ loadingComponent: N,
283
+ isLoading: z,
284
+ configurationName: r,
285
+ children: /* @__PURE__ */ C(V, {
286
+ redirect_uri: B.configuration.redirect_uri,
287
+ silent_redirect_uri: B.configuration.silent_redirect_uri,
288
+ silent_login_uri: B.configuration.silent_login_uri,
289
+ callbackSuccessComponent: i,
290
+ callbackErrorComponent: u,
291
291
  authenticatingComponent: o,
292
- configurationName: i,
293
- withCustomHistory: y,
294
- navigateAfterCallback: b,
295
- location: C ?? new r(),
296
- children: /* @__PURE__ */ v(B, {
297
- loadingComponent: W,
298
- configurationName: i,
292
+ configurationName: r,
293
+ withCustomHistory: h,
294
+ navigateAfterCallback: g,
295
+ location: b ?? new a(),
296
+ children: /* @__PURE__ */ C(ae, {
297
+ loadingComponent: N,
298
+ configurationName: r,
299
299
  children: e
300
300
  })
301
301
  })
302
302
  });
303
303
  }
304
- }, G = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
304
+ }, q = ({ children: e, callbackPath: n = null, extras: r = null, configurationName: i = "default" }) => {
305
305
  let a = t.getOrThrow, o = a(i);
306
- return m(() => {
306
+ return y(() => {
307
307
  !o.tokens && !o.isLoggingOut && o.loginAsync(n, r);
308
308
  }, [
309
309
  i,
310
310
  n,
311
311
  r
312
- ]), o.tokens ? /* @__PURE__ */ v(_, { children: e }) : null;
313
- }, K = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ v(G, {
312
+ ]), o.tokens ? /* @__PURE__ */ C(S, { children: e }) : null;
313
+ }, oe = (e, t = null, n = null, r = "default") => (i) => /* @__PURE__ */ C(q, {
314
314
  callbackPath: t,
315
315
  extras: n,
316
316
  configurationName: r,
317
- children: /* @__PURE__ */ v(e, { ...i })
318
- }), q = /* @__PURE__ */ new Set(), J = (e) => {
319
- q.has(e) || (q.add(e), console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`));
320
- }, Y = "default", X = (e, t) => {
317
+ children: /* @__PURE__ */ C(e, { ...i })
318
+ }), J = /* @__PURE__ */ new Set(), Y = (e) => {
319
+ J.has(e) || (J.add(e), console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`));
320
+ }, X = "default", Z = (e, t) => {
321
321
  let n = !1, r = e(t);
322
322
  return r && (n = r.tokens != null), n;
323
- }, Z = (e = Y) => {
324
- let n = t.get, [r, i] = g(() => X(n, e));
325
- return m(() => {
323
+ }, se = (e = X) => {
324
+ let n = t.get, [r, i] = x(() => Z(n, e));
325
+ return y(() => {
326
326
  let r = !0, a = n(e);
327
327
  if (!a) {
328
- J(e);
328
+ Y(e);
329
329
  return;
330
330
  }
331
331
  let o = a.subscribeEvents((a, o) => {
332
- (a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(X(n, e));
332
+ (a === t.eventNames.logout_from_another_tab || a === t.eventNames.logout_from_same_tab || a === t.eventNames.token_acquired) && r && i(Z(n, e));
333
333
  });
334
334
  return () => {
335
335
  r = !1, a.removeEventSubscription(o);
@@ -337,15 +337,15 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
337
337
  }, [e]), {
338
338
  login: (t = void 0, r = void 0, i = !1, a = void 0) => {
339
339
  let o = n(e);
340
- return o ? o.loginAsync(t, r, !1, a, i) : (J(e), Promise.resolve());
340
+ return o ? o.loginAsync(t, r, !1, a, i) : (Y(e), Promise.resolve());
341
341
  },
342
342
  logout: (t = void 0, r = void 0) => {
343
343
  let i = n(e);
344
- return i ? i.logoutAsync(t, r) : (J(e), Promise.resolve());
344
+ return i ? i.logoutAsync(t, r) : (Y(e), Promise.resolve());
345
345
  },
346
346
  renewTokens: async (t = void 0) => {
347
347
  let r = n(e);
348
- if (!r) return J(e), {
348
+ if (!r) return Y(e), {
349
349
  accessToken: null,
350
350
  accessTokenPayload: null,
351
351
  idToken: null,
@@ -364,7 +364,7 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
364
364
  }, Q = {
365
365
  accessToken: null,
366
366
  accessTokenPayload: null
367
- }, ne = (e) => {
367
+ }, ce = (e) => {
368
368
  let n = t.get, r = n(e);
369
369
  if (!r) return Q;
370
370
  if (r.tokens) {
@@ -377,15 +377,15 @@ var b = "default", x = (e, t, n = !1) => async (...r) => await t().fetchWithToke
377
377
  }
378
378
  return Q;
379
379
  };
380
- function re(e, t) {
380
+ function le(e, t) {
381
381
  return e.configuration.demonstrating_proof_of_possession ? (n, r, i = {}) => e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken, n, r, i) : null;
382
382
  }
383
- var ie = (e = Y) => {
384
- let n = t.get, [r, i] = g(() => ne(e));
385
- return m(() => {
383
+ var ue = (e = X) => {
384
+ let n = t.get, [r, i] = x(() => ce(e));
385
+ return y(() => {
386
386
  let r = !0, a = n(e);
387
387
  if (!a) {
388
- J(e);
388
+ Y(e);
389
389
  return;
390
390
  }
391
391
  let o = a.subscribeEvents((e, n) => {
@@ -394,7 +394,7 @@ var ie = (e = Y) => {
394
394
  i(e == null ? Q : {
395
395
  accessToken: e.accessToken,
396
396
  accessTokenPayload: e.accessTokenPayload,
397
- generateDemonstrationOfProofOfPossessionAsync: re(a, e)
397
+ generateDemonstrationOfProofOfPossessionAsync: le(a, e)
398
398
  });
399
399
  }
400
400
  });
@@ -405,7 +405,7 @@ var ie = (e = Y) => {
405
405
  }, $ = {
406
406
  idToken: null,
407
407
  idTokenPayload: null
408
- }, ae = (e) => {
408
+ }, de = (e) => {
409
409
  let n = t.get, r = n(e);
410
410
  if (!r) return $;
411
411
  if (r.tokens) {
@@ -416,12 +416,12 @@ var ie = (e = Y) => {
416
416
  };
417
417
  }
418
418
  return $;
419
- }, oe = (e = Y) => {
420
- let n = t.get, [r, i] = g(() => ae(e));
421
- return m(() => {
419
+ }, fe = (e = X) => {
420
+ let n = t.get, [r, i] = x(() => de(e));
421
+ return y(() => {
422
422
  let r = !0, a = n(e);
423
423
  if (!a) {
424
- J(e);
424
+ Y(e);
425
425
  return;
426
426
  }
427
427
  let o = a.subscribeEvents((e, n) => {
@@ -437,17 +437,17 @@ var ie = (e = Y) => {
437
437
  r = !1, a.removeEventSubscription(o);
438
438
  };
439
439
  }, [e]), r;
440
- }, se = /* @__PURE__ */ function(e) {
440
+ }, pe = /* @__PURE__ */ function(e) {
441
441
  return e.Unauthenticated = "Unauthenticated", e.Loading = "Loading user", e.Loaded = "User loaded", e.LoadingError = "Error loading user", e;
442
- }({}), ce = (e = "default", n = !1) => {
443
- let r = t.get(e), i = r ? r.userInfo() : null, [a, o] = g({
442
+ }({}), me = (e = "default", n = !1) => {
443
+ let r = t.get(e), i = r ? r.userInfo() : null, [a, o] = x({
444
444
  user: i,
445
445
  status: i ? "User loaded" : "Unauthenticated"
446
- }), [s, c] = g(+!!i), l = h(+!!i);
447
- return m(() => {
446
+ }), [s, c] = x(+!!i), l = b(+!!i);
447
+ return y(() => {
448
448
  let r = t.get(e), i = !0;
449
449
  if (!r) {
450
- J(e);
450
+ Y(e);
451
451
  return;
452
452
  }
453
453
  if (r.tokens) {
@@ -495,4 +495,4 @@ var ie = (e = Y) => {
495
495
  };
496
496
  };
497
497
  //#endregion
498
- export { e as OidcClient, n as OidcLocation, W as OidcProvider, G as OidcSecure, i as OidcStateError, a as OidcStateErrorCode, se as OidcUserStatus, o as TokenAutomaticRenewMode, s as TokenRenewMode, d as isOidcStateError, Z as useOidc, ie as useOidcAccessToken, C as useOidcFetch, oe as useOidcIdToken, ce as useOidcUser, S as withOidcFetch, K as withOidcSecure };
498
+ export { e as OidcClient, n as OidcError, r as OidcErrorCode, i as OidcLocation, K as OidcProvider, q as OidcSecure, o as OidcStateError, s as OidcStateErrorCode, pe as OidcUserStatus, c as PushedAuthorizationRequestError, l as PushedAuthorizationRequestErrorCode, u as TokenAutomaticRenewMode, d as TokenRenewMode, m as isOidcError, h as isOidcStateError, g as isPushedAuthorizationRequestError, se as useOidc, ue as useOidcAccessToken, O as useOidcFetch, fe as useOidcIdToken, me as useOidcUser, D as withOidcFetch, oe 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.getOrThrow;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=200,C=(e,t=window)=>t.location.pathname===e||e===`/`,w=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o,navigateAfterCallback:s})=>{let[c,l]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.getOrThrow;try{let r=n(a),{callbackPath:i}=await r.loginCallbackAsync(),c=i||`/`;if(s)try{await s(c),r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c})}catch(n){r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:n}),e&&(console.warn(n),l(!0))}else (o?o():b()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},S)}),e&&(C(c)?r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c}):(r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:Error(`Navigation did not commit: expected "${c}" but found "${window.location.pathname}"`)}),l(!0)))}catch(t){e&&(console.warn(t),l(!0))}})(),()=>{e=!1}},[]);let u=e||h,d=i||x;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},T=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),E=()=>(0,r.jsx)(`div`,{className:`oidc-loading-timeout`,children:(0,r.jsxs)(`div`,{className:`oidc-loading-timeout__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-loading-timeout__title`,children:`Loading timeout`}),(0,r.jsx)(`p`,{className:`oidc-loading-timeout__content`,children:`Authentication is taking longer than expected. Please try refreshing the page.`})]})}),D=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.jsx)(`p`,{className:`oidc-serviceworker__content`,children:`Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.`})]})}),O=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),k=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.getOrThrow(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),A=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.getOrThrow,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},j=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null,navigateAfterCallback:d=null})=>{let[f,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.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=new Set,V=e=>{B.has(e)||(B.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},H=`default`,U=(e,t)=>{let n=!1,r=e(t);return r&&(n=r.tokens!=null),n},W=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(U(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(V(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(V(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return V(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Q=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=L,e.OidcSecure=R,Object.defineProperty(e,`OidcStateError`,{enumerable:!0,get:function(){return t.OidcStateError}}),Object.defineProperty(e,`OidcStateErrorCode`,{enumerable:!0,get:function(){return t.OidcStateErrorCode}}),e.OidcUserStatus=Q,Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),Object.defineProperty(e,`isOidcStateError`,{enumerable:!0,get:function(){return t.isOidcStateError}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=m,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){V(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=p,e.withOidcSecure=z});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@axa-fr/oidc-client`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@axa-fr/oidc-client`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`react-oidc`]={},e._axa_fr_oidc_client,e.React,e.react_jsx_runtime))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=`default`,f=(e,t,n=!1)=>async(...r)=>await t().fetchWithTokens(e,n)(...r),p=(e=null,t=d,n=!1)=>i=>a=>{let{fetch:o}=m(e||a.fetch,t,n);return(0,r.jsx)(i,{...a,fetch:o})},m=(e=null,r=d,i=!1)=>{let a=e||window.fetch,o=t.OidcClient.getOrThrow;return{fetch:(0,n.useCallback)((e,t)=>f(a,()=>o(r),i)(e,t),[a,r,i])}},h=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Error authentication`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`An error occurred during authentication.`})]})}),g=()=>(0,r.jsx)(`div`,{className:`oidc-authenticating`,children:(0,r.jsxs)(`div`,{className:`oidc-authenticating__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-authenticating__title`,children:`Authentication in progress`}),(0,r.jsx)(`p`,{className:`oidc-authenticating__content`,children:`You will be redirected to the login page.`})]})}),_=()=>Math.random().toString(36).slice(2,8),v=(e,t)=>(n,r)=>{if(typeof e.CustomEvent==`function`)return new e.CustomEvent(n,r);let i=r||{bubbles:!1,cancelable:!1,detail:void 0},a=t.createEvent(`CustomEvent`);return a.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),a.prototype=e.Event.prototype,a},y=(e,t,n)=>({replaceState:(r,i)=>{let a=n(),o=i||e.history.state;e.history.replaceState({key:a,state:o},null,r),e.dispatchEvent(t(`popstate`))}}),b=()=>y(window,v(window,document),_),x=()=>(0,r.jsx)(`div`,{className:`oidc-callback`,children:(0,r.jsxs)(`div`,{className:`oidc-callback__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-callback__title`,children:`Authentication complete`}),(0,r.jsx)(`p`,{className:`oidc-callback__content`,children:`You will be redirected to your application.`})]})}),S=200,C=(e,t=window)=>t.location.pathname===e||e===`/`,w=({callBackError:e,callBackSuccess:i,configurationName:a,withCustomHistory:o,navigateAfterCallback:s})=>{let[c,l]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=!0;return(async()=>{let n=t.OidcClient.getOrThrow;try{let r=n(a),{callbackPath:i}=await r.loginCallbackAsync(),c=i||`/`;if(s)try{await s(c),r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c})}catch(n){r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:n}),e&&(console.warn(n),l(!0))}else (o?o():b()).replaceState(c),await new Promise(e=>{setTimeout(()=>{e()},S)}),e&&(C(c)?r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigated,{configurationName:a,callbackPath:c}):(r.publishEvent(t.OidcClient.eventNames.loginCallbackAsync_navigation_error,{configurationName:a,callbackPath:c,error:Error(`Navigation did not commit: expected "${c}" but found "${window.location.pathname}"`)}),l(!0)))}catch(t){e&&(console.warn(t),l(!0))}})(),()=>{e=!1}},[]);let u=e||h,d=i||x;return c?(0,r.jsx)(u,{configurationName:a}):(0,r.jsx)(d,{configurationName:a})},T=()=>(0,r.jsx)(`span`,{className:`oidc-loading`,children:`Loading`}),E=()=>(0,r.jsx)(`div`,{className:`oidc-loading-timeout`,children:(0,r.jsxs)(`div`,{className:`oidc-loading-timeout__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-loading-timeout__title`,children:`Loading timeout`}),(0,r.jsx)(`p`,{className:`oidc-loading-timeout__content`,children:`Authentication is taking longer than expected. Please try refreshing the page.`})]})}),D=()=>(0,r.jsx)(`div`,{className:`oidc-serviceworker`,children:(0,r.jsxs)(`div`,{className:`oidc-serviceworker__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-serviceworker__title`,children:`Unable to authenticate on this browser`}),(0,r.jsx)(`p`,{className:`oidc-serviceworker__content`,children:`Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser.`})]})}),O=()=>(0,r.jsx)(`div`,{className:`oidc-session-lost`,children:(0,r.jsxs)(`div`,{className:`oidc-session-lost__container`,children:[(0,r.jsx)(`h1`,{className:`oidc-session-lost__title`,children:`Session timed out`}),(0,r.jsx)(`p`,{className:`oidc-session-lost__content`,children:`Your session has expired. Please re-authenticate.`})]})}),k=({configurationName:e})=>((0,n.useEffect)(()=>{(async()=>{t.OidcClient.getOrThrow(e).silentLoginCallbackAsync()})().catch(e=>{console.error(`Error during silent login callback:`,e)})},[e]),null),A=({configurationName:e})=>{let i=(0,t.getParseQueryStringFromLocation)(window.location.href),a=t.OidcClient.getOrThrow,o=a(e),s=null;for(let[e,t]of Object.entries(i))e===`state`||e===`scope`||(s===null&&(s={}),s[e]=t);return(0,n.useEffect)(()=>{o.tokens||o.loginAsync(null,s,!0,i.scope)},[]),(0,r.jsx)(r.Fragment,{})},j=n.default.memo(({callbackErrorComponent:e,callbackSuccessComponent:i,redirect_uri:a,silent_redirect_uri:o,silent_login_uri:s,children:c,configurationName:l,withCustomHistory:u=null,navigateAfterCallback:d=null})=>{let[f,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=>e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_end||e===t.OidcClient.eventNames.tryKeepExistingSessionAsync_error,L=({children:e,configuration:i,configurationName:a=`default`,callbackSuccessComponent:o=x,authenticatingComponent:s=g,loadingComponent:c=T,loadingTimeoutComponent:l=E,serviceWorkerNotSupportedComponent:u=D,authenticatingErrorComponent:d=h,sessionLostComponent:f=O,onSessionLost:p=null,onLogoutFromAnotherTab:m=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,navigateAfterCallback:y=null,onEvent:b=null,getFetch:S=null,location:C=null})=>{if(i&&i.redirect_uri&&i.silent_redirect_uri&&i.redirect_uri===i.silent_redirect_uri)throw Error(`redirect_uri and silent_redirect_uri must be different`);let w=(e=`default`)=>t.OidcClient.getOrCreate(S??t.getFetchDefault,C??new t.OidcLocation)(i,e),[k,A]=(0,n.useState)(M),[L,R]=(0,n.useState)(!0),[z,B]=(0,n.useState)(a);(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,t)=>{b&&b(a,e,t)});return()=>{w(a).removeEventSubscription(e)}},[a,b]),(0,n.useEffect)(()=>{let e=w(a).subscribeEvents((e,n)=>{if(e===t.OidcClient.eventNames.loginAsync_begin?R(!0):I(e)&&R(!1),e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error){if(p!=null){p();return}A({name:e,data:n})}else if(e===t.OidcClient.eventNames.logout_from_another_tab){if(m!=null){m();return}A({name:e,data:n})}else e===t.OidcClient.eventNames.logout_from_same_tab?_?.():(e===t.OidcClient.eventNames.loadingTimeout_error||e===t.OidcClient.eventNames.loginAsync_begin||e===t.OidcClient.eventNames.loginCallbackAsync_end||e===t.OidcClient.eventNames.loginAsync_error||e===t.OidcClient.eventNames.loginCallbackAsync_error||e===t.OidcClient.eventNames.service_worker_not_supported_by_browser&&i.service_worker_only===!0)&&A({name:e,data:n})});return queueMicrotask(()=>{B(a)}),()=>{w(a).removeEventSubscription(e),A(M),R(!0)}},[i,a]),(0,n.useEffect)(()=>{let e=i?.loading_timeout_ms??F;if(e<=0||!L||w(a)?.tokens!=null||!(k.name===``||k.name===t.OidcClient.eventNames.loginAsync_begin))return;let n=setTimeout(()=>{w(a).publishEvent(t.OidcClient.eventNames.loadingTimeout_error,{timeoutMs:e})},e);return()=>clearTimeout(n)},[k.name,L,a,i]);let V=f,H=s,U=c,W=l,G=u,K=d,q=z!==a,J=w(a);switch(k.name){case t.OidcClient.eventNames.service_worker_not_supported_by_browser:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(G,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_begin:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(H,{configurationName:a})});case t.OidcClient.eventNames.loadingTimeout_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(W,{configurationName:a})});case t.OidcClient.eventNames.loginAsync_error:case t.OidcClient.eventNames.loginCallbackAsync_error:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(K,{configurationName:a})});case t.OidcClient.eventNames.refreshTokensAsync_error:case t.OidcClient.eventNames.syncTokensAsync_error:case t.OidcClient.eventNames.logout_from_another_tab:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(V,{configurationName:a})});default:return(0,r.jsx)(P,{loadingComponent:U,isLoading:q,configurationName:a,children:(0,r.jsx)(j,{redirect_uri:J.configuration.redirect_uri,silent_redirect_uri:J.configuration.silent_redirect_uri,silent_login_uri:J.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:d,authenticatingComponent:s,configurationName:a,withCustomHistory:v,navigateAfterCallback:y,location:C??new t.OidcLocation,children:(0,r.jsx)(N,{loadingComponent:U,configurationName:a,children:e})})})}},R=({children:e,callbackPath:i=null,extras:a=null,configurationName:o=`default`})=>{let s=t.OidcClient.getOrThrow,c=s(o);return(0,n.useEffect)(()=>{!c.tokens&&!c.isLoggingOut&&c.loginAsync(i,a)},[o,i,a]),c.tokens?(0,r.jsx)(r.Fragment,{children:e}):null},z=(e,t=null,n=null,i=`default`)=>a=>(0,r.jsx)(R,{callbackPath:t,extras:n,configurationName:i,children:(0,r.jsx)(e,{...a})}),B=new Set,V=e=>{B.has(e)||(B.add(e),console.warn(`@axa-fr/react-oidc: no OIDC configuration found for "${e}". Make sure to wrap your component tree with <OidcProvider configurationName="${e}">. Hooks are returning safe default values (issue #1679).`))},H=`default`,U=(e,t)=>{let n=!1,r=e(t);return r&&(n=r.tokens!=null),n},W=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>U(r,e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((i,o)=>{(i===t.OidcClient.eventNames.logout_from_another_tab||i===t.OidcClient.eventNames.logout_from_same_tab||i===t.OidcClient.eventNames.token_acquired)&&n&&a(U(r,e))});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),{login:(t=void 0,n=void 0,i=!1,a=void 0)=>{let o=r(e);return o?o.loginAsync(t,n,!1,a,i):(V(e),Promise.resolve())},logout:(t=void 0,n=void 0)=>{let i=r(e);return i?i.logoutAsync(t,n):(V(e),Promise.resolve())},renewTokens:async(t=void 0)=>{let n=r(e);if(!n)return V(e),{accessToken:null,accessTokenPayload:null,idToken:null,idTokenPayload:null};let i=await n.renewTokensAsync(t);return{accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload,idToken:i.idToken,idTokenPayload:i.idTokenPayload}},isAuthenticated:i}},G={accessToken:null,accessTokenPayload:null},K=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return G;if(r.tokens){let e=r.tokens;return{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:r.configuration.demonstrating_proof_of_possession?(t,n)=>r.generateDemonstrationOfProofOfPossessionAsync(e.accessToken,t,n):null}}return G};function q(e,t){return e.configuration.demonstrating_proof_of_possession?(n,r,i={})=>e.generateDemonstrationOfProofOfPossessionAsync(t.accessToken,n,r,i):null}var J=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>K(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?G:{accessToken:e.accessToken,accessTokenPayload:e.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:q(i,e)})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Y={idToken:null,idTokenPayload:null},X=e=>{let n=t.OidcClient.get,r=n(e);if(!r)return Y;if(r.tokens){let e=r.tokens;return{idToken:e.idToken,idTokenPayload:e.idTokenPayload}}return Y},Z=(e=H)=>{let r=t.OidcClient.get,[i,a]=(0,n.useState)(()=>X(e));return(0,n.useEffect)(()=>{let n=!0,i=r(e);if(!i){V(e);return}let o=i.subscribeEvents((e,r)=>{if((e===t.OidcClient.eventNames.token_renewed||e===t.OidcClient.eventNames.token_acquired||e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab||e===t.OidcClient.eventNames.refreshTokensAsync_error||e===t.OidcClient.eventNames.syncTokensAsync_error)&&n){let e=i.tokens;a(e==null?Y:{idToken:e.idToken,idTokenPayload:e.idTokenPayload})}});return()=>{n=!1,i.removeEventSubscription(o)}},[e]),i},Q=function(e){return e.Unauthenticated=`Unauthenticated`,e.Loading=`Loading user`,e.Loaded=`User loaded`,e.LoadingError=`Error loading user`,e}({});Object.defineProperty(e,`OidcClient`,{enumerable:!0,get:function(){return t.OidcClient}}),Object.defineProperty(e,`OidcError`,{enumerable:!0,get:function(){return t.OidcError}}),Object.defineProperty(e,`OidcErrorCode`,{enumerable:!0,get:function(){return t.OidcErrorCode}}),Object.defineProperty(e,`OidcLocation`,{enumerable:!0,get:function(){return t.OidcLocation}}),e.OidcProvider=L,e.OidcSecure=R,Object.defineProperty(e,`OidcStateError`,{enumerable:!0,get:function(){return t.OidcStateError}}),Object.defineProperty(e,`OidcStateErrorCode`,{enumerable:!0,get:function(){return t.OidcStateErrorCode}}),e.OidcUserStatus=Q,Object.defineProperty(e,`PushedAuthorizationRequestError`,{enumerable:!0,get:function(){return t.PushedAuthorizationRequestError}}),Object.defineProperty(e,`PushedAuthorizationRequestErrorCode`,{enumerable:!0,get:function(){return t.PushedAuthorizationRequestErrorCode}}),Object.defineProperty(e,`TokenAutomaticRenewMode`,{enumerable:!0,get:function(){return t.TokenAutomaticRenewMode}}),Object.defineProperty(e,`TokenRenewMode`,{enumerable:!0,get:function(){return t.TokenRenewMode}}),Object.defineProperty(e,`isOidcError`,{enumerable:!0,get:function(){return t.isOidcError}}),Object.defineProperty(e,`isOidcStateError`,{enumerable:!0,get:function(){return t.isOidcStateError}}),Object.defineProperty(e,`isPushedAuthorizationRequestError`,{enumerable:!0,get:function(){return t.isPushedAuthorizationRequestError}}),e.useOidc=W,e.useOidcAccessToken=J,e.useOidcFetch=m,e.useOidcIdToken=Z,e.useOidcUser=(e=`default`,r=!1)=>{let i=t.OidcClient.get(e),a=i?i.userInfo():null,[o,s]=(0,n.useState)({user:a,status:a?`User loaded`:`Unauthenticated`}),[c,l]=(0,n.useState)(+!!a),u=(0,n.useRef)(+!!a);return(0,n.useEffect)(()=>{let n=t.OidcClient.get(e),i=!0;if(!n){V(e);return}if(n.tokens){let e=c===u.current;if(e&&n.userInfo())return;u.current=c,queueMicrotask(()=>{i&&s({...o,status:`Loading user`})}),n.userInfoAsync(!e,r).then(e=>{i&&s({user:e,status:`User loaded`})}).catch(()=>s({...o,status:`Error loading user`}))}else queueMicrotask(()=>{i&&s({user:null,status:`Unauthenticated`})});let a=n.subscribeEvents(e=>{(e===t.OidcClient.eventNames.logout_from_another_tab||e===t.OidcClient.eventNames.logout_from_same_tab)&&i&&s({user:null,status:`Unauthenticated`})});return()=>{i=!1,n.removeEventSubscription(a)}},[c,e,r]),{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:()=>{l(c+1)}}},e.withOidcFetch=p,e.withOidcSecure=z});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.27.19",
3
+ "version": "7.29.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -36,12 +36,11 @@
36
36
  "test": "vitest --root . --coverage",
37
37
  "clean": "rimraf dist",
38
38
  "postinstall": "echo 'WARNING keep sink OidcServiceWorker.js version file'",
39
- "prepare": "pnpm run clean && pnpm run copy-service-worker && pnpm run build",
40
39
  "lint": "eslint src"
41
40
  },
42
41
  "dependencies": {
43
- "@axa-fr/oidc-client": "7.27.19",
44
- "@axa-fr/oidc-client-service-worker": "7.27.19"
42
+ "@axa-fr/oidc-client": "7.29.2",
43
+ "@axa-fr/oidc-client-service-worker": "7.29.2"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
@@ -288,7 +288,7 @@ describe('OidcProvider loading timeout', () => {
288
288
  expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
289
289
  });
290
290
 
291
- it('should still fire loadingTimeout_error when silent session restore reports no existing session', async () => {
291
+ it('should NOT fire loadingTimeout_error on an anonymous route when no session exists', async () => {
292
292
  render(
293
293
  <OidcProvider
294
294
  configuration={{ ...baseConfiguration, loading_timeout_ms: 300 }}
@@ -310,9 +310,63 @@ describe('OidcProvider loading timeout', () => {
310
310
  vi.advanceTimersByTime(300);
311
311
  });
312
312
 
313
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
314
+ });
315
+
316
+ it('should fire loadingTimeout_error when a protected route starts login after no session was found', async () => {
317
+ render(
318
+ <OidcProvider
319
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 300 }}
320
+ configurationName="default"
321
+ >
322
+ <div>App</div>
323
+ </OidcProvider>,
324
+ );
325
+
326
+ act(() => {
327
+ mockEventSubscribers.forEach(sub =>
328
+ sub.func('tryKeepExistingSessionAsync_end', { success: false }),
329
+ );
330
+ });
331
+
332
+ act(() => {
333
+ mockEventSubscribers.forEach(sub => sub.func('loginAsync_begin', {}));
334
+ });
335
+
336
+ mockPublishEvent.mockClear();
337
+
338
+ act(() => {
339
+ vi.advanceTimersByTime(300);
340
+ });
341
+
313
342
  expect(mockPublishEvent).toHaveBeenCalledWith('loadingTimeout_error', { timeoutMs: 300 });
314
343
  });
315
344
 
345
+ it('should NOT fire loadingTimeout_error on an anonymous route when session restore fails', async () => {
346
+ render(
347
+ <OidcProvider
348
+ configuration={{ ...baseConfiguration, loading_timeout_ms: 300 }}
349
+ configurationName="default"
350
+ >
351
+ <div>App</div>
352
+ </OidcProvider>,
353
+ );
354
+
355
+ act(() => {
356
+ mockEventSubscribers.forEach(sub =>
357
+ sub.func('tryKeepExistingSessionAsync_error', { message: 'session restore failed' }),
358
+ );
359
+ });
360
+
361
+ mockPublishEvent.mockClear();
362
+
363
+ act(() => {
364
+ vi.advanceTimersByTime(300);
365
+ });
366
+
367
+ expect(mockPublishEvent).not.toHaveBeenCalledWith('loadingTimeout_error', expect.anything());
368
+ });
369
+
316
370
  it('should NOT fire loadingTimeout_error when token_acquired fires before the deadline', async () => {
317
371
  render(
318
372
  <OidcProvider
@@ -90,28 +90,17 @@ const Switch = ({ isLoading, loadingComponent, children, configurationName }) =>
90
90
  const DEFAULT_LOADING_TIMEOUT_MS = 30_000;
91
91
 
92
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.
93
+ * Returns true when an event signals that the OIDC client is no longer
94
+ * loading. Restoring the existing session is complete even when no session was
95
+ * found: an OidcSecure child will emit `loginAsync_begin` if the current route
96
+ * actually requires authentication.
101
97
  */
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
- };
98
+ const isLoadingEndSignal = (name: string): boolean =>
99
+ name === OidcClient.eventNames.token_acquired ||
100
+ name === OidcClient.eventNames.token_renewed ||
101
+ name === OidcClient.eventNames.loginCallbackAsync_end ||
102
+ name === OidcClient.eventNames.tryKeepExistingSessionAsync_end ||
103
+ name === OidcClient.eventNames.tryKeepExistingSessionAsync_error;
115
104
 
116
105
  export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
117
106
  children,
@@ -148,7 +137,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
148
137
 
149
138
  const loading = false;
150
139
  const [event, setEvent] = useState(defaultEventState);
151
- const [isAuthenticatedAndIdle, setIsAuthenticatedAndIdle] = useState<boolean>(false);
140
+ const [isLoadingWatchdogActive, setIsLoadingWatchdogActive] = useState<boolean>(true);
152
141
  const [currentConfigurationName, setConfigurationName] = useState(configurationName);
153
142
 
154
143
  useEffect(() => {
@@ -167,8 +156,10 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
167
156
  useEffect(() => {
168
157
  const oidc = getOidc(configurationName);
169
158
  const newSubscriptionId = oidc.subscribeEvents((name, data) => {
170
- if (isReadySignal(name, data)) {
171
- setIsAuthenticatedAndIdle(true);
159
+ if (name === OidcClient.eventNames.loginAsync_begin) {
160
+ setIsLoadingWatchdogActive(true);
161
+ } else if (isLoadingEndSignal(name)) {
162
+ setIsLoadingWatchdogActive(false);
172
163
  }
173
164
  if (
174
165
  name === OidcClient.eventNames.refreshTokensAsync_error ||
@@ -215,7 +206,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
215
206
  const previousOidc = getOidc(configurationName);
216
207
  previousOidc.removeEventSubscription(newSubscriptionId);
217
208
  setEvent(defaultEventState);
218
- setIsAuthenticatedAndIdle(false);
209
+ setIsLoadingWatchdogActive(true);
219
210
  };
220
211
  }, [configuration, configurationName]);
221
212
 
@@ -224,7 +215,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
224
215
  if (timeoutMs <= 0) {
225
216
  return;
226
217
  }
227
- if (isAuthenticatedAndIdle) {
218
+ if (!isLoadingWatchdogActive) {
228
219
  return;
229
220
  }
230
221
  const oidcInstance = getOidc(configurationName);
@@ -241,7 +232,7 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
241
232
  });
242
233
  }, timeoutMs);
243
234
  return () => clearTimeout(timeoutId);
244
- }, [event.name, isAuthenticatedAndIdle, configurationName, configuration]);
235
+ }, [event.name, isLoadingWatchdogActive, configurationName, configuration]);
245
236
 
246
237
  const SessionLostComponent = sessionLostComponent;
247
238
  const AuthenticatingComponent = authenticatingComponent;
package/src/index.ts CHANGED
@@ -9,15 +9,24 @@ export type {
9
9
  Fetch,
10
10
  ILOidcLocation,
11
11
  OidcConfiguration,
12
+ OidcErrorOptions,
13
+ OidcErrorPhase,
14
+ PushedAuthorizationRequestMode,
12
15
  StringMap,
13
16
  } from '@axa-fr/oidc-client';
14
17
  export type { OidcUserInfo } from '@axa-fr/oidc-client';
15
18
  export {
19
+ isOidcError,
16
20
  isOidcStateError,
21
+ isPushedAuthorizationRequestError,
17
22
  OidcClient,
23
+ OidcError,
24
+ OidcErrorCode,
18
25
  OidcLocation,
19
26
  OidcStateError,
20
27
  OidcStateErrorCode,
28
+ PushedAuthorizationRequestError,
29
+ PushedAuthorizationRequestErrorCode,
21
30
  TokenAutomaticRenewMode,
22
31
  TokenRenewMode,
23
32
  } from '@axa-fr/oidc-client';