@axa-fr/react-oidc 7.26.4 → 7.26.5

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.
@@ -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;AAWlF,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,kCAAkC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAoLjE,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;AAWlF,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,kCAAkC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACxD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;IACpC,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,iBAAiB,CAAC,EAAE,MAAM,aAAa,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAqCF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAmLjE,CAAC;AAEF,eAAe,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -176,7 +176,7 @@ const x = "default", Z = (t, s, e = !1) => async (...n) => await s().fetchWithTo
176
176
  } else h === c.eventNames.logout_from_same_tab ? k?.() : h === c.eventNames.loginAsync_begin || h === c.eventNames.loginCallbackAsync_end || h === c.eventNames.loginAsync_error || h === c.eventNames.loginCallbackAsync_error ? C({ name: h, data: g }) : h === c.eventNames.service_worker_not_supported_by_browser && s.service_worker_only === !0 && C({ name: h, data: g });
177
177
  });
178
178
  return queueMicrotask(() => {
179
- M(e), setLoading(!1);
179
+ M(e);
180
180
  }), () => {
181
181
  T(e).removeEventSubscription(I), C(q);
182
182
  };
@@ -1 +1 @@
1
- (function(f,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,(function(f,c,s,d){"use strict";const F="default",z=(t,n,e=!1)=>async(...o)=>await n().fetchWithTokens(t,e)(...o),K=(t=null,n=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,n,e);return c.jsx(o,{...r,fetch:i})},I=(t=null,n=F,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:d.useCallback((u,a)=>z(o,()=>r(n),e)(u,a),[o,n,e])}},U=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),c.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),c.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),G=()=>Math.random().toString(36).slice(2,8),H=(t,n)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=n.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},Q=(t,n,e)=>({replaceState:(o,r)=>{const i=e(),u=r||t.history.state;t.history.replaceState({key:i,state:u},null,o),t.dispatchEvent(n("popstate"))}}),J=()=>Q(window,H(window,document),G),m=()=>c.jsx("div",{className:"oidc-callback",children:c.jsxs("div",{className:"oidc-callback__container",children:[c.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),c.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),V=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:o})=>{const[r,i]=d.useState(!1);d.useEffect(()=>{let l=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(o?o():J()).replaceState(_||"/")}catch(_){l&&(console.warn(_),i(!0))}})(),()=>{l=!1}},[]);const u=t||U,a=n||m;return r?c.jsx(u,{configurationName:e}):c.jsx(a,{configurationName:e})},X=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),Z=()=>c.jsx("div",{className:"oidc-serviceworker",children:c.jsxs("div",{className:"oidc-serviceworker__container",children:[c.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),c.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."})]})}),x=()=>c.jsx("div",{className:"oidc-session-lost",children:c.jsxs("div",{className:"oidc-session-lost__container",children:[c.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),c.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),R=({configurationName:t})=>(d.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),ee=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,u]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=u);return d.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,n.scope)},[]),c.jsx(c.Fragment,{})},te=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:u,withCustomHistory:a=null})=>{const l=window?s.getPath(window.location.href):"",[h,O]=d.useState(l);d.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);return o&&h===s.getPath(o)?c.jsx(R,{configurationName:u}):r&&h===s.getPath(r)?c.jsx(ee,{configurationName:u}):h===_?c.jsx(V,{callBackError:t,callBackSuccess:n,configurationName:u,withCustomHistory:a}):c.jsx(c.Fragment,{children:i})},se=d.memo(te),M={name:"",data:null},ne=({loadingComponent:t,children:n,configurationName:e})=>{const[o,r]=d.useState(!0),i=s.OidcClient.get,u=i(e);d.useEffect(()=>{let l=!0;return u&&u.tryKeepExistingSessionAsync().then(()=>{l&&r(!1)}),()=>{l=!1}},[e]);const a=t;return c.jsx(c.Fragment,{children:o?c.jsx(a,{configurationName:e}):c.jsx(c.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:o})=>{const r=n;return t?c.jsx(r,{configurationName:o,children:e}):c.jsx(c.Fragment,{children:e})},ce=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:o=m,authenticatingComponent:r=$,loadingComponent:i=X,serviceWorkerNotSupportedComponent:u=Z,authenticatingErrorComponent:a=U,sessionLostComponent:l=x,onSessionLost:h=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:w=null,getFetch:y=null,location:E=null})=>{if(n&&n.redirect_uri&&n.silent_redirect_uri&&n.redirect_uri===n.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const T=(L="default")=>s.OidcClient.getOrCreate(y??s.getFetchDefault,E??new s.OidcLocation)(n,L),[fe,S]=d.useState(M),[ke,B]=d.useState(e);d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{w&&w(e,k,g)});return()=>{T(e).removeEventSubscription(N)}},[e,w]),d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(h!=null){h();return}S({name:k,data:g})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:g})}else k===s.OidcClient.eventNames.logout_from_same_tab?_?.():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:g}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&S({name:k,data:g})});return queueMicrotask(()=>{B(e),setLoading(!1)}),()=>{T(e).removeEventSubscription(N),S(M)}},[n,e]),d.useEffect(()=>{B(e)},[e]);const _e=l,Oe=r,b=i,ve=u,ye=a,A=ke!==e,C=T(e);switch(fe.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(Oe,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(_e,{configurationName:e})});default:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(se,{redirect_uri:C.configuration.redirect_uri,silent_redirect_uri:C.configuration.silent_redirect_uri,silent_login_uri:C.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:E??new s.OidcLocation,children:c.jsx(ne,{loadingComponent:b,configurationName:e,children:t})})})}},q=({children:t,callbackPath:n=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return d.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[o,n,e]),i.tokens?c.jsx(c.Fragment,{children:t}):null},oe=(t,n=null,e=null,o="default")=>r=>c.jsx(q,{callbackPath:n,extras:e,configurationName:o,children:c.jsx(t,{...r})}),P="default",D=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},re=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>D(n,t));return d.useEffect(()=>{let a=!0;const l=n(t),h=l.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&o(D(n,t))});return()=>{a=!1,l.removeEventSubscription(h)}},[t]),{login:(a=void 0,l=void 0,h=!1,O=void 0)=>n(t).loginAsync(a,l,!1,O,h),logout:(a=void 0,l=void 0)=>n(t).logoutAsync(a,l),renewTokens:async(a=void 0)=>{const l=await n(t).renewTokensAsync(a);return{accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload,idToken:l.idToken,idTokenPayload:l.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},ie=t=>{const n=s.OidcClient.get,e=n(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 ae(t,n){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,o,r):null}const le=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>ie(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{accessToken:h.accessToken,accessTokenPayload:h.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(i,h)}:W)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e},j={idToken:null,idTokenPayload:null},de=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},ue=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>de(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{idToken:h.idToken,idTokenPayload:h.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const he=(t="default",n=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=d.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[u,a]=d.useState(o?1:0),[l,h]=d.useState(o?1:0);d.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const y=u===l;if(y&&_.userInfo())return;queueMicrotask(()=>{v&&(i({...r,status:"Loading user"}),h(u))}),_.userInfoAsync(!y,n).then(E=>{v&&i({user:E,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{v&&i({user:null,status:"Unauthenticated"})});const w=_.subscribeEvents(y=>{(y===s.OidcClient.eventNames.logout_from_another_tab||y===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(w)}},[u,t,n,l]);const O=()=>{a(u+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),f.OidcProvider=ce,f.OidcSecure=q,f.OidcUserStatus=Y,f.useOidc=re,f.useOidcAccessToken=le,f.useOidcFetch=I,f.useOidcIdToken=ue,f.useOidcUser=he,f.withOidcFetch=K,f.withOidcSecure=oe,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(f,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["react-oidc"]={},f.jsxRuntime,f.oidcClient,f.React))})(this,(function(f,c,s,d){"use strict";const F="default",z=(t,n,e=!1)=>async(...o)=>await n().fetchWithTokens(t,e)(...o),K=(t=null,n=F,e=!1)=>o=>r=>{const{fetch:i}=I(t||r.fetch,n,e);return c.jsx(o,{...r,fetch:i})},I=(t=null,n=F,e=!1)=>{const o=t||window.fetch,r=s.OidcClient.get;return{fetch:d.useCallback((u,a)=>z(o,()=>r(n),e)(u,a),[o,n,e])}},U=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),c.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$=()=>c.jsx("div",{className:"oidc-authenticating",children:c.jsxs("div",{className:"oidc-authenticating__container",children:[c.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),c.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),G=()=>Math.random().toString(36).slice(2,8),H=(t,n)=>(e,o)=>{if(typeof t.CustomEvent=="function")return new t.CustomEvent(e,o);const r=o||{bubbles:!1,cancelable:!1,detail:void 0},i=n.createEvent("CustomEvent");return i.initCustomEvent(e,r.bubbles,r.cancelable,r.detail),i.prototype=t.Event.prototype,i},Q=(t,n,e)=>({replaceState:(o,r)=>{const i=e(),u=r||t.history.state;t.history.replaceState({key:i,state:u},null,o),t.dispatchEvent(n("popstate"))}}),J=()=>Q(window,H(window,document),G),m=()=>c.jsx("div",{className:"oidc-callback",children:c.jsxs("div",{className:"oidc-callback__container",children:[c.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),c.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),V=({callBackError:t,callBackSuccess:n,configurationName:e,withCustomHistory:o})=>{const[r,i]=d.useState(!1);d.useEffect(()=>{let l=!0;return(async()=>{const O=s.OidcClient.get;try{const{callbackPath:_}=await O(e).loginCallbackAsync();(o?o():J()).replaceState(_||"/")}catch(_){l&&(console.warn(_),i(!0))}})(),()=>{l=!1}},[]);const u=t||U,a=n||m;return r?c.jsx(u,{configurationName:e}):c.jsx(a,{configurationName:e})},X=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),Z=()=>c.jsx("div",{className:"oidc-serviceworker",children:c.jsxs("div",{className:"oidc-serviceworker__container",children:[c.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),c.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."})]})}),x=()=>c.jsx("div",{className:"oidc-session-lost",children:c.jsxs("div",{className:"oidc-session-lost__container",children:[c.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),c.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),R=({configurationName:t})=>(d.useEffect(()=>{(async()=>{s.OidcClient.get(t).silentLoginCallbackAsync()})().catch(e=>{console.error("Error during silent login callback:",e)})},[t]),null),ee=({configurationName:t})=>{const n=s.getParseQueryStringFromLocation(window.location.href),e=s.OidcClient.get,o=e(t);let r=null;for(const[i,u]of Object.entries(n))i==="state"||i==="scope"||(r===null&&(r={}),r[i]=u);return d.useEffect(()=>{o.tokens||o.loginAsync(null,r,!0,n.scope)},[]),c.jsx(c.Fragment,{})},te=({callbackErrorComponent:t,callbackSuccessComponent:n,redirect_uri:e,silent_redirect_uri:o,silent_login_uri:r,children:i,configurationName:u,withCustomHistory:a=null})=>{const l=window?s.getPath(window.location.href):"",[h,O]=d.useState(l);d.useEffect(()=>{const v=()=>O(s.getPath(window.location.href));return v(),window.addEventListener("popstate",v,!1),()=>window.removeEventListener("popstate",v,!1)},[]);const _=s.getPath(e);return o&&h===s.getPath(o)?c.jsx(R,{configurationName:u}):r&&h===s.getPath(r)?c.jsx(ee,{configurationName:u}):h===_?c.jsx(V,{callBackError:t,callBackSuccess:n,configurationName:u,withCustomHistory:a}):c.jsx(c.Fragment,{children:i})},se=d.memo(te),M={name:"",data:null},ne=({loadingComponent:t,children:n,configurationName:e})=>{const[o,r]=d.useState(!0),i=s.OidcClient.get,u=i(e);d.useEffect(()=>{let l=!0;return u&&u.tryKeepExistingSessionAsync().then(()=>{l&&r(!1)}),()=>{l=!1}},[e]);const a=t;return c.jsx(c.Fragment,{children:o?c.jsx(a,{configurationName:e}):c.jsx(c.Fragment,{children:n})})},p=({isLoading:t,loadingComponent:n,children:e,configurationName:o})=>{const r=n;return t?c.jsx(r,{configurationName:o,children:e}):c.jsx(c.Fragment,{children:e})},ce=({children:t,configuration:n,configurationName:e="default",callbackSuccessComponent:o=m,authenticatingComponent:r=$,loadingComponent:i=X,serviceWorkerNotSupportedComponent:u=Z,authenticatingErrorComponent:a=U,sessionLostComponent:l=x,onSessionLost:h=null,onLogoutFromAnotherTab:O=null,onLogoutFromSameTab:_=null,withCustomHistory:v=null,onEvent:w=null,getFetch:y=null,location:E=null})=>{if(n&&n.redirect_uri&&n.silent_redirect_uri&&n.redirect_uri===n.silent_redirect_uri)throw new Error("redirect_uri and silent_redirect_uri must be different");const T=(L="default")=>s.OidcClient.getOrCreate(y??s.getFetchDefault,E??new s.OidcLocation)(n,L),[fe,S]=d.useState(M),[ke,B]=d.useState(e);d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{w&&w(e,k,g)});return()=>{T(e).removeEventSubscription(N)}},[e,w]),d.useEffect(()=>{const N=T(e).subscribeEvents((k,g)=>{if(k===s.OidcClient.eventNames.refreshTokensAsync_error||k===s.OidcClient.eventNames.syncTokensAsync_error){if(h!=null){h();return}S({name:k,data:g})}else if(k===s.OidcClient.eventNames.logout_from_another_tab){if(O!=null){O();return}S({name:k,data:g})}else k===s.OidcClient.eventNames.logout_from_same_tab?_?.():k===s.OidcClient.eventNames.loginAsync_begin||k===s.OidcClient.eventNames.loginCallbackAsync_end||k===s.OidcClient.eventNames.loginAsync_error||k===s.OidcClient.eventNames.loginCallbackAsync_error?S({name:k,data:g}):k===s.OidcClient.eventNames.service_worker_not_supported_by_browser&&n.service_worker_only===!0&&S({name:k,data:g})});return queueMicrotask(()=>{B(e)}),()=>{T(e).removeEventSubscription(N),S(M)}},[n,e]),d.useEffect(()=>{B(e)},[e]);const _e=l,Oe=r,b=i,ve=u,ye=a,A=ke!==e,C=T(e);switch(fe.name){case s.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ve,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_begin:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(Oe,{configurationName:e})});case s.OidcClient.eventNames.loginAsync_error:case s.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(ye,{configurationName:e})});case s.OidcClient.eventNames.refreshTokensAsync_error:case s.OidcClient.eventNames.syncTokensAsync_error:case s.OidcClient.eventNames.logout_from_another_tab:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(_e,{configurationName:e})});default:return c.jsx(p,{loadingComponent:b,isLoading:A,configurationName:e,children:c.jsx(se,{redirect_uri:C.configuration.redirect_uri,silent_redirect_uri:C.configuration.silent_redirect_uri,silent_login_uri:C.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:a,authenticatingComponent:r,configurationName:e,withCustomHistory:v,location:E??new s.OidcLocation,children:c.jsx(ne,{loadingComponent:b,configurationName:e,children:t})})})}},q=({children:t,callbackPath:n=null,extras:e=null,configurationName:o="default"})=>{const r=s.OidcClient.get,i=r(o);return d.useEffect(()=>{i.tokens||i.loginAsync(n,e)},[o,n,e]),i.tokens?c.jsx(c.Fragment,{children:t}):null},oe=(t,n=null,e=null,o="default")=>r=>c.jsx(q,{callbackPath:n,extras:e,configurationName:o,children:c.jsx(t,{...r})}),P="default",D=(t,n)=>{let e=!1;return t(n)&&(e=t(n).tokens!=null),e},re=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>D(n,t));return d.useEffect(()=>{let a=!0;const l=n(t),h=l.subscribeEvents((O,_)=>{(O===s.OidcClient.eventNames.logout_from_another_tab||O===s.OidcClient.eventNames.logout_from_same_tab||O===s.OidcClient.eventNames.token_acquired)&&a&&o(D(n,t))});return()=>{a=!1,l.removeEventSubscription(h)}},[t]),{login:(a=void 0,l=void 0,h=!1,O=void 0)=>n(t).loginAsync(a,l,!1,O,h),logout:(a=void 0,l=void 0)=>n(t).logoutAsync(a,l),renewTokens:async(a=void 0)=>{const l=await n(t).renewTokensAsync(a);return{accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload,idToken:l.idToken,idTokenPayload:l.idTokenPayload}},isAuthenticated:e}},W={accessToken:null,accessTokenPayload:null},ie=t=>{const n=s.OidcClient.get,e=n(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 ae(t,n){return t.configuration.demonstrating_proof_of_possession?(e,o,r={})=>t.generateDemonstrationOfProofOfPossessionAsync(n.accessToken,e,o,r):null}const le=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>ie(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{accessToken:h.accessToken,accessTokenPayload:h.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:ae(i,h)}:W)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e},j={idToken:null,idTokenPayload:null},de=t=>{const n=s.OidcClient.get,e=n(t);if(e.tokens){const o=e.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return j},ue=(t=P)=>{const n=s.OidcClient.get,[e,o]=d.useState(()=>de(t));return d.useEffect(()=>{let r=!0;const i=n(t),u=i.subscribeEvents((a,l)=>{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 h=i.tokens;o(h!=null?{idToken:h.idToken,idTokenPayload:h.idTokenPayload}:j)}});return()=>{r=!1,i.removeEventSubscription(u)}},[t]),e};var Y=(t=>(t.Unauthenticated="Unauthenticated",t.Loading="Loading user",t.Loaded="User loaded",t.LoadingError="Error loading user",t))(Y||{});const he=(t="default",n=!1)=>{const o=s.OidcClient.get(t).userInfo(),[r,i]=d.useState({user:o,status:o?"User loaded":"Unauthenticated"}),[u,a]=d.useState(o?1:0),[l,h]=d.useState(o?1:0);d.useEffect(()=>{const _=s.OidcClient.get(t);let v=!0;if(_&&_.tokens){const y=u===l;if(y&&_.userInfo())return;queueMicrotask(()=>{v&&(i({...r,status:"Loading user"}),h(u))}),_.userInfoAsync(!y,n).then(E=>{v&&i({user:E,status:"User loaded"})}).catch(()=>i({...r,status:"Error loading user"}))}else queueMicrotask(()=>{v&&i({user:null,status:"Unauthenticated"})});const w=_.subscribeEvents(y=>{(y===s.OidcClient.eventNames.logout_from_another_tab||y===s.OidcClient.eventNames.logout_from_same_tab)&&v&&i({user:null,status:"Unauthenticated"})});return()=>{v=!1,_.removeEventSubscription(w)}},[u,t,n,l]);const O=()=>{a(u+1)};return{oidcUser:r.user,oidcUserLoadingState:r.status,reloadOidcUser:O}};Object.defineProperty(f,"OidcClient",{enumerable:!0,get:()=>s.OidcClient}),Object.defineProperty(f,"OidcLocation",{enumerable:!0,get:()=>s.OidcLocation}),Object.defineProperty(f,"TokenAutomaticRenewMode",{enumerable:!0,get:()=>s.TokenAutomaticRenewMode}),Object.defineProperty(f,"TokenRenewMode",{enumerable:!0,get:()=>s.TokenRenewMode}),f.OidcProvider=ce,f.OidcSecure=q,f.OidcUserStatus=Y,f.useOidc=re,f.useOidcAccessToken=le,f.useOidcFetch=I,f.useOidcIdToken=ue,f.useOidcUser=he,f.withOidcFetch=K,f.withOidcSecure=oe,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/react-oidc",
3
- "version": "7.26.4",
3
+ "version": "7.26.5",
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.26.4",
44
- "@axa-fr/oidc-client": "7.26.4"
43
+ "@axa-fr/oidc-client-service-worker": "7.26.5",
44
+ "@axa-fr/oidc-client": "7.26.5"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
@@ -172,7 +172,6 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
172
172
 
173
173
  queueMicrotask(() => {
174
174
  setConfigurationName(configurationName);
175
- setLoading(false);
176
175
  });
177
176
 
178
177
  return () => {