@axa-fr/react-oidc 7.25.11 → 7.25.13

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/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as i, jsxs as E, Fragment as m } from "react/jsx-runtime";
2
2
  import { OidcClient as r, getParseQueryStringFromLocation as V, getPath as O, OidcLocation as M, getFetchDefault as X } from "@axa-fr/oidc-client";
3
3
  import { OidcClient as Me, OidcLocation as De, TokenAutomaticRenewMode as xe, TokenRenewMode as We } from "@axa-fr/oidc-client";
4
- import Z, { useCallback as ee, useState as _, useEffect as v } from "react";
4
+ import Z, { useCallback as ee, useState as v, useEffect as f } from "react";
5
5
  const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithTokens(t, e)(...n), Oe = (t = null, s = x, e = !1) => (n) => (o) => {
6
6
  const { fetch: c } = ne(
7
7
  t || o.fetch,
@@ -49,13 +49,13 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
49
49
  configurationName: e,
50
50
  withCustomHistory: n
51
51
  }) => {
52
- const [o, c] = _(!1);
53
- v(() => {
52
+ const [o, c] = v(!1);
53
+ f(() => {
54
54
  let d = !0;
55
55
  return (async () => {
56
- const f = r.get;
56
+ const _ = r.get;
57
57
  try {
58
- const { callbackPath: h } = await f(e).loginCallbackAsync();
58
+ const { callbackPath: h } = await _(e).loginCallbackAsync();
59
59
  (n ? n() : ie()).replaceState(h || "/");
60
60
  } catch (h) {
61
61
  d && (console.warn(h), c(!0));
@@ -72,7 +72,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
72
72
  ] }) }), ue = () => /* @__PURE__ */ i("div", { className: "oidc-session-lost", children: /* @__PURE__ */ E("div", { className: "oidc-session-lost__container", children: [
73
73
  /* @__PURE__ */ i("h1", { className: "oidc-session-lost__title", children: "Session timed out" }),
74
74
  /* @__PURE__ */ i("p", { className: "oidc-session-lost__content", children: "Your session has expired. Please re-authenticate." })
75
- ] }) }), ke = ({ configurationName: t }) => (v(() => {
75
+ ] }) }), ke = ({ configurationName: t }) => (f(() => {
76
76
  (async () => {
77
77
  r.get(t).silentLoginCallbackAsync();
78
78
  })().catch((e) => {
@@ -83,10 +83,10 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
83
83
  let o = null;
84
84
  for (const [c, l] of Object.entries(s))
85
85
  c === "state" || c === "scope" || (o === null && (o = {}), o[c] = l);
86
- return v(() => {
86
+ return f(() => {
87
87
  n.tokens || n.loginAsync(null, o, !0, s.scope);
88
88
  }, []), /* @__PURE__ */ i(m, {});
89
- }, fe = ({
89
+ }, _e = ({
90
90
  callbackErrorComponent: t,
91
91
  callbackSuccessComponent: s,
92
92
  redirect_uri: e,
@@ -96,9 +96,9 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
96
96
  configurationName: l,
97
97
  withCustomHistory: a = null
98
98
  }) => {
99
- const d = window ? O(window.location.href) : "", [u, f] = _(d);
100
- v(() => {
101
- const g = () => f(O(window.location.href));
99
+ const d = window ? O(window.location.href) : "", [u, _] = v(d);
100
+ f(() => {
101
+ const g = () => _(O(window.location.href));
102
102
  return g(), window.addEventListener("popstate", g, !1), () => window.removeEventListener("popstate", g, !1);
103
103
  }, []);
104
104
  const h = O(e);
@@ -120,13 +120,13 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
120
120
  default:
121
121
  return /* @__PURE__ */ i(m, { children: c });
122
122
  }
123
- }, _e = Z.memo(fe), D = { name: "", data: null }, ve = ({
123
+ }, ve = Z.memo(_e), D = { name: "", data: null }, fe = ({
124
124
  loadingComponent: t,
125
125
  children: s,
126
126
  configurationName: e
127
127
  }) => {
128
- const [n, o] = _(!0), c = r.get, l = c(e);
129
- return v(() => {
128
+ const [n, o] = v(!0), c = r.get, l = c(e);
129
+ return f(() => {
130
130
  let d = !0;
131
131
  return l && l.tryKeepExistingSessionAsync().then(() => {
132
132
  d && o(!1);
@@ -148,7 +148,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
148
148
  authenticatingErrorComponent: a = W,
149
149
  sessionLostComponent: d = ue,
150
150
  onSessionLost: u = null,
151
- onLogoutFromAnotherTab: f = null,
151
+ onLogoutFromAnotherTab: _ = null,
152
152
  onLogoutFromSameTab: h = null,
153
153
  withCustomHistory: g = null,
154
154
  onEvent: T = null,
@@ -158,15 +158,15 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
158
158
  const w = (L = "default") => r.getOrCreate(p ?? X, S ?? new M())(
159
159
  s,
160
160
  L
161
- ), [j, B] = _(!0), [z, C] = _(D), [K, $] = _("default");
162
- v(() => {
161
+ ), [j, B] = v(!0), [z, C] = v(D), [K, $] = v("default");
162
+ f(() => {
163
163
  const I = w(e).subscribeEvents((k, b) => {
164
164
  T && T(e, k, b);
165
165
  });
166
166
  return () => {
167
167
  w(e).removeEventSubscription(I);
168
168
  };
169
- }, [e, T]), v(() => {
169
+ }, [e, T]), f(() => {
170
170
  const I = w(e).subscribeEvents((k, b) => {
171
171
  if (k === r.eventNames.refreshTokensAsync_error || k === r.eventNames.syncTokensAsync_error) {
172
172
  if (u != null) {
@@ -175,8 +175,8 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
175
175
  }
176
176
  C({ name: k, data: b });
177
177
  } else if (k === r.eventNames.logout_from_another_tab) {
178
- if (f != null) {
179
- f();
178
+ if (_ != null) {
179
+ _();
180
180
  return;
181
181
  }
182
182
  C({ name: k, data: b });
@@ -239,7 +239,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
239
239
  isLoading: A,
240
240
  configurationName: e,
241
241
  children: /* @__PURE__ */ i(
242
- _e,
242
+ ve,
243
243
  {
244
244
  redirect_uri: N.configuration.redirect_uri,
245
245
  silent_redirect_uri: N.configuration.silent_redirect_uri,
@@ -250,7 +250,7 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
250
250
  configurationName: e,
251
251
  withCustomHistory: g,
252
252
  location: S ?? new M(),
253
- children: /* @__PURE__ */ i(ve, { loadingComponent: y, configurationName: e, children: t })
253
+ children: /* @__PURE__ */ i(fe, { loadingComponent: y, configurationName: e, children: t })
254
254
  }
255
255
  )
256
256
  }
@@ -263,31 +263,31 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
263
263
  configurationName: n = "default"
264
264
  }) => {
265
265
  const o = r.get, c = o(n);
266
- return v(() => {
266
+ return f(() => {
267
267
  c.tokens || c.loginAsync(s, e);
268
268
  }, [n, s, e]), c.tokens ? /* @__PURE__ */ i(m, { children: t }) : null;
269
269
  }, Ee = (t, s = null, e = null, n = "default") => (o) => /* @__PURE__ */ i(ge, { callbackPath: s, extras: e, configurationName: n, children: /* @__PURE__ */ i(t, { ...o }) }), F = "default", U = (t, s) => {
270
270
  let e = !1;
271
271
  return t(s) && (e = t(s).tokens != null), e;
272
272
  }, Se = (t = F) => {
273
- const s = r.get, [e, n] = _(
273
+ const s = r.get, [e, n] = v(
274
274
  U(s, t)
275
275
  );
276
- return v(() => {
276
+ return f(() => {
277
277
  let a = !0;
278
278
  const d = s(t);
279
279
  n(U(s, t));
280
- const u = d.subscribeEvents((f, h) => {
281
- (f === r.eventNames.logout_from_another_tab || f === r.eventNames.logout_from_same_tab || f === r.eventNames.token_acquired) && a && n(U(s, t));
280
+ const u = d.subscribeEvents((_, h) => {
281
+ (_ === r.eventNames.logout_from_another_tab || _ === r.eventNames.logout_from_same_tab || _ === r.eventNames.token_acquired) && a && n(U(s, t));
282
282
  });
283
283
  return () => {
284
284
  a = !1, d.removeEventSubscription(u);
285
285
  };
286
- }, [t]), { login: (a = void 0, d = void 0, u = !1, f = void 0) => s(t).loginAsync(
286
+ }, [t]), { login: (a = void 0, d = void 0, u = !1, _ = void 0) => s(t).loginAsync(
287
287
  a,
288
288
  d,
289
289
  !1,
290
- f,
290
+ _,
291
291
  u
292
292
  ), logout: (a = void 0, d = void 0) => s(t).logoutAsync(a, d), renewTokens: async (a = void 0) => {
293
293
  const d = await s(t).renewTokensAsync(a);
@@ -318,8 +318,8 @@ function ye(t, s) {
318
318
  return t.configuration.demonstrating_proof_of_possession ? (e, n, o = {}) => t.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, e, n, o) : null;
319
319
  }
320
320
  const Ne = (t = F) => {
321
- const s = r.get, [e, n] = _(pe(t));
322
- return v(() => {
321
+ const s = r.get, [e, n] = v(pe(t));
322
+ return f(() => {
323
323
  let o = !0;
324
324
  const c = s(t);
325
325
  if (c.tokens) {
@@ -353,8 +353,8 @@ const Ne = (t = F) => {
353
353
  }
354
354
  return Y;
355
355
  }, Le = (t = F) => {
356
- const s = r.get, [e, n] = _(be(t));
357
- return v(() => {
356
+ const s = r.get, [e, n] = v(be(t));
357
+ return f(() => {
358
358
  let o = !0;
359
359
  const c = s(t);
360
360
  if (c.tokens) {
@@ -376,12 +376,12 @@ const Ne = (t = F) => {
376
376
  };
377
377
  var me = /* @__PURE__ */ ((t) => (t.Unauthenticated = "Unauthenticated", t.Loading = "Loading user", t.Loaded = "User loaded", t.LoadingError = "Error loading user", t))(me || {});
378
378
  const Ie = (t = "default", s = !1) => {
379
- const n = r.get(t).userInfo(), [o, c] = _({
379
+ const n = r.get(t).userInfo(), [o, c] = v({
380
380
  user: n,
381
381
  status: n ? "User loaded" : "Unauthenticated"
382
382
  /* Unauthenticated */
383
- }), [l, a] = _(n ? 1 : 0), [d, u] = _(n ? 1 : 0);
384
- v(() => {
383
+ }), [l, a] = v(n ? 1 : 0), [d, u] = v(n ? 1 : 0);
384
+ f(() => {
385
385
  const h = r.get(t);
386
386
  let g = !0;
387
387
  if (h && h.tokens) {
@@ -420,10 +420,10 @@ const Ie = (t = "default", s = !1) => {
420
420
  g = !1, h.removeEventSubscription(T);
421
421
  };
422
422
  }, [l]);
423
- const f = () => {
423
+ const _ = () => {
424
424
  a(l + 1);
425
425
  };
426
- return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: f };
426
+ return { oidcUser: o.user, oidcUserLoadingState: o.status, reloadOidcUser: _ };
427
427
  };
428
428
  export {
429
429
  Me as OidcClient,
@@ -1 +1 @@
1
- (function(k,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],n):(k=typeof globalThis<"u"?globalThis:k||self,n(k["react-oidc"]={},k.jsxRuntime,k.oidcClient,k.React))})(this,function(k,n,s,l){"use strict";const F="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},I=(t=null,c=F,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(o,()=>r(c),e)(d,a),[o,c])}},U=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),n.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),n.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,c)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=c.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},H=(t,c,e)=>({replaceState:(o,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,o),t.dispatchEvent(c("popstate"))}}),Q=()=>H(window,G(window,document),$),M=()=>n.jsx("div",{className:"oidc-callback",children:n.jsxs("div",{className:"oidc-callback__container",children:[n.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),n.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:c,configurationName:e,withCustomHistory:o})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const _=s.OidcClient.get;try{const{callbackPath:O}=await _(e).loginCallbackAsync();(o?o():Q()).replaceState(O||"/")}catch(O){u&&(console.warn(O),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=c||M;return r?n.jsx(d,{configurationName:e}):n.jsx(a,{configurationName:e})},V=()=>n.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>n.jsx("div",{className:"oidc-serviceworker",children:n.jsxs("div",{className:"oidc-serviceworker__container",children:[n.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),n.jsx("p",{className:"oidc-serviceworker__content",children:"Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."})]})}),Z=()=>n.jsx("div",{className:"oidc-session-lost",children:n.jsxs("div",{className:"oidc-session-lost__container",children:[n.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),n.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const c=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,d]of Object.entries(c))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,c.scope)},[]),n.jsx(n.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:c,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,_]=l.useState(u);l.useEffect(()=>{const g=()=>_(s.getPath(window.location.href));return g(),window.addEventListener("popstate",g,!1),()=>window.removeEventListener("popstate",g,!1)},[]);const O=s.getPath(e);if(o&&f===s.getPath(o))return n.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return n.jsx(R,{configurationName:d});switch(f){case O:return n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a});default:return n.jsx(n.Fragment,{children:i})}},te=l.memo(ee),q={name:"",data:null},se=({loadingComponent:t,children:c,configurationName:e})=>{const[o,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return n.jsx(n.Fragment,{children:o?n.jsx(a,{configurationName:e}):n.jsx(n.Fragment,{children:c})})},p=({isLoading:t,loadingComponent:c,children:e,configurationName:o})=>{const r=c;return t?n.jsx(r,{configurationName:o,children:e}):n.jsx(n.Fragment,{children:e})},ne=({children:t,configuration:c,configurationName:e="default",callbackSuccessComponent:o=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:O=null,withCustomHistory:g=null,onEvent:T=null,getFetch:v=null,location:P=null})=>{const w=(N="default")=>s.OidcClient.getOrCreate(v??s.getFetchDefault,P??new s.OidcLocation)(c,N),[fe,ke]=l.useState(!0),[he,S]=l.useState(q),[Oe,_e]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{T&&T(e,h,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{if(h===s.OidcClient.eventNames.refreshTokensAsync_error||h===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:h,data:b})}else if(h===s.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}S({name:h,data:b})}else h===s.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():h===s.OidcClient.eventNames.loginAsync_begin||h===s.OidcClient.eventNames.loginCallbackAsync_end||h===s.OidcClient.eventNames.loginAsync_error||h===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:h,data:b}):h===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:h,data:b})});return _e(e),ke(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[c,e]);const ge=u,ve=r,y=i,ye=d,be=a,A=fe||Oe!==e,L=w(e);switch(he.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ge,{configurationName:e})});default:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(te,{redirect_uri:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:g,location:P??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},D=({children:t,callbackPath:c=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return l.useEffect(()=>{i.tokens||i.loginAsync(c,e)},[o,c,e]),i.tokens?n.jsx(n.Fragment,{children:t}):null},oe=(t,c=null,e=null,o="default")=>r=>n.jsx(D,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),E="default",C=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},ce=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(C(c,t));return l.useEffect(()=>{let a=!0;const u=c(t);o(C(c,t));const f=u.subscribeEvents((_,O)=>{(_===s.OidcClient.eventNames.logout_from_another_tab||_===s.OidcClient.eventNames.logout_from_same_tab||_===s.OidcClient.eventNames.token_acquired)&&a&&o(C(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,_=void 0)=>c(t).loginAsync(a,u,!1,_,f),logout:(a=void 0,u=void 0)=>c(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await c(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,i):null}}return W};function ie(t,c){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,e,o,r):null}const ae=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},de=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({idToken:a.idToken,idTokenPayload:a.idTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",c=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[d,a]=l.useState(o?1:0),[u,f]=l.useState(o?1:0);l.useEffect(()=>{const O=s.OidcClient.get(t);let g=!0;if(O&&O.tokens){const v=d===u;if(v&&O.userInfo())return;i({...r,status:"Loading user"}),O.userInfoAsync(!v,c).then(P=>{g&&i({user:P,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"})),f(d)}else i({user:null,status:"Unauthenticated"});const T=O.subscribeEvents(v=>{(v===s.OidcClient.eventNames.logout_from_another_tab||v===s.OidcClient.eventNames.logout_from_same_tab)&&g&&i({user:null,status:"Unauthenticated"})});return()=>{g=!1,O.removeEventSubscription(T)}},[d]);const _=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:_}};Object.defineProperty(k,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(k,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(k,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(k,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),k.OidcProvider=ne,k.OidcSecure=D,k.OidcUserStatus=Y,k.useOidc=ce,k.useOidcAccessToken=ae,k.useOidcFetch=I,k.useOidcIdToken=de,k.useOidcUser=ue,k.withOidcFetch=z,k.withOidcSecure=oe,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@axa-fr/oidc-client"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@axa-fr/oidc-client","react"],n):(k=typeof globalThis<"u"?globalThis:k||self,n(k["react-oidc"]={},k.jsxRuntime,k.oidcClient,k.React))})(this,function(k,n,s,l){"use strict";const F="default",B=(t,c,e=!1)=>async(...o)=>await c().fetchWithTokens(t,e)(...o),z=(t=null,c=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,c,e);return n.jsx(o,{...r,fetch:i})},I=(t=null,c=F,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:l.useCallback((d,a)=>B(o,()=>r(c),e)(d,a),[o,c])}},U=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),n.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),K=()=>n.jsx("div",{className:"oidc-authenticating",children:n.jsxs("div",{className:"oidc-authenticating__container",children:[n.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),n.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),$=()=>Math.random().toString(36).slice(2,8),G=(t,c)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=c.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},H=(t,c,e)=>({replaceState:(o,r)=>{const i=e(),d=r||t.history.state;t.history.replaceState({key:i,state:d},null,o),t.dispatchEvent(c("popstate"))}}),Q=()=>H(window,G(window,document),$),M=()=>n.jsx("div",{className:"oidc-callback",children:n.jsxs("div",{className:"oidc-callback__container",children:[n.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),n.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),J=({callBackError:t,callBackSuccess:c,configurationName:e,withCustomHistory:o})=>{const[r,i]=l.useState(!1);l.useEffect(()=>{let u=!0;return(async()=>{const _=s.OidcClient.get;try{const{callbackPath:O}=await _(e).loginCallbackAsync();(o?o():Q()).replaceState(O||"/")}catch(O){u&&(console.warn(O),i(!0))}})(),()=>{u=!1}},[]);const d=t||U,a=c||M;return r?n.jsx(d,{configurationName:e}):n.jsx(a,{configurationName:e})},V=()=>n.jsx("span",{className:"oidc-loading",children:"Loading"}),X=()=>n.jsx("div",{className:"oidc-serviceworker",children:n.jsxs("div",{className:"oidc-serviceworker__container",children:[n.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),n.jsx("p",{className:"oidc-serviceworker__content",children:"Your browser is not secure enough to make authentication work. Try updating your browser or use a newer browser."})]})}),Z=()=>n.jsx("div",{className:"oidc-session-lost",children:n.jsxs("div",{className:"oidc-session-lost__container",children:[n.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),n.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),x=({configurationName:t})=>(l.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),R=({configurationName:t})=>{const c=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,d]of Object.entries(c))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=d);return l.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,c.scope)},[]),n.jsx(n.Fragment,{})},ee=({callbackErrorComponent:t,callbackSuccessComponent:c,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:d,withCustomHistory:a=null})=>{const u=window?s.getPath(window.location.href):"",[f,_]=l.useState(u);l.useEffect(()=>{const v=()=>_(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const O=s.getPath(e);if(o&&f===s.getPath(o))return n.jsx(x,{configurationName:d});if(r&&f===s.getPath(r))return n.jsx(R,{configurationName:d});switch(f){case O:return n.jsx(J,{callBackError:t,callBackSuccess:c,configurationName:d,withCustomHistory:a});default:return n.jsx(n.Fragment,{children:i})}},te=l.memo(ee),q={name:"",data:null},se=({loadingComponent:t,children:c,configurationName:e})=>{const[o,r]=l.useState(!0),i=s.OidcClient.get,d=i(e);l.useEffect(()=>{let u=!0;return d&&d.tryKeepExistingSessionAsync().then(()=>{u&&r(!1)}),()=>{u=!1}},[e]);const a=t;return n.jsx(n.Fragment,{children:o?n.jsx(a,{configurationName:e}):n.jsx(n.Fragment,{children:c})})},p=({isLoading:t,loadingComponent:c,children:e,configurationName:o})=>{const r=c;return t?n.jsx(r,{configurationName:o,children:e}):n.jsx(n.Fragment,{children:e})},ne=({children:t,configuration:c,configurationName:e="default",callbackSuccessComponent:o=M,authenticatingComponent:r=K,loadingComponent:i=V,serviceWorkerNotSupportedComponent:d=X,authenticatingErrorComponent:a=U,sessionLostComponent:u=Z,onSessionLost:f=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:O=null,withCustomHistory:v=null,onEvent:T=null,getFetch:g=null,location:P=null})=>{const w=(N="default")=>s.OidcClient.getOrCreate(g??s.getFetchDefault,P??new s.OidcLocation)(c,N),[fe,ke]=l.useState(!0),[he,S]=l.useState(q),[Oe,_e]=l.useState("default");l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{T&&T(e,h,b)});return()=>{w(e).removeEventSubscription(m)}},[e,T]),l.useEffect(()=>{const m=w(e).subscribeEvents((h,b)=>{if(h===s.OidcClient.eventNames.refreshTokensAsync_error||h===s.OidcClient.eventNames.syncTokensAsync_error){if(f!=null){f();return}S({name:h,data:b})}else if(h===s.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}S({name:h,data:b})}else h===s.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():h===s.OidcClient.eventNames.loginAsync_begin||h===s.OidcClient.eventNames.loginCallbackAsync_end||h===s.OidcClient.eventNames.loginAsync_error||h===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:h,data:b}):h===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&c.service_worker_only===!0&&S({name:h,data:b})});return _e(e),ke(!1),()=>{w(e).removeEventSubscription(m),S(q)}},[c,e]);const ve=u,ge=r,y=i,ye=d,be=a,A=fe||Oe!==e,L=w(e);switch(he.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ge,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(be,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(ve,{configurationName:e})});default:return n.jsx(p,{loadingComponent:y,isLoading:A,configurationName:e,children:n.jsx(te,{redirect_uri:L.configuration.redirect_uri,silent_redirect_uri:L.configuration.silent_redirect_uri,silent_login_uri:L.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:P??new s.OidcLocation,children:n.jsx(se,{loadingComponent:y,configurationName:e,children:t})})})}},D=({children:t,callbackPath:c=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return l.useEffect(()=>{i.tokens||i.loginAsync(c,e)},[o,c,e]),i.tokens?n.jsx(n.Fragment,{children:t}):null},oe=(t,c=null,e=null,o="default")=>r=>n.jsx(D,{callbackPath:c,extras:e,configurationName:o,children:n.jsx(t,{...r})}),E="default",C=(t,c)=>{let e=!1;return t(c)&&(e=t(c).tokens!=null),e},ce=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(C(c,t));return l.useEffect(()=>{let a=!0;const u=c(t);o(C(c,t));const f=u.subscribeEvents((_,O)=>{(_===s.OidcClient.eventNames.logout_from_another_tab||_===s.OidcClient.eventNames.logout_from_same_tab||_===s.OidcClient.eventNames.token_acquired)&&a&&o(C(c,t))});return()=>{a=!1,u.removeEventSubscription(f)}},[t]),{login:(a=void 0,u=void 0,f=!1,_=void 0)=>c(t).loginAsync(a,u,!1,_,f),logout:(a=void 0,u=void 0)=>c(t).logoutAsync(a,u),renewTokens:async(a=void 0)=>{const u=await c(t).renewTokensAsync(a);return{accessToken:u.accessToken,accessTokenPayload:u.accessTokenPayload,idToken:u.idToken,idTokenPayload:u.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},re=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:e.configuration.demonstrating_proof_of_possession?(r,i)=>e.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,r,i):null}}return W};function ie(t,c){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(c.accessToken,e,o,r):null}const ae=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(re(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{accessToken:f.accessToken,accessTokenPayload:f.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ie(i,f)}:W)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e},j={idToken:null,idTokenPayload:null},le=t=>{const c=s.OidcClient.get,e=c(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},de=(t=E)=>{const c=s.OidcClient.get,[e,o]=l.useState(le(t));return l.useEffect(()=>{let r=!0;const i=c(t);if(i.tokens){const a=i.tokens;o({idToken:a.idToken,idTokenPayload:a.idTokenPayload})}const d=i.subscribeEvents((a,u)=>{if((a===s.OidcClient.eventNames.token_renewed||a===s.OidcClient.eventNames.token_acquired||a===s.OidcClient.eventNames.logout_from_another_tab||a===s.OidcClient.eventNames.logout_from_same_tab||a===s.OidcClient.eventNames.refreshTokensAsync_error||a===s.OidcClient.eventNames.syncTokensAsync_error)&&r){const f=i.tokens;o(f!=null?{idToken:f.idToken,idTokenPayload:f.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(d)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const ue=(t="default",c=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=l.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[d,a]=l.useState(o?1:0),[u,f]=l.useState(o?1:0);l.useEffect(()=>{const O=s.OidcClient.get(t);let v=!0;if(O&&O.tokens){const g=d===u;if(g&&O.userInfo())return;i({...r,status:"Loading user"}),O.userInfoAsync(!g,c).then(P=>{v&&i({user:P,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"})),f(d)}else i({user:null,status:"Unauthenticated"});const T=O.subscribeEvents(g=>{(g===s.OidcClient.eventNames.logout_from_another_tab||g===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,O.removeEventSubscription(T)}},[d]);const _=()=>{a(d+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:_}};Object.defineProperty(k,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(k,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(k,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(k,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),k.OidcProvider=ne,k.OidcSecure=D,k.OidcUserStatus=Y,k.useOidc=ce,k.useOidcAccessToken=ae,k.useOidcFetch=I,k.useOidcIdToken=de,k.useOidcUser=ue,k.withOidcFetch=z,k.withOidcSecure=oe,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.25.11",
3
+ "version": "7.25.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -40,8 +40,8 @@
40
40
  "lint": "eslint src"
41
41
  },
42
42
  "dependencies": {
43
- "@axa-fr/oidc-client-service-worker": "7.25.11",
44
- "@axa-fr/oidc-client": "7.25.11"
43
+ "@axa-fr/oidc-client-service-worker": "7.25.13",
44
+ "@axa-fr/oidc-client": "7.25.13"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
@@ -50,21 +50,21 @@
50
50
  "@testing-library/jest-dom": "6.6.3",
51
51
  "@testing-library/react": "16.3.0",
52
52
  "@testing-library/user-event": "14.6.1",
53
- "@types/react": "19.1.1",
54
- "@vitejs/plugin-react": "4.3.4",
55
- "@vitest/coverage-v8": "3.1.1",
53
+ "@types/react": "19.1.2",
54
+ "@vitejs/plugin-react": "4.4.1",
55
+ "@vitest/coverage-v8": "3.1.3",
56
56
  "cpy": "11.1.0",
57
57
  "cpy-cli": "^5.0.0",
58
58
  "cross-env": "^7.0.3",
59
59
  "jsdom": "26.1.0",
60
- "msw": "2.7.4",
60
+ "msw": "2.7.6",
61
61
  "react": "^19.1.0",
62
62
  "react-dom": "^19.1.0",
63
63
  "rimraf": "6.0.1",
64
64
  "typescript": "5.8.3",
65
- "vite": "6.2.6",
65
+ "vite": "6.3.5",
66
66
  "vite-plugin-dts": "4.5.3",
67
- "vitest": "3.1.1"
67
+ "vitest": "3.1.3"
68
68
  },
69
69
  "license": "MIT",
70
70
  "publishConfig": {