@axa-fr/react-oidc 7.19.6 → 7.20.0-alpha.1394
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/ReactOidc.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/ReactOidc.tsx +2 -3
package/dist/ReactOidc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"ReactOidc.d.ts","sourceRoot":"","sources":["../src/ReactOidc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,qBAAqB,CAAC;AAkBpE,eAAO,MAAM,OAAO;2BAuBY,MAAM,GAAG,SAAS,WAAqB,SAAS;4BAG9C,MAAM,GAAG,IAAI,GAAG,SAAS,WAAqB,SAAS;2BAGlD,SAAS,KAAW,QAAQ,eAAe,GAAG,WAAW,CAAC;;CAehG,CAAC;AAkBF,MAAM,MAAM,eAAe,GAAG;IAC1B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAC;IACzB,6CAA6C,CAAC,EAAE,GAAG,CAAC;CACvD,CAAA;AAMD,eAAO,MAAM,kBAAkB,iDAoC9B,CAAC;AAcF,MAAM,MAAM,WAAW,GAAG;IACtB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,GAAG,CAAC;CACxB,CAAA;AAED,eAAO,MAAM,cAAc,6CAgC1B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -858,7 +858,7 @@ const Be = "default", Ct = (o, s) => async (...r) => await s().fetchWithTokens(o
|
|
|
858
858
|
return Je;
|
|
859
859
|
};
|
|
860
860
|
function qt(o, s) {
|
|
861
|
-
return o.configuration.demonstrating_proof_of_possession ? (r, a) => o.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, r, a) : null;
|
|
861
|
+
return o.configuration.demonstrating_proof_of_possession ? (r, a, l = {}) => o.generateDemonstrationOfProofOfPossessionAsync(s.accessToken, r, a, l) : null;
|
|
862
862
|
}
|
|
863
863
|
const Zt = (o = ke) => {
|
|
864
864
|
const s = f.get, [r, a] = A(Vt(o));
|
package/dist/index.umd.cjs
CHANGED
|
@@ -24,4 +24,4 @@ Check the render method of \``+e+"`."}return""}}function Mt(e){{if(e!==void 0){v
|
|
|
24
24
|
|
|
25
25
|
Check your code at `+t+":"+r+"."}return""}}var Ge={};function Yt(e){{var t=ze();if(!t){var r=typeof e=="string"?e:e.displayName||e.name;r&&(t=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+r+">.")}return t}}function Je(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var r=Yt(t);if(Ge[r])return;Ge[r]=!0;var d="";e&&e._owner&&e._owner!==ge.current&&(d=" It was passed a child from "+P(e._owner.type)+"."),B(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,d),B(null)}}function Ke(e,t){{if(typeof e!="object")return;if(pe(e))for(var r=0;r<e.length;r++){var d=e[r];be(d)&&Je(d,t)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var y=M(e);if(typeof y=="function"&&y!==e.entries)for(var m=y.call(e),p;!(p=m.next()).done;)be(p.value)&&Je(p.value,t)}}}function Vt(e){{var t=e.type;if(t==null||typeof t=="string")return;var r;if(typeof t=="function")r=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===S))r=t.propTypes;else return;if(r){var d=P(t);jt(r,e.props,"prop",d,e)}else if(t.PropTypes!==void 0&&!ye){ye=!0;var y=P(t);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",y||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Bt(e){{for(var t=Object.keys(e.props),r=0;r<t.length;r++){var d=t[r];if(d!=="children"&&d!=="key"){B(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",d),B(null);break}}e.ref!==null&&(B(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),B(null))}}function He(e,t,r,d,y,m){{var p=ue(e);if(!p){var h="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(h+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var j=Mt(y);j?h+=j:h+=ze();var O;e===null?O="null":pe(e)?O="array":e!==void 0&&e.$$typeof===o?(O="<"+(P(e.type)||"Unknown")+" />",h=" Did you accidentally export a JSX literal instead of a component?"):O=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",O,h)}var T=Wt(e,t,r,y,m);if(T==null)return T;if(p){var A=t.children;if(A!==void 0)if(d)if(pe(A)){for(var z=0;z<A.length;z++)Ke(A[z],e);Object.freeze&&Object.freeze(A)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ke(A,e)}return e===a?Bt(T):Vt(T),T}}function zt(e,t,r){return He(e,t,r,!0)}function Gt(e,t,r){return He(e,t,r,!1)}var Jt=Gt,Kt=zt;J.Fragment=a,J.jsx=Jt,J.jsxs=Kt}()),J}process.env.NODE_ENV==="production"?ne.exports=Qe():ne.exports=Ze();var i=ne.exports;const Oe="default",qe=(s,o)=>async(...n)=>await o().fetchWithTokens(s)(...n),$e=(s=null,o=Oe)=>n=>a=>{const{fetch:u}=Ee(s||a.fetch,o);return i.jsx(n,{...a,fetch:u})},Ee=(s=null,o=Oe)=>{const n=s||window.fetch,a=c.OidcClient.get;return{fetch:g.useCallback((f,_)=>qe(n,()=>a(o))(f,_),[n,o])}},Te=()=>i.jsx("div",{className:"oidc-authenticating",children:i.jsxs("div",{className:"oidc-authenticating__container",children:[i.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),i.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),et=()=>i.jsx("div",{className:"oidc-authenticating",children:i.jsxs("div",{className:"oidc-authenticating__container",children:[i.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),i.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),tt=()=>Math.random().toString(36).substr(2,6),nt=(s,o)=>(n,a)=>{if(typeof s.CustomEvent=="function")return new s.CustomEvent(n,a);const u=a||{bubbles:!1,cancelable:!1,detail:void 0},f=o.createEvent("CustomEvent");return f.initCustomEvent(n,u.bubbles,u.cancelable,u.detail),f.prototype=s.Event.prototype,f},rt=(s,o,n)=>({replaceState:(a,u)=>{const f=n(),_=u||s.history.state;s.history.replaceState({key:f,state:_},null,a),s.dispatchEvent(o("popstate"))}}),st=()=>rt(window,nt(window,document),tt),we=()=>i.jsx("div",{className:"oidc-callback",children:i.jsxs("div",{className:"oidc-callback__container",children:[i.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),i.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),ot=({callBackError:s,callBackSuccess:o,configurationName:n,withCustomHistory:a})=>{const[u,f]=g.useState(!1);g.useEffect(()=>{let v=!0;return(async()=>{const k=c.OidcClient.get;try{const{callbackPath:S}=await k(n).loginCallbackAsync();(a?a():st()).replaceState(S||"/")}catch(S){v&&(console.warn(S),f(!0))}})(),()=>{v=!1}},[]);const _=s||Te,l=o||we;return u?i.jsx(_,{configurationName:n}):i.jsx(l,{configurationName:n})},at=()=>i.jsx("span",{className:"oidc-loading",children:"Loading"}),ct=()=>i.jsx("div",{className:"oidc-serviceworker",children:i.jsxs("div",{className:"oidc-serviceworker__container",children:[i.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),i.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."})]})}),it=()=>i.jsx("div",{className:"oidc-session-lost",children:i.jsxs("div",{className:"oidc-session-lost__container",children:[i.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),i.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),lt=({configurationName:s})=>(g.useEffect(()=>{(async()=>{const n=c.OidcClient.get;n(s).silentLoginCallbackAsync()})()},[]),i.jsx(i.Fragment,{})),ut=({configurationName:s})=>{const o=c.getParseQueryStringFromLocation(window.location.href),n=c.OidcClient.get,a=n(s);let u=null;for(const[f,_]of Object.entries(o))f==="state"||f==="scope"||(u===null&&(u={}),u[f]=_);return g.useEffect(()=>{a.tokens||a.loginAsync(null,u,!0,o.scope)},[]),i.jsx(i.Fragment,{})},ft=({callbackErrorComponent:s,callbackSuccessComponent:o,redirect_uri:n,silent_redirect_uri:a,silent_login_uri:u,children:f,configurationName:_,withCustomHistory:l=null,location:v})=>{const b=window?c.getPath(window.location.href):"",[k,S]=g.useState(b);g.useEffect(()=>{const x=()=>S(c.getPath(window.location.href));return x(),window.addEventListener("popstate",x,!1),()=>window.removeEventListener("popstate",x,!1)},[]);const C=c.getPath(n);if(a&&k===c.getPath(a))return i.jsx(lt,{configurationName:_});if(u&&k===c.getPath(u))return i.jsx(ut,{configurationName:_});switch(k){case C:return i.jsx(ot,{callBackError:s,callBackSuccess:o,configurationName:_,withCustomHistory:l});default:return i.jsx(i.Fragment,{children:f})}},dt=g.memo(ft),Se={name:"",data:null},vt=({loadingComponent:s,children:o,configurationName:n})=>{const[a,u]=g.useState(!0),f=c.OidcClient.get,_=f(n);g.useEffect(()=>{let v=!0;return _&&_.tryKeepExistingSessionAsync().then(()=>{v&&u(!1)}),()=>{v=!1}},[n]);const l=s;return i.jsx(i.Fragment,{children:a?i.jsx(l,{configurationName:n}):i.jsx(i.Fragment,{children:o})})},K=({isLoading:s,loadingComponent:o,children:n,configurationName:a})=>{const u=o;return s?i.jsx(u,{configurationName:a,children:n}):i.jsx(i.Fragment,{children:n})},ht=({children:s,configuration:o,configurationName:n="default",callbackSuccessComponent:a=we,authenticatingComponent:u=et,loadingComponent:f=at,serviceWorkerNotSupportedComponent:_=ct,authenticatingErrorComponent:l=Te,sessionLostComponent:v=it,onSessionLost:b=null,onLogoutFromAnotherTab:k=null,onLogoutFromSameTab:S=null,withCustomHistory:C=null,onEvent:x=null,getFetch:X=null,location:Q=null})=>{const M=(D="default")=>c.OidcClient.getOrCreate(X??c.getFetchDefault,Q??new c.OidcLocation)(o,D),[L,R]=g.useState(!0),[oe,Y]=g.useState(Se),[ae,ce]=g.useState("default");g.useEffect(()=>{const V=M(n).subscribeEvents((E,N)=>{x&&x(n,E,N)});return()=>{M(n).removeEventSubscription(V)}},[n,x]),g.useEffect(()=>{const V=M(n).subscribeEvents((E,N)=>{if(E===c.OidcClient.eventNames.refreshTokensAsync_error||E===c.OidcClient.eventNames.syncTokensAsync_error){if(b!=null){b();return}Y({name:E,data:N})}else if(E===c.OidcClient.eventNames.logout_from_another_tab){if(k!=null){k();return}Y({name:E,data:N})}else E===c.OidcClient.eventNames.logout_from_same_tab?S!=null&&S():E===c.OidcClient.eventNames.loginAsync_begin||E===c.OidcClient.eventNames.loginCallbackAsync_end||E===c.OidcClient.eventNames.loginAsync_error||E===c.OidcClient.eventNames.loginCallbackAsync_error?Y({name:E,data:N}):E===c.OidcClient.eventNames.service_worker_not_supported_by_browser&&o.service_worker_only===!0&&Y({name:E,data:N})});return ce(n),R(!1),()=>{M(n).removeEventSubscription(V),Y(Se)}},[o,n]);const ie=v,le=u,F=f,ue=_,fe=l,U=L||ae!==n,P=M(n);switch(oe.name){case c.OidcClient.eventNames.service_worker_not_supported_by_browser:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(ue,{configurationName:n})});case c.OidcClient.eventNames.loginAsync_begin:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(le,{configurationName:n})});case c.OidcClient.eventNames.loginAsync_error:case c.OidcClient.eventNames.loginCallbackAsync_error:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(fe,{configurationName:n})});case c.OidcClient.eventNames.refreshTokensAsync_error:case c.OidcClient.eventNames.syncTokensAsync_error:case c.OidcClient.eventNames.logout_from_another_tab:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(ie,{configurationName:n})});default:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(dt,{redirect_uri:P.configuration.redirect_uri,silent_redirect_uri:P.configuration.silent_redirect_uri,silent_login_uri:P.configuration.silent_login_uri,callbackSuccessComponent:a,callbackErrorComponent:l,authenticatingComponent:u,configurationName:n,withCustomHistory:C,location:Q??new c.OidcLocation,children:i.jsx(vt,{loadingComponent:F,configurationName:n,children:s})})})}},Re=({children:s,callbackPath:o=null,extras:n=null,configurationName:a="default"})=>{const u=c.OidcClient.get,f=u(a);return g.useEffect(()=>{f.tokens||f.loginAsync(o,n)},[a,o,n]),f.tokens?i.jsx(i.Fragment,{children:s}):null},pt=(s,o=null,n=null,a="default")=>u=>i.jsx(Re,{callbackPath:o,extras:n,configurationName:a,children:i.jsx(s,{...u})}),re="default",se=(s,o)=>{let n=!1;return s(o)&&(n=s(o).tokens!=null),n},_t=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(se(o,s));return g.useEffect(()=>{let l=!0;const v=o(s);a(se(o,s));const b=v.subscribeEvents((k,S)=>{(k===c.OidcClient.eventNames.logout_from_another_tab||k===c.OidcClient.eventNames.logout_from_same_tab||k===c.OidcClient.eventNames.token_aquired)&&l&&a(se(o,s))});return()=>{l=!1,v.removeEventSubscription(b)}},[s]),{login:(l=void 0,v=null,b=!1)=>o(s).loginAsync(l,v,!1,void 0,b),logout:(l=void 0,v=null)=>o(s).logoutAsync(l,v),renewTokens:async(l=null)=>{const v=await o(s).renewTokensAsync(l);return{accessToken:v.accessToken,accessTokenPayload:v.accessTokenPayload,idToken:v.idToken,idTokenPayload:v.idTokenPayload}},isAuthenticated:n}},je={accessToken:null,accessTokenPayload:null},gt=s=>{const o=c.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:n.configuration.demonstrating_proof_of_possession?(u,f)=>n.generateDemonstrationOfProofOfPossessionAsync(a.accessToken,u,f):null}}return je};function yt(s,o){return s.configuration.demonstrating_proof_of_possession?(n,a)=>s.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,n,a):null}const bt=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(gt(s));return g.useEffect(()=>{let u=!0;const f=o(s);if(f.tokens){const l=f.tokens;a({accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload})}const _=f.subscribeEvents((l,v)=>{if((l===c.OidcClient.eventNames.token_renewed||l===c.OidcClient.eventNames.token_aquired||l===c.OidcClient.eventNames.logout_from_another_tab||l===c.OidcClient.eventNames.logout_from_same_tab||l===c.OidcClient.eventNames.refreshTokensAsync_error||l===c.OidcClient.eventNames.syncTokensAsync_error)&&u){const b=f.tokens;a(b!=null?{accessToken:b.accessToken,accessTokenPayload:b.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:yt(f,b)}:je)}});return()=>{u=!1,f.removeEventSubscription(_)}},[s]),n},Pe={idToken:null,idTokenPayload:null},kt=s=>{const o=c.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{idToken:a.idToken,idTokenPayload:a.idTokenPayload}}return Pe},mt=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(kt(s));return g.useEffect(()=>{let u=!0;const f=o(s);if(f.tokens){const l=f.tokens;a({idToken:l.idToken,idTokenPayload:l.idTokenPayload})}const _=f.subscribeEvents((l,v)=>{if((l===c.OidcClient.eventNames.token_renewed||l===c.OidcClient.eventNames.token_aquired||l===c.OidcClient.eventNames.logout_from_another_tab||l===c.OidcClient.eventNames.logout_from_same_tab||l===c.OidcClient.eventNames.refreshTokensAsync_error||l===c.OidcClient.eventNames.syncTokensAsync_error)&&u){const b=f.tokens;a(b!=null?{idToken:b.idToken,idTokenPayload:b.idTokenPayload}:Pe)}});return()=>{u=!1,f.removeEventSubscription(_)}},[s]),n};var Ce=(s=>(s.Unauthenticated="Unauthenticated",s.Loading="Loading user",s.Loaded="User loaded",s.LoadingError="Error loading user",s))(Ce||{});const Ot=(s="default")=>{const[o,n]=g.useState({user:null,status:"Unauthenticated"}),[a,u]=g.useState("");g.useEffect(()=>{const _=c.OidcClient.get(s);let l=!0;if(_&&_.tokens){n({...o,status:"Loading user"});const b=a!=="";_.userInfoAsync(b).then(k=>{l&&n({user:k,status:"User loaded"})}).catch(()=>n({...o,status:"Error loading user"}))}else n({user:null,status:"Unauthenticated"});const v=_.subscribeEvents((b,k)=>{(b===c.OidcClient.eventNames.logout_from_another_tab||b===c.OidcClient.eventNames.logout_from_same_tab)&&l&&n({user:null,status:"Unauthenticated"})});return()=>{l=!1,_.removeEventSubscription(v)}},[a]);const f=()=>{u(a+" ")};return{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:f}};Object.defineProperty(w,"OidcClient",{enumerable:!0,get:()=>c.OidcClient}),Object.defineProperty(w,"TokenRenewMode",{enumerable:!0,get:()=>c.TokenRenewMode}),w.OidcProvider=ht,w.OidcSecure=Re,w.OidcUserStatus=Ce,w.useOidc=_t,w.useOidcAccessToken=bt,w.useOidcFetch=Ee,w.useOidcIdToken=mt,w.useOidcUser=Ot,w.withOidcFetch=$e,w.withOidcSecure=pt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
27
|
+
Check the top-level render call using <`+r+">.")}return t}}function Je(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var r=Yt(t);if(Ge[r])return;Ge[r]=!0;var d="";e&&e._owner&&e._owner!==ge.current&&(d=" It was passed a child from "+P(e._owner.type)+"."),B(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,d),B(null)}}function Ke(e,t){{if(typeof e!="object")return;if(pe(e))for(var r=0;r<e.length;r++){var d=e[r];be(d)&&Je(d,t)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var y=M(e);if(typeof y=="function"&&y!==e.entries)for(var m=y.call(e),p;!(p=m.next()).done;)be(p.value)&&Je(p.value,t)}}}function Vt(e){{var t=e.type;if(t==null||typeof t=="string")return;var r;if(typeof t=="function")r=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===S))r=t.propTypes;else return;if(r){var d=P(t);jt(r,e.props,"prop",d,e)}else if(t.PropTypes!==void 0&&!ye){ye=!0;var y=P(t);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",y||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Bt(e){{for(var t=Object.keys(e.props),r=0;r<t.length;r++){var d=t[r];if(d!=="children"&&d!=="key"){B(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",d),B(null);break}}e.ref!==null&&(B(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),B(null))}}function He(e,t,r,d,y,m){{var p=ue(e);if(!p){var h="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(h+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var j=Mt(y);j?h+=j:h+=ze();var O;e===null?O="null":pe(e)?O="array":e!==void 0&&e.$$typeof===o?(O="<"+(P(e.type)||"Unknown")+" />",h=" Did you accidentally export a JSX literal instead of a component?"):O=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",O,h)}var T=Wt(e,t,r,y,m);if(T==null)return T;if(p){var A=t.children;if(A!==void 0)if(d)if(pe(A)){for(var z=0;z<A.length;z++)Ke(A[z],e);Object.freeze&&Object.freeze(A)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ke(A,e)}return e===a?Bt(T):Vt(T),T}}function zt(e,t,r){return He(e,t,r,!0)}function Gt(e,t,r){return He(e,t,r,!1)}var Jt=Gt,Kt=zt;J.Fragment=a,J.jsx=Jt,J.jsxs=Kt}()),J}process.env.NODE_ENV==="production"?ne.exports=Qe():ne.exports=Ze();var i=ne.exports;const Oe="default",qe=(s,o)=>async(...n)=>await o().fetchWithTokens(s)(...n),$e=(s=null,o=Oe)=>n=>a=>{const{fetch:u}=Ee(s||a.fetch,o);return i.jsx(n,{...a,fetch:u})},Ee=(s=null,o=Oe)=>{const n=s||window.fetch,a=c.OidcClient.get;return{fetch:g.useCallback((f,_)=>qe(n,()=>a(o))(f,_),[n,o])}},Te=()=>i.jsx("div",{className:"oidc-authenticating",children:i.jsxs("div",{className:"oidc-authenticating__container",children:[i.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),i.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),et=()=>i.jsx("div",{className:"oidc-authenticating",children:i.jsxs("div",{className:"oidc-authenticating__container",children:[i.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),i.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),tt=()=>Math.random().toString(36).substr(2,6),nt=(s,o)=>(n,a)=>{if(typeof s.CustomEvent=="function")return new s.CustomEvent(n,a);const u=a||{bubbles:!1,cancelable:!1,detail:void 0},f=o.createEvent("CustomEvent");return f.initCustomEvent(n,u.bubbles,u.cancelable,u.detail),f.prototype=s.Event.prototype,f},rt=(s,o,n)=>({replaceState:(a,u)=>{const f=n(),_=u||s.history.state;s.history.replaceState({key:f,state:_},null,a),s.dispatchEvent(o("popstate"))}}),st=()=>rt(window,nt(window,document),tt),we=()=>i.jsx("div",{className:"oidc-callback",children:i.jsxs("div",{className:"oidc-callback__container",children:[i.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),i.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),ot=({callBackError:s,callBackSuccess:o,configurationName:n,withCustomHistory:a})=>{const[u,f]=g.useState(!1);g.useEffect(()=>{let v=!0;return(async()=>{const k=c.OidcClient.get;try{const{callbackPath:S}=await k(n).loginCallbackAsync();(a?a():st()).replaceState(S||"/")}catch(S){v&&(console.warn(S),f(!0))}})(),()=>{v=!1}},[]);const _=s||Te,l=o||we;return u?i.jsx(_,{configurationName:n}):i.jsx(l,{configurationName:n})},at=()=>i.jsx("span",{className:"oidc-loading",children:"Loading"}),ct=()=>i.jsx("div",{className:"oidc-serviceworker",children:i.jsxs("div",{className:"oidc-serviceworker__container",children:[i.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),i.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."})]})}),it=()=>i.jsx("div",{className:"oidc-session-lost",children:i.jsxs("div",{className:"oidc-session-lost__container",children:[i.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),i.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),lt=({configurationName:s})=>(g.useEffect(()=>{(async()=>{const n=c.OidcClient.get;n(s).silentLoginCallbackAsync()})()},[]),i.jsx(i.Fragment,{})),ut=({configurationName:s})=>{const o=c.getParseQueryStringFromLocation(window.location.href),n=c.OidcClient.get,a=n(s);let u=null;for(const[f,_]of Object.entries(o))f==="state"||f==="scope"||(u===null&&(u={}),u[f]=_);return g.useEffect(()=>{a.tokens||a.loginAsync(null,u,!0,o.scope)},[]),i.jsx(i.Fragment,{})},ft=({callbackErrorComponent:s,callbackSuccessComponent:o,redirect_uri:n,silent_redirect_uri:a,silent_login_uri:u,children:f,configurationName:_,withCustomHistory:l=null,location:v})=>{const b=window?c.getPath(window.location.href):"",[k,S]=g.useState(b);g.useEffect(()=>{const x=()=>S(c.getPath(window.location.href));return x(),window.addEventListener("popstate",x,!1),()=>window.removeEventListener("popstate",x,!1)},[]);const C=c.getPath(n);if(a&&k===c.getPath(a))return i.jsx(lt,{configurationName:_});if(u&&k===c.getPath(u))return i.jsx(ut,{configurationName:_});switch(k){case C:return i.jsx(ot,{callBackError:s,callBackSuccess:o,configurationName:_,withCustomHistory:l});default:return i.jsx(i.Fragment,{children:f})}},dt=g.memo(ft),Se={name:"",data:null},vt=({loadingComponent:s,children:o,configurationName:n})=>{const[a,u]=g.useState(!0),f=c.OidcClient.get,_=f(n);g.useEffect(()=>{let v=!0;return _&&_.tryKeepExistingSessionAsync().then(()=>{v&&u(!1)}),()=>{v=!1}},[n]);const l=s;return i.jsx(i.Fragment,{children:a?i.jsx(l,{configurationName:n}):i.jsx(i.Fragment,{children:o})})},K=({isLoading:s,loadingComponent:o,children:n,configurationName:a})=>{const u=o;return s?i.jsx(u,{configurationName:a,children:n}):i.jsx(i.Fragment,{children:n})},ht=({children:s,configuration:o,configurationName:n="default",callbackSuccessComponent:a=we,authenticatingComponent:u=et,loadingComponent:f=at,serviceWorkerNotSupportedComponent:_=ct,authenticatingErrorComponent:l=Te,sessionLostComponent:v=it,onSessionLost:b=null,onLogoutFromAnotherTab:k=null,onLogoutFromSameTab:S=null,withCustomHistory:C=null,onEvent:x=null,getFetch:X=null,location:Q=null})=>{const M=(D="default")=>c.OidcClient.getOrCreate(X??c.getFetchDefault,Q??new c.OidcLocation)(o,D),[L,R]=g.useState(!0),[oe,Y]=g.useState(Se),[ae,ce]=g.useState("default");g.useEffect(()=>{const V=M(n).subscribeEvents((E,N)=>{x&&x(n,E,N)});return()=>{M(n).removeEventSubscription(V)}},[n,x]),g.useEffect(()=>{const V=M(n).subscribeEvents((E,N)=>{if(E===c.OidcClient.eventNames.refreshTokensAsync_error||E===c.OidcClient.eventNames.syncTokensAsync_error){if(b!=null){b();return}Y({name:E,data:N})}else if(E===c.OidcClient.eventNames.logout_from_another_tab){if(k!=null){k();return}Y({name:E,data:N})}else E===c.OidcClient.eventNames.logout_from_same_tab?S!=null&&S():E===c.OidcClient.eventNames.loginAsync_begin||E===c.OidcClient.eventNames.loginCallbackAsync_end||E===c.OidcClient.eventNames.loginAsync_error||E===c.OidcClient.eventNames.loginCallbackAsync_error?Y({name:E,data:N}):E===c.OidcClient.eventNames.service_worker_not_supported_by_browser&&o.service_worker_only===!0&&Y({name:E,data:N})});return ce(n),R(!1),()=>{M(n).removeEventSubscription(V),Y(Se)}},[o,n]);const ie=v,le=u,F=f,ue=_,fe=l,U=L||ae!==n,P=M(n);switch(oe.name){case c.OidcClient.eventNames.service_worker_not_supported_by_browser:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(ue,{configurationName:n})});case c.OidcClient.eventNames.loginAsync_begin:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(le,{configurationName:n})});case c.OidcClient.eventNames.loginAsync_error:case c.OidcClient.eventNames.loginCallbackAsync_error:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(fe,{configurationName:n})});case c.OidcClient.eventNames.refreshTokensAsync_error:case c.OidcClient.eventNames.syncTokensAsync_error:case c.OidcClient.eventNames.logout_from_another_tab:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(ie,{configurationName:n})});default:return i.jsx(K,{loadingComponent:F,isLoading:U,configurationName:n,children:i.jsx(dt,{redirect_uri:P.configuration.redirect_uri,silent_redirect_uri:P.configuration.silent_redirect_uri,silent_login_uri:P.configuration.silent_login_uri,callbackSuccessComponent:a,callbackErrorComponent:l,authenticatingComponent:u,configurationName:n,withCustomHistory:C,location:Q??new c.OidcLocation,children:i.jsx(vt,{loadingComponent:F,configurationName:n,children:s})})})}},Re=({children:s,callbackPath:o=null,extras:n=null,configurationName:a="default"})=>{const u=c.OidcClient.get,f=u(a);return g.useEffect(()=>{f.tokens||f.loginAsync(o,n)},[a,o,n]),f.tokens?i.jsx(i.Fragment,{children:s}):null},pt=(s,o=null,n=null,a="default")=>u=>i.jsx(Re,{callbackPath:o,extras:n,configurationName:a,children:i.jsx(s,{...u})}),re="default",se=(s,o)=>{let n=!1;return s(o)&&(n=s(o).tokens!=null),n},_t=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(se(o,s));return g.useEffect(()=>{let l=!0;const v=o(s);a(se(o,s));const b=v.subscribeEvents((k,S)=>{(k===c.OidcClient.eventNames.logout_from_another_tab||k===c.OidcClient.eventNames.logout_from_same_tab||k===c.OidcClient.eventNames.token_aquired)&&l&&a(se(o,s))});return()=>{l=!1,v.removeEventSubscription(b)}},[s]),{login:(l=void 0,v=null,b=!1)=>o(s).loginAsync(l,v,!1,void 0,b),logout:(l=void 0,v=null)=>o(s).logoutAsync(l,v),renewTokens:async(l=null)=>{const v=await o(s).renewTokensAsync(l);return{accessToken:v.accessToken,accessTokenPayload:v.accessTokenPayload,idToken:v.idToken,idTokenPayload:v.idTokenPayload}},isAuthenticated:n}},je={accessToken:null,accessTokenPayload:null},gt=s=>{const o=c.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:n.configuration.demonstrating_proof_of_possession?(u,f)=>n.generateDemonstrationOfProofOfPossessionAsync(a.accessToken,u,f):null}}return je};function yt(s,o){return s.configuration.demonstrating_proof_of_possession?(n,a,u={})=>s.generateDemonstrationOfProofOfPossessionAsync(o.accessToken,n,a,u):null}const bt=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(gt(s));return g.useEffect(()=>{let u=!0;const f=o(s);if(f.tokens){const l=f.tokens;a({accessToken:l.accessToken,accessTokenPayload:l.accessTokenPayload})}const _=f.subscribeEvents((l,v)=>{if((l===c.OidcClient.eventNames.token_renewed||l===c.OidcClient.eventNames.token_aquired||l===c.OidcClient.eventNames.logout_from_another_tab||l===c.OidcClient.eventNames.logout_from_same_tab||l===c.OidcClient.eventNames.refreshTokensAsync_error||l===c.OidcClient.eventNames.syncTokensAsync_error)&&u){const b=f.tokens;a(b!=null?{accessToken:b.accessToken,accessTokenPayload:b.accessTokenPayload,generateDemonstrationOfProofOfPossessionAsync:yt(f,b)}:je)}});return()=>{u=!1,f.removeEventSubscription(_)}},[s]),n},Pe={idToken:null,idTokenPayload:null},kt=s=>{const o=c.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{idToken:a.idToken,idTokenPayload:a.idTokenPayload}}return Pe},mt=(s=re)=>{const o=c.OidcClient.get,[n,a]=g.useState(kt(s));return g.useEffect(()=>{let u=!0;const f=o(s);if(f.tokens){const l=f.tokens;a({idToken:l.idToken,idTokenPayload:l.idTokenPayload})}const _=f.subscribeEvents((l,v)=>{if((l===c.OidcClient.eventNames.token_renewed||l===c.OidcClient.eventNames.token_aquired||l===c.OidcClient.eventNames.logout_from_another_tab||l===c.OidcClient.eventNames.logout_from_same_tab||l===c.OidcClient.eventNames.refreshTokensAsync_error||l===c.OidcClient.eventNames.syncTokensAsync_error)&&u){const b=f.tokens;a(b!=null?{idToken:b.idToken,idTokenPayload:b.idTokenPayload}:Pe)}});return()=>{u=!1,f.removeEventSubscription(_)}},[s]),n};var Ce=(s=>(s.Unauthenticated="Unauthenticated",s.Loading="Loading user",s.Loaded="User loaded",s.LoadingError="Error loading user",s))(Ce||{});const Ot=(s="default")=>{const[o,n]=g.useState({user:null,status:"Unauthenticated"}),[a,u]=g.useState("");g.useEffect(()=>{const _=c.OidcClient.get(s);let l=!0;if(_&&_.tokens){n({...o,status:"Loading user"});const b=a!=="";_.userInfoAsync(b).then(k=>{l&&n({user:k,status:"User loaded"})}).catch(()=>n({...o,status:"Error loading user"}))}else n({user:null,status:"Unauthenticated"});const v=_.subscribeEvents((b,k)=>{(b===c.OidcClient.eventNames.logout_from_another_tab||b===c.OidcClient.eventNames.logout_from_same_tab)&&l&&n({user:null,status:"Unauthenticated"})});return()=>{l=!1,_.removeEventSubscription(v)}},[a]);const f=()=>{u(a+" ")};return{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:f}};Object.defineProperty(w,"OidcClient",{enumerable:!0,get:()=>c.OidcClient}),Object.defineProperty(w,"TokenRenewMode",{enumerable:!0,get:()=>c.TokenRenewMode}),w.OidcProvider=ht,w.OidcSecure=Re,w.OidcUserStatus=Ce,w.useOidc=_t,w.useOidcAccessToken=bt,w.useOidcFetch=Ee,w.useOidcIdToken=mt,w.useOidcUser=Ot,w.withOidcFetch=$e,w.withOidcSecure=pt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/react-oidc",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.20.0-alpha.1394",
|
|
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.
|
|
44
|
-
"@axa-fr/oidc-client": "7.
|
|
43
|
+
"@axa-fr/oidc-client-service-worker": "7.20.0-alpha.1394",
|
|
44
|
+
"@axa-fr/oidc-client": "7.20.0-alpha.1394"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^17.0.0 || ^18.0.0"
|
package/src/ReactOidc.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { StringMap, OidcClient } from '@axa-fr/oidc-client';
|
|
1
|
+
import { StringMap, OidcClient, Tokens } from '@axa-fr/oidc-client';
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
import {Tokens} from "@axa-fr/oidc-client/dist/parseTokens";
|
|
4
3
|
|
|
5
4
|
const defaultConfigurationName = 'default';
|
|
6
5
|
|
|
@@ -86,7 +85,7 @@ export type OidcAccessToken = {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
function getGenerateDemonstrationOfProofOfPossessionAsync(oidc: OidcClient, tokens: Tokens) {
|
|
89
|
-
return oidc.configuration.demonstrating_proof_of_possession ? (url: string, method: string) => oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method) : null;
|
|
88
|
+
return oidc.configuration.demonstrating_proof_of_possession ? (url: string, method: string, extras:StringMap={}) => oidc.generateDemonstrationOfProofOfPossessionAsync(tokens.accessToken, url, method, extras) : null;
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
export const useOidcAccessToken = (configurationName = defaultConfigurationName) => {
|