@axa-fr/react-oidc 7.22.32 → 7.23.1

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.
@@ -2,8 +2,8 @@ import { Fetch } from '@axa-fr/oidc-client';
2
2
  export interface ComponentWithOidcFetchProps {
3
3
  fetch?: Fetch;
4
4
  }
5
- export declare const withOidcFetch: (fetch?: Fetch, configurationName?: string, demonstrating_proof_of_possession?: boolean) => (WrappedComponent: any) => (props: ComponentWithOidcFetchProps) => import("react/jsx-runtime").JSX.Element;
6
- export declare const useOidcFetch: (fetch?: Fetch, configurationName?: string, demonstrating_proof_of_possession?: boolean) => {
5
+ export declare const withOidcFetch: (fetch?: Fetch, configurationName?: string, demonstratingProofOfPossession?: boolean) => (WrappedComponent: any) => (props: ComponentWithOidcFetchProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const useOidcFetch: (fetch?: Fetch, configurationName?: string, demonstratingProofOfPossession?: boolean) => {
7
7
  fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
8
8
  };
9
9
  //# sourceMappingURL=FetchToken.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/FetchToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,qBAAqB,CAAC;AAGxD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAgBD,eAAO,MAAM,aAAa,WAEf,KAAK,kEAEuB,OAAO,wCAGpC,2BAA2B,4CAOlC,CAAC;AAEJ,eAAO,MAAM,YAAY,WAChB,KAAK,kEAEuB,OAAO;mBAMhC,WAAW,GAAG,GAAG,SAAS,WAAW;CAYhD,CAAC"}
1
+ {"version":3,"file":"FetchToken.d.ts","sourceRoot":"","sources":["../src/FetchToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,qBAAqB,CAAC;AAGxD,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAgBD,eAAO,MAAM,aAAa,WAEf,KAAK,+DAEoB,OAAO,wCAGjC,2BAA2B,4CAOlC,CAAC;AAEJ,eAAO,MAAM,YAAY,WAChB,KAAK,+DAEoB,OAAO;mBAM7B,WAAW,GAAG,GAAG,SAAS,WAAW;CAYhD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { StringMap } from '@axa-fr/oidc-client';
2
2
  export declare const useOidc: (configurationName?: string) => {
3
- login: (callbackPath?: string | undefined, extras?: StringMap | undefined, silentLoginOnly?: boolean) => Promise<unknown>;
3
+ login: (callbackPath?: string | undefined, extras?: StringMap | undefined, silentLoginOnly?: boolean, scope?: string) => Promise<unknown>;
4
4
  logout: (callbackPath?: string | null | undefined, extras?: StringMap | undefined) => Promise<void>;
5
5
  renewTokens: (extras?: StringMap | undefined) => Promise<OidcAccessToken | OidcIdToken>;
6
6
  isAuthenticated: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO;2BA6BF,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS;4BAYf,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS;2BAKrB,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAe1C,CAAC;AAsBF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACrD,CAAC;AASF,eAAO,MAAM,kBAAkB,iDA6C9B,CAAC;AAeF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,6CAqC1B,CAAC"}
1
+ {"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAU,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO;2BA6BF,MAAM,GAAG,SAAS,WACxB,SAAS,GAAG,SAAS,qCAEtB,MAAM;4BAWC,MAAM,GAAG,IAAI,GAAG,SAAS,WAC/B,SAAS,GAAG,SAAS;2BAKrB,SAAS,GAAG,SAAS,KAC5B,OAAO,CAAC,eAAe,GAAG,WAAW,CAAC;;CAe1C,CAAC;AAsBF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACrD,CAAC;AASF,eAAO,MAAM,kBAAkB,iDA6C9B,CAAC;AAeF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,cAAc,6CAqC1B,CAAC"}
package/dist/index.js CHANGED
@@ -284,11 +284,11 @@ const x = "default", te = (t, s, e = !1) => async (...n) => await s().fetchWithT
284
284
  return () => {
285
285
  a = !1, d.removeEventSubscription(u);
286
286
  };
287
- }, [t]), { login: (a = void 0, d = void 0, u = !1) => s(t).loginAsync(
287
+ }, [t]), { login: (a = void 0, d = void 0, u = !1, _ = void 0) => s(t).loginAsync(
288
288
  a,
289
289
  d,
290
290
  !1,
291
- void 0,
291
+ _,
292
292
  u
293
293
  ), logout: (a = void 0, d = void 0) => s(t).logoutAsync(a, d), renewTokens: async (a = void 0) => {
294
294
  const d = await s(t).renewTokensAsync(a);
@@ -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 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)=>c(t).loginAsync(a,u,!1,void 0,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"})});
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.22.32",
3
+ "version": "7.23.1",
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.22.32",
44
- "@axa-fr/oidc-client": "7.22.32"
43
+ "@axa-fr/oidc-client-service-worker": "7.23.1",
44
+ "@axa-fr/oidc-client": "7.23.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.0 || ^18.0.0"
@@ -11,11 +11,11 @@ const fetchWithToken =
11
11
  (
12
12
  fetch: Fetch,
13
13
  getOidcWithConfigurationName: () => OidcClient | null,
14
- demonstrating_proof_of_possession: boolean = false,
14
+ demonstratingProofOfPossession: boolean = false,
15
15
  ) =>
16
16
  async (...params: Parameters<Fetch>) => {
17
17
  const oidc = getOidcWithConfigurationName();
18
- const newFetch = oidc.fetchWithTokens(fetch, demonstrating_proof_of_possession);
18
+ const newFetch = oidc.fetchWithTokens(fetch, demonstratingProofOfPossession);
19
19
  return await newFetch(...params);
20
20
  };
21
21
 
@@ -23,14 +23,14 @@ export const withOidcFetch =
23
23
  (
24
24
  fetch: Fetch = null,
25
25
  configurationName = defaultConfigurationName,
26
- demonstrating_proof_of_possession: boolean = false,
26
+ demonstratingProofOfPossession: boolean = false,
27
27
  ) =>
28
28
  WrappedComponent =>
29
29
  (props: ComponentWithOidcFetchProps) => {
30
30
  const { fetch: newFetch } = useOidcFetch(
31
31
  fetch || props.fetch,
32
32
  configurationName,
33
- demonstrating_proof_of_possession,
33
+ demonstratingProofOfPossession,
34
34
  );
35
35
  return <WrappedComponent {...props} fetch={newFetch} />;
36
36
  };
@@ -38,7 +38,7 @@ export const withOidcFetch =
38
38
  export const useOidcFetch = (
39
39
  fetch: Fetch = null,
40
40
  configurationName = defaultConfigurationName,
41
- demonstrating_proof_of_possession: boolean = false,
41
+ demonstratingProofOfPossession: boolean = false,
42
42
  ) => {
43
43
  const previousFetch = fetch || window.fetch;
44
44
  const getOidc = OidcClient.get;
@@ -49,7 +49,7 @@ export const useOidcFetch = (
49
49
  const newFetch = fetchWithToken(
50
50
  previousFetch,
51
51
  getOidcWithConfigurationName,
52
- demonstrating_proof_of_possession,
52
+ demonstratingProofOfPossession,
53
53
  );
54
54
  return newFetch(input, init);
55
55
  },
package/src/ReactOidc.tsx CHANGED
@@ -48,12 +48,13 @@ export const useOidc = (configurationName = defaultConfigurationName) => {
48
48
  callbackPath: string | undefined = undefined,
49
49
  extras: StringMap | undefined = undefined,
50
50
  silentLoginOnly = false,
51
+ scope: string = undefined,
51
52
  ) => {
52
53
  return getOidc(configurationName).loginAsync(
53
54
  callbackPath,
54
55
  extras,
55
56
  false,
56
- undefined,
57
+ scope,
57
58
  silentLoginOnly,
58
59
  );
59
60
  };