@axa-fr/react-oidc 7.3.1 → 7.4.0-alpha.1025
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/OidcProvider.d.ts +0 -2
- package/dist/index.js +549 -555
- package/dist/index.umd.cjs +10 -10
- package/package.json +3 -3
- package/src/OidcProvider.tsx +13 -38
- package/src/OidcSecure.tsx +6 -4
- package/src/ReactOidc.tsx +6 -3
- package/src/User.ts +14 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(j,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react"),require("@axa-fr/oidc-client")):typeof define=="function"&&define.amd?define(["exports","react","@axa-fr/oidc-client"],k):(j=typeof globalThis<"u"?globalThis:j||self,k(j["react-oidc"]={},j.React,j.oidcClient))})(this,function(j,k,i){"use strict";var Q={exports:{}},M={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ve;function Xe(){if(ve)return M;ve=1;var s=k,a=Symbol.for("react.element"),r=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,f=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function h(c,v,_){var g,w={},R=null,I=null;_!==void 0&&(R=""+_),v.key!==void 0&&(R=""+v.key),v.ref!==void 0&&(I=v.ref);for(g in v)o.call(v,g)&&!l.hasOwnProperty(g)&&(w[g]=v[g]);if(c&&c.defaultProps)for(g in v=c.defaultProps,v)w[g]===void 0&&(w[g]=v[g]);return{$$typeof:a,type:c,key:R,ref:I,props:w,_owner:f.current}}return M.Fragment=r,M.jsx=h,M.jsxs=h,M}var Y={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+p[
|
|
17
|
+
*/var he;function Qe(){return he||(he=1,process.env.NODE_ENV!=="production"&&function(){var s=k,a=Symbol.for("react.element"),r=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),f=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),h=Symbol.for("react.provider"),c=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),_=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),F=Symbol.iterator,Te="@@iterator";function $(e){if(e===null||typeof e!="object")return null;var t=F&&e[F]||e[Te];return typeof t=="function"?t:null}var N=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function O(e){{for(var t=arguments.length,n=new Array(t>1?t-1:0),u=1;u<t;u++)n[u-1]=arguments[u];we("error",e,n)}}function we(e,t,n){{var u=N.ReactDebugCurrentFrame,b=u.getStackAddendum();b!==""&&(t+="%s",n=n.concat([b]));var m=n.map(function(y){return String(y)});m.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,m)}}var ee=!1,te=!1,ne=!1,re=!1,se=!1,D;D=Symbol.for("react.module.reference");function Se(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===l||se||e===f||e===_||e===g||re||e===I||ee||te||ne||typeof e=="object"&&e!==null&&(e.$$typeof===R||e.$$typeof===w||e.$$typeof===h||e.$$typeof===c||e.$$typeof===v||e.$$typeof===D||e.getModuleId!==void 0))}function V(e,t,n){var u=e.displayName;if(u)return u;var b=t.displayName||t.name||"";return b!==""?n+"("+b+")":n}function U(e){return e.displayName||"Context"}function E(e){if(e==null)return null;if(typeof e.tag=="number"&&O("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case o:return"Fragment";case r:return"Portal";case l:return"Profiler";case f:return"StrictMode";case _:return"Suspense";case g:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case c:var t=e;return U(t)+".Consumer";case h:var n=e;return U(n._context)+".Provider";case v:return V(e,e.render,"ForwardRef");case w:var u=e.displayName||null;return u!==null?u:E(e.type)||"Memo";case R:{var b=e,m=b._payload,y=b._init;try{return E(y(m))}catch{return null}}}return null}var x=Object.assign,B=0,Re,je,Pe,xe,Ce,Ae,Fe;function Ne(){}Ne.__reactDisabledLog=!0;function kt(){{if(B===0){Re=console.log,je=console.info,Pe=console.warn,xe=console.error,Ce=console.group,Ae=console.groupCollapsed,Fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}B++}}function Et(){{if(B--,B===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:Re}),info:x({},e,{value:je}),warn:x({},e,{value:Pe}),error:x({},e,{value:xe}),group:x({},e,{value:Ce}),groupCollapsed:x({},e,{value:Ae}),groupEnd:x({},e,{value:Fe})})}B<0&&O("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ae=N.ReactCurrentDispatcher,oe;function z(e,t,n){{if(oe===void 0)try{throw Error()}catch(b){var u=b.stack.trim().match(/\n( *(at )?)/);oe=u&&u[1]||""}return`
|
|
18
|
+
`+oe+e}}var ie=!1,G;{var mt=typeof WeakMap=="function"?WeakMap:Map;G=new mt}function Ie(e,t){if(!e||ie)return"";{var n=G.get(e);if(n!==void 0)return n}var u;ie=!0;var b=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var m;m=ae.current,ae.current=null,kt();try{if(t){var y=function(){throw Error()};if(Object.defineProperty(y.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(y,[])}catch(A){u=A}Reflect.construct(e,[],y)}else{try{y.call()}catch(A){u=A}e.call(y.prototype)}}else{try{throw Error()}catch(A){u=A}e()}}catch(A){if(A&&u&&typeof A.stack=="string"){for(var p=A.stack.split(`
|
|
19
|
+
`),P=u.stack.split(`
|
|
20
|
+
`),T=p.length-1,S=P.length-1;T>=1&&S>=0&&p[T]!==P[S];)S--;for(;T>=1&&S>=0;T--,S--)if(p[T]!==P[S]){if(T!==1||S!==1)do if(T--,S--,S<0||p[T]!==P[S]){var C=`
|
|
21
|
+
`+p[T].replace(" at new "," at ");return e.displayName&&C.includes("<anonymous>")&&(C=C.replace("<anonymous>",e.displayName)),typeof e=="function"&&G.set(e,C),C}while(T>=1&&S>=0);break}}}finally{ie=!1,ae.current=m,Et(),Error.prepareStackTrace=b}var W=e?e.displayName||e.name:"",Je=W?z(W):"";return typeof e=="function"&&G.set(e,Je),Je}function Ot(e,t,n){return Ie(e,!1)}function Tt(e){var t=e.prototype;return!!(t&&t.isReactComponent)}function H(e,t,n){if(e==null)return"";if(typeof e=="function")return Ie(e,Tt(e));if(typeof e=="string")return z(e);switch(e){case _:return z("Suspense");case g:return z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return Ot(e.render);case w:return H(e.type,t,n);case R:{var u=e,b=u._payload,m=u._init;try{return H(m(b),t,n)}catch{}}}return""}var J=Object.prototype.hasOwnProperty,De={},Ue=N.ReactDebugCurrentFrame;function X(e){if(e){var t=e._owner,n=H(e.type,e._source,t?t.type:null);Ue.setExtraStackFrame(n)}else Ue.setExtraStackFrame(null)}function wt(e,t,n,u,b){{var m=Function.call.bind(J);for(var y in e)if(m(e,y)){var p=void 0;try{if(typeof e[y]!="function"){var P=Error((u||"React class")+": "+n+" type `"+y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw P.name="Invariant Violation",P}p=e[y](t,y,u,n,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(T){p=T}p&&!(p instanceof Error)&&(X(b),O("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",u||"React class",n,y,typeof p),X(null)),p instanceof Error&&!(p.message in De)&&(De[p.message]=!0,X(b),O("Failed %s type: %s",n,p.message),X(null))}}}var St=Array.isArray;function ce(e){return St(e)}function Rt(e){{var t=typeof Symbol=="function"&&Symbol.toStringTag,n=t&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n}}function jt(e){try{return Le(e),!1}catch{return!0}}function Le(e){return""+e}function We(e){if(jt(e))return O("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Rt(e)),Le(e)}var K=N.ReactCurrentOwner,Pt={key:!0,ref:!0,__self:!0,__source:!0},Me,Ye,le;le={};function xt(e){if(J.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return e.ref!==void 0}function Ct(e){if(J.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function At(e,t){if(typeof e.ref=="string"&&K.current&&t&&K.current.stateNode!==t){var n=E(K.current.type);le[n]||(O('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',E(K.current.type),e.ref),le[n]=!0)}}function Ft(e,t){{var n=function(){Me||(Me=!0,O("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}}function Nt(e,t){{var n=function(){Ye||(Ye=!0,O("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};n.isReactWarning=!0,Object.defineProperty(e,"ref",{get:n,configurable:!0})}}var It=function(e,t,n,u,b,m,y){var p={$$typeof:a,type:e,key:t,ref:n,props:y,_owner:m};return p._store={},Object.defineProperty(p._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(p,"_self",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.defineProperty(p,"_source",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.freeze&&(Object.freeze(p.props),Object.freeze(p)),p};function Dt(e,t,n,u,b){{var m,y={},p=null,P=null;n!==void 0&&(We(n),p=""+n),Ct(t)&&(We(t.key),p=""+t.key),xt(t)&&(P=t.ref,At(t,b));for(m in t)J.call(t,m)&&!Pt.hasOwnProperty(m)&&(y[m]=t[m]);if(e&&e.defaultProps){var T=e.defaultProps;for(m in T)y[m]===void 0&&(y[m]=T[m])}if(p||P){var S=typeof e=="function"?e.displayName||e.name||"Unknown":e;p&&Ft(y,S),P&&Nt(y,S)}return It(e,p,P,b,u,K.current,y)}}var ue=N.ReactCurrentOwner,Ve=N.ReactDebugCurrentFrame;function L(e){if(e){var t=e._owner,n=H(e.type,e._source,t?t.type:null);Ve.setExtraStackFrame(n)}else Ve.setExtraStackFrame(null)}var de;de=!1;function fe(e){return typeof e=="object"&&e!==null&&e.$$typeof===a}function Be(){{if(ue.current){var e=E(ue.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function Ut(e){{if(e!==void 0){var t=e.fileName.replace(/^.*[\\\/]/,""),n=e.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+t+":"+
|
|
25
|
+
Check your code at `+t+":"+n+"."}return""}}var Ke={};function Lt(e){{var t=Be();if(!t){var n=typeof e=="string"?e:e.displayName||e.name;n&&(t=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+r+">.")}return t}}function He(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var r=Mt(t);if(Ge[r])return;Ge[r]=!0;var f="";e&&e._owner&&e._owner!==_e.current&&(f=" It was passed a child from "+A(e._owner.type)+"."),B(e),j('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,f),B(null)}}function Je(e,t){{if(typeof e!="object")return;if(he(e))for(var r=0;r<e.length;r++){var f=e[r];ye(f)&&He(f,t)}else if(ye(e))e._store&&(e._store.validated=!0);else if(e){var b=oe(e);if(typeof b=="function"&&b!==e.entries)for(var m=b.call(e),_;!(_=m.next()).done;)ye(_.value)&&He(_.value,t)}}}function Yt(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===O))r=t.propTypes;else return;if(r){var f=A(t);St(r,e.props,"prop",f,e)}else if(t.PropTypes!==void 0&&!ge){ge=!0;var b=A(t);j("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&j("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Vt(e){{for(var t=Object.keys(e.props),r=0;r<t.length;r++){var f=t[r];if(f!=="children"&&f!=="key"){B(e),j("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",f),B(null);break}}e.ref!==null&&(B(e),j("Invalid attribute `ref` supplied to `React.Fragment`."),B(null))}}function Ke(e,t,r,f,b,m){{var _=ue(e);if(!_){var p="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(p+=" 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 C=Wt(b);C?p+=C:p+=ze();var E;e===null?E="null":he(e)?E="array":e!==void 0&&e.$$typeof===o?(E="<"+(A(e.type)||"Unknown")+" />",p=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,j("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,p)}var w=Ut(e,t,r,b,m);if(w==null)return w;if(_){var x=t.children;if(x!==void 0)if(f)if(he(x)){for(var z=0;z<x.length;z++)Je(x[z],e);Object.freeze&&Object.freeze(x)}else j("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 Je(x,e)}return e===a?Vt(w):Yt(w),w}}function Bt(e,t,r){return Ke(e,t,r,!0)}function zt(e,t,r){return Ke(e,t,r,!1)}var Gt=zt,Ht=Bt;H.Fragment=a,H.jsx=Gt,H.jsxs=Ht}()),H}process.env.NODE_ENV==="production"?ne.exports=Qe():ne.exports=Ze();var c=ne.exports;const me="default",qe=(s,o)=>async(...n)=>{var S;const[a,d,...u]=n,h=d?{...d}:{method:"GET"};let i=new Headers;h.headers&&(i=h.headers instanceof Headers?h.headers:new Headers(h.headers));const g=await o().getValidTokenAsync(),k=(S=g==null?void 0:g.tokens)==null?void 0:S.accessToken;i.has("Accept")||i.set("Accept","application/json"),k&&(i.set("Authorization",`Bearer ${k}`),h.credentials||(h.credentials="same-origin"));const O={...h,headers:i};return await s(a,O,...u)},$e=(s=null,o=me)=>n=>a=>{const{fetch:d}=Oe(s||a.fetch,o);return c.jsx(n,{...a,fetch:d})},Oe=(s=null,o=me)=>{const n=s||window.fetch,a=l.OidcClient.get;return{fetch:y.useCallback((u,h)=>qe(n,()=>a(o))(u,h),[n,o])}},Ee=()=>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."})]})}),et=()=>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."})]})}),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 d=a||{bubbles:!1,cancelable:!1,detail:void 0},u=o.createEvent("CustomEvent");return u.initCustomEvent(n,d.bubbles,d.cancelable,d.detail),u.prototype=s.Event.prototype,u},rt=(s,o,n)=>({replaceState:(a,d)=>{const u=n(),h=d||s.history.state;s.history.replaceState({key:u,state:h},null,a),s.dispatchEvent(o("popstate"))}}),st=()=>rt(window,nt(window,document),tt),Te=()=>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."})]})}),ot=({callBackError:s,callBackSuccess:o,configurationName:n,withCustomHistory:a})=>{const[d,u]=y.useState(!1);y.useEffect(()=>{let v=!0;return(async()=>{const k=l.OidcClient.get;try{const{callbackPath:O}=await k(n).loginCallbackAsync();(a?a():st()).replaceState(O||"/")}catch(O){v&&(console.warn(O),u(!0))}})(),()=>{v=!1}},[]);const h=s||Ee,i=o||Te;return d?c.jsx(h,{configurationName:n}):c.jsx(i,{configurationName:n})},at=()=>c.jsx("span",{className:"oidc-loading",children:"Loading"}),ct=()=>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."})]})}),it=()=>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."})]})}),lt=({configurationName:s})=>(y.useEffect(()=>{(async()=>{const n=l.OidcClient.get;n(s).silentLoginCallbackAsync()})()},[]),c.jsx(c.Fragment,{})),ut=({configurationName:s})=>{const o=l.getParseQueryStringFromLocation(window.location.href),n=l.OidcClient.get,a=n(s);let d=null;for(const[u,h]of Object.entries(o))u==="state"||u==="scope"||(d===null&&(d={}),d[u]=h);return y.useEffect(()=>{a.tokens||a.loginAsync(null,d,!0,o.scope)},[]),c.jsx(c.Fragment,{})},dt=({callbackErrorComponent:s,callbackSuccessComponent:o,redirect_uri:n,silent_redirect_uri:a,silent_login_uri:d,children:u,configurationName:h,withCustomHistory:i=null})=>{const v=window?l.getPath(window.location.href):"",[g,k]=y.useState(v);y.useEffect(()=>{const S=()=>k(l.getPath(window.location.href));return S(),window.addEventListener("popstate",S,!1),()=>window.removeEventListener("popstate",S,!1)},[]);const O=l.getPath(n);if(a&&g===l.getPath(a))return c.jsx(lt,{configurationName:h});if(d&&g===l.getPath(d))return c.jsx(ut,{configurationName:h});switch(g){case O:return c.jsx(ot,{callBackError:s,callBackSuccess:o,configurationName:h,withCustomHistory:i});default:return c.jsx(c.Fragment,{children:u})}},ft=y.memo(dt),we={name:"",data:null},vt=({loadingComponent:s,children:o,configurationName:n})=>{const[a,d]=y.useState(!0),u=l.OidcClient.get,h=u(n);y.useEffect(()=>{let v=!0;return h&&h.tryKeepExistingSessionAsync().then(()=>{v&&d(!1)}),()=>{v=!1}},[n]);const i=s;return c.jsx(c.Fragment,{children:a?c.jsx(i,{configurationName:n}):c.jsx(c.Fragment,{children:o})})},J=({isLoading:s,loadingComponent:o,children:n,configurationName:a})=>{const d=o;return s?c.jsx(d,{configurationName:a,children:n}):c.jsx(c.Fragment,{children:n})},ht=({children:s,configuration:o,configurationName:n="default",callbackSuccessComponent:a=Te,authenticatingComponent:d=et,loadingComponent:u=at,serviceWorkerNotSupportedComponent:h=ct,authenticatingErrorComponent:i=Ee,sessionLostComponent:v=it,onSessionLost:g=null,onLogoutFromAnotherTab:k=null,onLogoutFromSameTab:O=null,withCustomHistory:S=null,onEvent:D=null,getFetch:X=null})=>{const W=(P="default")=>l.OidcClient.getOrCreate(X??l.getFetchDefault)(o,P),[oe,L]=y.useState(!0),[j,M]=y.useState(we),[ae,ce]=y.useState("default");y.useEffect(()=>{const F=W(n).subscribeEvents((T,N)=>{D&&D(n,T,N)});return()=>{W(n).removeEventSubscription(F)}},[n,D]),y.useEffect(()=>{const F=W(n).subscribeEvents((T,N)=>{if(T===l.OidcClient.eventNames.refreshTokensAsync_error||T===l.OidcClient.eventNames.syncTokensAsync_error){if(g!=null){g();return}M({name:T,data:N})}else if(T===l.OidcClient.eventNames.logout_from_another_tab){if(k!=null){k();return}M({name:T,data:N})}else T===l.OidcClient.eventNames.logout_from_same_tab?O!=null&&O():T===l.OidcClient.eventNames.loginAsync_begin||T===l.OidcClient.eventNames.loginCallbackAsync_end||T===l.OidcClient.eventNames.loginAsync_error||T===l.OidcClient.eventNames.loginCallbackAsync_error?M({name:T,data:N}):T===l.OidcClient.eventNames.service_worker_not_supported_by_browser&&o.service_worker_only===!0&&M({name:T,data:N})});return ce(n),L(!1),()=>{W(n).removeEventSubscription(F),M(we)}},[o,n]);const ie=v,le=d,U=u,Q=h,ue=i,Y=oe||ae!==n,V=W(n);switch(j.name){case l.OidcClient.eventNames.service_worker_not_supported_by_browser:return c.jsx(J,{loadingComponent:U,isLoading:Y,configurationName:n,children:c.jsx(Q,{configurationName:n})});case l.OidcClient.eventNames.loginAsync_begin:return c.jsx(J,{loadingComponent:U,isLoading:Y,configurationName:n,children:c.jsx(le,{configurationName:n})});case l.OidcClient.eventNames.loginAsync_error:case l.OidcClient.eventNames.loginCallbackAsync_error:return c.jsx(J,{loadingComponent:U,isLoading:Y,configurationName:n,children:c.jsx(ue,{configurationName:n})});case l.OidcClient.eventNames.refreshTokensAsync_error:case l.OidcClient.eventNames.syncTokensAsync_error:case l.OidcClient.eventNames.logout_from_another_tab:return c.jsx(J,{loadingComponent:U,isLoading:Y,configurationName:n,children:c.jsx(ie,{configurationName:n})});default:return c.jsx(J,{loadingComponent:U,isLoading:Y,configurationName:n,children:c.jsx(ft,{redirect_uri:V.configuration.redirect_uri,silent_redirect_uri:V.configuration.silent_redirect_uri,silent_login_uri:V.configuration.silent_login_uri,callbackSuccessComponent:a,callbackErrorComponent:i,authenticatingComponent:d,configurationName:n,withCustomHistory:S,children:c.jsx(vt,{loadingComponent:U,configurationName:n,children:s})})})}},Re=({children:s,callbackPath:o=null,extras:n=null,configurationName:a="default"})=>{const d=l.OidcClient.get,u=d(a);return y.useEffect(()=>{u.tokens||u.loginAsync(o,n)},[a,o,n]),u.tokens?c.jsx(c.Fragment,{children:s}):null},pt=(s,o=null,n=null,a="default")=>d=>c.jsx(Re,{callbackPath:o,extras:n,configurationName:a,children:c.jsx(s,{...d})}),re="default",se=(s,o)=>{let n=!1;return s(o)&&(n=s(o).tokens!=null),n},_t=(s=re)=>{const o=l.OidcClient.get,[n,a]=y.useState(se(o,s));return y.useEffect(()=>{let i=!0;const v=o(s);a(se(o,s));const g=v.subscribeEvents((k,O)=>{(k===l.OidcClient.eventNames.logout_from_another_tab||k===l.OidcClient.eventNames.logout_from_same_tab||k===l.OidcClient.eventNames.token_aquired)&&i&&a(se(o,s))});return()=>{i=!1,v.removeEventSubscription(g)}},[s]),{login:(i=void 0,v=null,g=!1)=>o(s).loginAsync(i,v,!1,void 0,g),logout:(i=void 0,v=null)=>o(s).logoutAsync(i,v),renewTokens:async(i=null)=>{const v=await o(s).renewTokensAsync(i);return{accessToken:v.accessToken,accessTokenPayload:v.accessTokenPayload,idToken:v.idToken,idTokenPayload:v.idTokenPayload}},isAuthenticated:n}},Se={accessToken:null,accessTokenPayload:null},gt=s=>{const o=l.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{accessToken:a.accessToken,accessTokenPayload:a.accessTokenPayload}}return Se},yt=(s=re)=>{const o=l.OidcClient.get,[n,a]=y.useState(gt(s));return y.useEffect(()=>{let d=!0;const u=o(s);if(u.tokens){const i=u.tokens;a({accessToken:i.accessToken,accessTokenPayload:i.accessTokenPayload})}const h=u.subscribeEvents((i,v)=>{if((i===l.OidcClient.eventNames.token_renewed||i===l.OidcClient.eventNames.token_aquired||i===l.OidcClient.eventNames.logout_from_another_tab||i===l.OidcClient.eventNames.logout_from_same_tab||i===l.OidcClient.eventNames.refreshTokensAsync_error||i===l.OidcClient.eventNames.syncTokensAsync_error)&&d){const g=u.tokens;a(g!=null?{accessToken:g.accessToken,accessTokenPayload:g.accessTokenPayload}:Se)}});return()=>{d=!1,u.removeEventSubscription(h)}},[s]),n},je={idToken:null,idTokenPayload:null},bt=s=>{const o=l.OidcClient.get,n=o(s);if(n.tokens){const a=n.tokens;return{idToken:a.idToken,idTokenPayload:a.idTokenPayload}}return je},kt=(s=re)=>{const o=l.OidcClient.get,[n,a]=y.useState(bt(s));return y.useEffect(()=>{let d=!0;const u=o(s);if(u.tokens){const i=u.tokens;a({idToken:i.idToken,idTokenPayload:i.idTokenPayload})}const h=u.subscribeEvents((i,v)=>{if((i===l.OidcClient.eventNames.token_renewed||i===l.OidcClient.eventNames.token_aquired||i===l.OidcClient.eventNames.logout_from_another_tab||i===l.OidcClient.eventNames.logout_from_same_tab||i===l.OidcClient.eventNames.refreshTokensAsync_error||i===l.OidcClient.eventNames.syncTokensAsync_error)&&d){const g=u.tokens;a(g!=null?{idToken:g.idToken,idTokenPayload:g.idTokenPayload}:je)}});return()=>{d=!1,u.removeEventSubscription(h)}},[s]),n};var Ce=(s=>(s.Unauthenticated="Unauthenticated",s.Loading="Loading user",s.Loaded="User loaded",s.LoadingError="Error loading user",s))(Ce||{});const mt=(s="default")=>{const[o,n]=y.useState({user:null,status:"Unauthenticated"}),[a,d]=y.useState(""),u=l.OidcClient.get(s);y.useEffect(()=>{let i=!0;if(u&&u.tokens){n({...o,status:"Loading user"});const v=a!=="";u.userInfoAsync(v).then(g=>{i&&n({user:g,status:"User loaded"})}).catch(()=>n({...o,status:"Error loading user"}))}else n({user:null,status:"Unauthenticated"});return()=>{i=!1}},[a]);const h=()=>{d(a+" ")};return{oidcUser:o.user,oidcUserLoadingState:o.status,reloadOidcUser:h}};Object.defineProperty(R,"TokenRenewMode",{enumerable:!0,get:()=>l.TokenRenewMode}),R.OidcProvider=ht,R.OidcSecure=Re,R.OidcUserStatus=Ce,R.useOidc=_t,R.useOidcAccessToken=yt,R.useOidcFetch=Oe,R.useOidcIdToken=kt,R.useOidcUser=mt,R.withOidcFetch=$e,R.withOidcSecure=pt,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
|
|
27
|
+
Check the top-level render call using <`+n+">.")}return t}}function ze(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var n=Lt(t);if(Ke[n])return;Ke[n]=!0;var u="";e&&e._owner&&e._owner!==ue.current&&(u=" It was passed a child from "+E(e._owner.type)+"."),L(e),O('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',n,u),L(null)}}function Ge(e,t){{if(typeof e!="object")return;if(ce(e))for(var n=0;n<e.length;n++){var u=e[n];fe(u)&&ze(u,t)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var b=$(e);if(typeof b=="function"&&b!==e.entries)for(var m=b.call(e),y;!(y=m.next()).done;)fe(y.value)&&ze(y.value,t)}}}function Wt(e){{var t=e.type;if(t==null||typeof t=="string")return;var n;if(typeof t=="function")n=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===v||t.$$typeof===w))n=t.propTypes;else return;if(n){var u=E(t);wt(n,e.props,"prop",u,e)}else if(t.PropTypes!==void 0&&!de){de=!0;var b=E(t);O("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",b||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&O("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Mt(e){{for(var t=Object.keys(e.props),n=0;n<t.length;n++){var u=t[n];if(u!=="children"&&u!=="key"){L(e),O("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",u),L(null);break}}e.ref!==null&&(L(e),O("Invalid attribute `ref` supplied to `React.Fragment`."),L(null))}}function He(e,t,n,u,b,m){{var y=Se(e);if(!y){var p="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(p+=" 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 P=Ut(b);P?p+=P:p+=Be();var T;e===null?T="null":ce(e)?T="array":e!==void 0&&e.$$typeof===a?(T="<"+(E(e.type)||"Unknown")+" />",p=" Did you accidentally export a JSX literal instead of a component?"):T=typeof e,O("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",T,p)}var S=Dt(e,t,n,b,m);if(S==null)return S;if(y){var C=t.children;if(C!==void 0)if(u)if(ce(C)){for(var W=0;W<C.length;W++)Ge(C[W],e);Object.freeze&&Object.freeze(C)}else O("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 Ge(C,e)}return e===o?Mt(S):Wt(S),S}}function Yt(e,t,n){return He(e,t,n,!0)}function Vt(e,t,n){return He(e,t,n,!1)}var Bt=Vt,Kt=Yt;Y.Fragment=o,Y.jsx=Bt,Y.jsxs=Kt}()),Y}process.env.NODE_ENV==="production"?Q.exports=Xe():Q.exports=Qe();var d=Q.exports;const pe="default",Ze=(s,a)=>async(...r)=>{var R;const[o,f,...l]=r,h=f?{...f}:{method:"GET"};let c=new Headers;h.headers&&(c=h.headers instanceof Headers?h.headers:new Headers(h.headers));const _=await a().getValidTokenAsync(),g=(R=_==null?void 0:_.tokens)==null?void 0:R.accessToken;c.has("Accept")||c.set("Accept","application/json"),g&&(c.set("Authorization",`Bearer ${g}`),h.credentials||(h.credentials="same-origin"));const w={...h,headers:c};return await s(o,w,...l)},qe=(s=null,a=pe)=>r=>o=>{const{fetch:f}=_e(s||o.fetch,a);return d.jsx(r,{...o,fetch:f})},_e=(s=null,a=pe)=>{const r=s||window.fetch,o=i.OidcClient.get;return{fetch:k.useCallback((l,h)=>Ze(r,()=>o(a))(l,h),[r,a])}},ye=()=>d.jsx("div",{className:"oidc-authenticating",children:d.jsxs("div",{className:"oidc-authenticating__container",children:[d.jsx("h1",{className:"oidc-authenticating__title",children:"Error authentication"}),d.jsx("p",{className:"oidc-authenticating__content",children:"An error occurred during authentication."})]})}),$e=()=>d.jsx("div",{className:"oidc-authenticating",children:d.jsxs("div",{className:"oidc-authenticating__container",children:[d.jsx("h1",{className:"oidc-authenticating__title",children:"Authentication in progress"}),d.jsx("p",{className:"oidc-authenticating__content",children:"You will be redirected to the login page."})]})}),et=()=>Math.random().toString(36).substr(2,6),tt=(s,a)=>(r,o)=>{if(typeof s.CustomEvent=="function")return new s.CustomEvent(r,o);const f=o||{bubbles:!1,cancelable:!1,detail:void 0},l=a.createEvent("CustomEvent");return l.initCustomEvent(r,f.bubbles,f.cancelable,f.detail),l.prototype=s.Event.prototype,l},nt=(s,a,r)=>({replaceState:(o,f)=>{const l=r(),h=f||s.history.state;s.history.replaceState({key:l,state:h},null,o),s.dispatchEvent(a("popstate"))}}),rt=()=>nt(window,tt(window,document),et),ge=()=>d.jsx("div",{className:"oidc-callback",children:d.jsxs("div",{className:"oidc-callback__container",children:[d.jsx("h1",{className:"oidc-callback__title",children:"Authentication complete"}),d.jsx("p",{className:"oidc-callback__content",children:"You will be redirected to your application."})]})}),st=({callBackError:s,callBackSuccess:a,configurationName:r,withCustomHistory:o})=>{const[f,l]=k.useState(!1);k.useEffect(()=>{let v=!0;return(async()=>{const g=i.OidcClient.get;try{const{callbackPath:w}=await g(r).loginCallbackAsync();(o?o():rt()).replaceState(w||"/")}catch(w){v&&(console.warn(w),l(!0))}})(),()=>{v=!1}},[]);const h=s||ye,c=a||ge;return f?d.jsx(h,{configurationName:r}):d.jsx(c,{configurationName:r})},at=()=>d.jsx("div",{className:"oidc-serviceworker",children:d.jsxs("div",{className:"oidc-serviceworker__container",children:[d.jsx("h1",{className:"oidc-serviceworker__title",children:"Unable to authenticate on this browser"}),d.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."})]})}),ot=()=>d.jsx("div",{className:"oidc-session-lost",children:d.jsxs("div",{className:"oidc-session-lost__container",children:[d.jsx("h1",{className:"oidc-session-lost__title",children:"Session timed out"}),d.jsx("p",{className:"oidc-session-lost__content",children:"Your session has expired. Please re-authenticate."})]})}),it=({configurationName:s})=>(k.useEffect(()=>{(async()=>{const r=i.OidcClient.get;r(s).silentLoginCallbackAsync()})()},[]),d.jsx(d.Fragment,{})),ct=({configurationName:s})=>{const a=i.getParseQueryStringFromLocation(window.location.href),r=i.OidcClient.get,o=r(s);let f=null;for(const[l,h]of Object.entries(a))l==="state"||l==="scope"||(f===null&&(f={}),f[l]=h);return k.useEffect(()=>{o.tokens||o.loginAsync(null,f,!0,a.scope)},[]),d.jsx(d.Fragment,{})},lt=({callbackErrorComponent:s,callbackSuccessComponent:a,redirect_uri:r,silent_redirect_uri:o,silent_login_uri:f,children:l,configurationName:h,withCustomHistory:c=null})=>{const v=window?i.getPath(window.location.href):"",[_,g]=k.useState(v);k.useEffect(()=>{const R=()=>g(i.getPath(window.location.href));return R(),window.addEventListener("popstate",R,!1),()=>window.removeEventListener("popstate",R,!1)},[]);const w=i.getPath(r);if(o&&_===i.getPath(o))return d.jsx(it,{configurationName:h});if(f&&_===i.getPath(f))return d.jsx(ct,{configurationName:h});switch(_){case w:return d.jsx(st,{callBackError:s,callBackSuccess:a,configurationName:h,withCustomHistory:c});default:return d.jsx(d.Fragment,{children:l})}},ut=k.memo(lt),be={name:"",data:null},dt=({children:s,configurationName:a})=>{const r=i.OidcClient.get,o=r(a);return k.useEffect(()=>{o&&o.tryKeepExistingSessionAsync()},[a]),d.jsx(d.Fragment,{children:s})},ft=({children:s,configuration:a,configurationName:r="default",callbackSuccessComponent:o=ge,authenticatingComponent:f=$e,serviceWorkerNotSupportedComponent:l=at,authenticatingErrorComponent:h=ye,sessionLostComponent:c=ot,onSessionLost:v=null,onLogoutFromAnotherTab:_=null,onLogoutFromSameTab:g=null,withCustomHistory:w=null,onEvent:R=null,getFetch:I=null})=>{const F=(V="default")=>i.OidcClient.getOrCreate(I??i.getFetchDefault)(a,V),[Te,$]=k.useState(!0),[N,O]=k.useState(be),[we,ee]=k.useState("default");k.useEffect(()=>{const U=F(r).subscribeEvents((E,x)=>{R&&R(r,E,x)});return()=>{F(r).removeEventSubscription(U)}},[r,R]),k.useEffect(()=>{const U=F(r).subscribeEvents((E,x)=>{if(E===i.OidcClient.eventNames.refreshTokensAsync_error||E===i.OidcClient.eventNames.syncTokensAsync_error){if(v!=null){v();return}O({name:E,data:x})}else if(E===i.OidcClient.eventNames.logout_from_another_tab){if(_!=null){_();return}O({name:E,data:x})}else E===i.OidcClient.eventNames.logout_from_same_tab?g!=null&&g():E===i.OidcClient.eventNames.loginAsync_begin||E===i.OidcClient.eventNames.loginCallbackAsync_end||E===i.OidcClient.eventNames.loginAsync_error||E===i.OidcClient.eventNames.loginCallbackAsync_error?O({name:E,data:x}):E===i.OidcClient.eventNames.service_worker_not_supported_by_browser&&a.service_worker_only===!0&&O({name:E,data:x})});return ee(r),$(!1),()=>{F(r).removeEventSubscription(U),O(be)}},[a,r]);const te=c,ne=f,re=l,se=h,D=F(r);switch(N.name){case i.OidcClient.eventNames.service_worker_not_supported_by_browser:return d.jsx(re,{configurationName:r});case i.OidcClient.eventNames.loginAsync_begin:return d.jsx(ne,{configurationName:r});case i.OidcClient.eventNames.loginAsync_error:case i.OidcClient.eventNames.loginCallbackAsync_error:return d.jsx(se,{configurationName:r});case i.OidcClient.eventNames.refreshTokensAsync_error:case i.OidcClient.eventNames.syncTokensAsync_error:case i.OidcClient.eventNames.logout_from_another_tab:return d.jsx(te,{configurationName:r});default:return d.jsx(ut,{redirect_uri:D.configuration.redirect_uri,silent_redirect_uri:D.configuration.silent_redirect_uri,silent_login_uri:D.configuration.silent_login_uri,callbackSuccessComponent:o,callbackErrorComponent:h,authenticatingComponent:f,configurationName:r,withCustomHistory:w,children:d.jsx(dt,{configurationName:r,children:s})})}},ke=({children:s,callbackPath:a=null,extras:r=null,configurationName:o="default"})=>{const f=i.OidcClient.get,l=f(o);return k.useEffect(()=>{l.tryKeepExistingSessionAsync().then(()=>{l.tokens||l.loginAsync(a,r)})},[o,a,r]),!l&&!l.tokens?null:d.jsx(d.Fragment,{children:s})},vt=(s,a=null,r=null,o="default")=>f=>d.jsx(ke,{callbackPath:a,extras:r,configurationName:o,children:d.jsx(s,{...f})}),Z="default",q=(s,a)=>{let r=!1;return s(a)&&(r=s(a).tokens!=null),r},ht=(s=Z)=>{const a=i.OidcClient.get,[r,o]=k.useState(q(a,s));return k.useEffect(()=>{let c=!0;const v=a(s);o(q(a,s));const _=v.subscribeEvents((g,w)=>{(g===i.OidcClient.eventNames.logout_from_another_tab||g===i.OidcClient.eventNames.logout_from_same_tab||g===i.OidcClient.eventNames.token_aquired||g==i.OidcClient.eventNames.tryKeepExistingSessionAsync_end)&&c&&o(q(a,s))});return()=>{c=!1,v.removeEventSubscription(_)}},[s]),{login:(c=void 0,v=null,_=!1)=>a(s).loginAsync(c,v,!1,void 0,_),logout:(c=void 0,v=null)=>a(s).logoutAsync(c,v),renewTokens:async(c=null)=>{const v=await a(s).renewTokensAsync(c);return{accessToken:v.accessToken,accessTokenPayload:v.accessTokenPayload,idToken:v.idToken,idTokenPayload:v.idTokenPayload}},isAuthenticated:r}},Ee={accessToken:null,accessTokenPayload:null},pt=s=>{const a=i.OidcClient.get,r=a(s);if(r.tokens){const o=r.tokens;return{accessToken:o.accessToken,accessTokenPayload:o.accessTokenPayload}}return Ee},_t=(s=Z)=>{const a=i.OidcClient.get,[r,o]=k.useState(pt(s));return k.useEffect(()=>{let f=!0;const l=a(s);if(l.tokens){const c=l.tokens;o({accessToken:c.accessToken,accessTokenPayload:c.accessTokenPayload})}const h=l.subscribeEvents((c,v)=>{if((c===i.OidcClient.eventNames.token_renewed||c===i.OidcClient.eventNames.token_aquired||c===i.OidcClient.eventNames.logout_from_another_tab||c===i.OidcClient.eventNames.logout_from_same_tab||c===i.OidcClient.eventNames.refreshTokensAsync_error||c===i.OidcClient.eventNames.syncTokensAsync_error||c==i.OidcClient.eventNames.tryKeepExistingSessionAsync_end)&&f){const _=l.tokens;o(_!=null?{accessToken:_.accessToken,accessTokenPayload:_.accessTokenPayload}:Ee)}});return()=>{f=!1,l.removeEventSubscription(h)}},[s]),r},me={idToken:null,idTokenPayload:null},yt=s=>{const a=i.OidcClient.get,r=a(s);if(r.tokens){const o=r.tokens;return{idToken:o.idToken,idTokenPayload:o.idTokenPayload}}return me},gt=(s=Z)=>{const a=i.OidcClient.get,[r,o]=k.useState(yt(s));return k.useEffect(()=>{let f=!0;const l=a(s);if(l.tokens){const c=l.tokens;o({idToken:c.idToken,idTokenPayload:c.idTokenPayload})}const h=l.subscribeEvents((c,v)=>{if((c===i.OidcClient.eventNames.token_renewed||c===i.OidcClient.eventNames.token_aquired||c===i.OidcClient.eventNames.logout_from_another_tab||c===i.OidcClient.eventNames.logout_from_same_tab||c===i.OidcClient.eventNames.refreshTokensAsync_error||c===i.OidcClient.eventNames.syncTokensAsync_error||c==i.OidcClient.eventNames.tryKeepExistingSessionAsync_end)&&f){const _=l.tokens;o(_!=null?{idToken:_.idToken,idTokenPayload:_.idTokenPayload}:me)}});return()=>{f=!1,l.removeEventSubscription(h)}},[s]),r};var Oe=(s=>(s.Unauthenticated="Unauthenticated",s.Loading="Loading user",s.Loaded="User loaded",s.LoadingError="Error loading user",s))(Oe||{});const bt=(s="default")=>{const[a,r]=k.useState({user:null,status:"Unauthenticated"}),[o,f]=k.useState(""),l=i.OidcClient.get(s);k.useEffect(()=>{let c=!0;if(l&&l.tokens){r({...a,status:"Loading user"});const _=o!=="";l.userInfoAsync(_).then(g=>{c&&r({user:g,status:"User loaded"})}).catch(()=>r({...a,status:"Error loading user"}))}else r({user:null,status:"Unauthenticated"});const v=l.subscribeEvents((_,g)=>{console.log(`Event ${_} has been raised`),_==i.OidcClient.eventNames.tryKeepExistingSessionAsync_end&&c&&h()});return()=>{c=!1,l.removeEventSubscription(v)}},[o]);const h=()=>{f(o+" ")};return{oidcUser:a.user,oidcUserLoadingState:a.status,reloadOidcUser:h}};Object.defineProperty(j,"TokenRenewMode",{enumerable:!0,get:()=>i.TokenRenewMode}),j.OidcProvider=ft,j.OidcSecure=ke,j.OidcUserStatus=Oe,j.useOidc=ht,j.useOidcAccessToken=_t,j.useOidcFetch=_e,j.useOidcIdToken=gt,j.useOidcUser=bt,j.withOidcFetch=qe,j.withOidcSecure=vt,Object.defineProperty(j,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.4.0-alpha.1025",
|
|
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.4.0-alpha.1025",
|
|
44
|
+
"@axa-fr/oidc-client": "7.4.0-alpha.1025",
|
|
45
45
|
"base64-js": "1.5.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
package/src/OidcProvider.tsx
CHANGED
|
@@ -18,7 +18,6 @@ export type OidcProviderProps = {
|
|
|
18
18
|
sessionLostComponent?: ComponentType<any>;
|
|
19
19
|
authenticatingComponent?: ComponentType<any>;
|
|
20
20
|
authenticatingErrorComponent?: ComponentType<any>;
|
|
21
|
-
loadingComponent?: ComponentType<any>;
|
|
22
21
|
serviceWorkerNotSupportedComponent?: ComponentType<any>;
|
|
23
22
|
configurationName?: string;
|
|
24
23
|
configuration?: OidcConfiguration;
|
|
@@ -33,39 +32,18 @@ export type OidcProviderProps = {
|
|
|
33
32
|
|
|
34
33
|
export type OidcSessionProps = {
|
|
35
34
|
configurationName: string;
|
|
36
|
-
loadingComponent: PropsWithChildren<any>;
|
|
37
35
|
};
|
|
38
36
|
|
|
39
|
-
const OidcSession: FC<PropsWithChildren<OidcSessionProps>> = ({
|
|
40
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
37
|
+
const OidcSession: FC<PropsWithChildren<OidcSessionProps>> = ({ children, configurationName }) => {
|
|
41
38
|
const getOidc = OidcClient.get;
|
|
42
39
|
const oidc = getOidc(configurationName);
|
|
43
40
|
useEffect(() => {
|
|
44
|
-
let isMounted = true;
|
|
45
41
|
if (oidc) {
|
|
46
|
-
oidc.tryKeepExistingSessionAsync()
|
|
47
|
-
if (isMounted) {
|
|
48
|
-
setIsLoading(false);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
42
|
+
oidc.tryKeepExistingSessionAsync();
|
|
51
43
|
}
|
|
52
|
-
return () => {
|
|
53
|
-
isMounted = false;
|
|
54
|
-
};
|
|
55
44
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
45
|
}, [configurationName]);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
{isLoading
|
|
61
|
-
? (
|
|
62
|
-
<LoadingComponent configurationName={configurationName} />
|
|
63
|
-
)
|
|
64
|
-
: (
|
|
65
|
-
<>{children}</>
|
|
66
|
-
)}
|
|
67
|
-
</>
|
|
68
|
-
);
|
|
46
|
+
return <>{children}</>;
|
|
69
47
|
};
|
|
70
48
|
|
|
71
49
|
const Switch = ({ isLoading, loadingComponent, children, configurationName }) => {
|
|
@@ -82,7 +60,6 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
82
60
|
configurationName = 'default',
|
|
83
61
|
callbackSuccessComponent = CallBackSuccess,
|
|
84
62
|
authenticatingComponent = Authenticating,
|
|
85
|
-
loadingComponent = Loading,
|
|
86
63
|
serviceWorkerNotSupportedComponent = ServiceWorkerNotSupported,
|
|
87
64
|
authenticatingErrorComponent = AuthenticatingError,
|
|
88
65
|
sessionLostComponent = SessionLost,
|
|
@@ -157,7 +134,6 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
157
134
|
|
|
158
135
|
const SessionLostComponent = sessionLostComponent;
|
|
159
136
|
const AuthenticatingComponent = authenticatingComponent;
|
|
160
|
-
const LoadingComponent = loadingComponent;
|
|
161
137
|
const ServiceWorkerNotSupportedComponent = serviceWorkerNotSupportedComponent;
|
|
162
138
|
const AuthenticatingErrorComponent = authenticatingErrorComponent;
|
|
163
139
|
|
|
@@ -166,27 +142,27 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
166
142
|
const eventName = event.name;
|
|
167
143
|
switch (eventName) {
|
|
168
144
|
case OidcClient.eventNames.service_worker_not_supported_by_browser:
|
|
169
|
-
return (
|
|
145
|
+
return (
|
|
170
146
|
<ServiceWorkerNotSupportedComponent configurationName={configurationName} />
|
|
171
|
-
|
|
147
|
+
);
|
|
172
148
|
case OidcClient.eventNames.loginAsync_begin:
|
|
173
|
-
return (
|
|
149
|
+
return (
|
|
174
150
|
<AuthenticatingComponent configurationName={configurationName} />
|
|
175
|
-
|
|
151
|
+
);
|
|
176
152
|
case OidcClient.eventNames.loginAsync_error:
|
|
177
153
|
case OidcClient.eventNames.loginCallbackAsync_error:
|
|
178
|
-
return (
|
|
154
|
+
return (
|
|
179
155
|
<AuthenticatingErrorComponent configurationName={configurationName} />
|
|
180
|
-
|
|
156
|
+
);
|
|
181
157
|
case OidcClient.eventNames.refreshTokensAsync_error:
|
|
182
158
|
case OidcClient.eventNames.syncTokensAsync_error:
|
|
183
159
|
case OidcClient.eventNames.logout_from_another_tab:
|
|
184
|
-
return (
|
|
160
|
+
return (
|
|
185
161
|
<SessionLostComponent configurationName={configurationName} />
|
|
186
|
-
|
|
162
|
+
);
|
|
187
163
|
default:
|
|
188
164
|
return (
|
|
189
|
-
|
|
165
|
+
|
|
190
166
|
<OidcRoutes redirect_uri={oidc.configuration.redirect_uri}
|
|
191
167
|
silent_redirect_uri={oidc.configuration.silent_redirect_uri}
|
|
192
168
|
silent_login_uri={oidc.configuration.silent_login_uri}
|
|
@@ -195,11 +171,10 @@ export const OidcProvider: FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
195
171
|
authenticatingComponent={authenticatingComponent}
|
|
196
172
|
configurationName={configurationName}
|
|
197
173
|
withCustomHistory={withCustomHistory}>
|
|
198
|
-
<OidcSession
|
|
174
|
+
<OidcSession configurationName={configurationName}>
|
|
199
175
|
{children}
|
|
200
176
|
</OidcSession>
|
|
201
177
|
</OidcRoutes>
|
|
202
|
-
</Switch>
|
|
203
178
|
);
|
|
204
179
|
}
|
|
205
180
|
};
|
package/src/OidcSecure.tsx
CHANGED
|
@@ -11,12 +11,14 @@ export const OidcSecure: FC<PropsWithChildren<OidcSecureProps>> = ({ children, c
|
|
|
11
11
|
const getOidc = OidcClient.get;
|
|
12
12
|
const oidc = getOidc(configurationName);
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
oidc.
|
|
16
|
-
|
|
14
|
+
oidc.tryKeepExistingSessionAsync().then(() => {
|
|
15
|
+
if (!oidc.tokens) {
|
|
16
|
+
oidc.loginAsync(callbackPath, extras);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
17
19
|
}, [configurationName, callbackPath, extras]);
|
|
18
20
|
|
|
19
|
-
if (!oidc.tokens) {
|
|
21
|
+
if (!oidc &&!oidc.tokens) {
|
|
20
22
|
return null;
|
|
21
23
|
}
|
|
22
24
|
return <>{children}</>;
|
package/src/ReactOidc.tsx
CHANGED
|
@@ -26,7 +26,7 @@ export const useOidc = (configurationName = defaultConfigurationName) => {
|
|
|
26
26
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
28
|
const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
|
|
29
|
-
if (name === OidcClient.eventNames.logout_from_another_tab || name === OidcClient.eventNames.logout_from_same_tab || name === OidcClient.eventNames.token_aquired) {
|
|
29
|
+
if (name === OidcClient.eventNames.logout_from_another_tab || name === OidcClient.eventNames.logout_from_same_tab || name === OidcClient.eventNames.token_aquired || name == OidcClient.eventNames.tryKeepExistingSessionAsync_end) {
|
|
30
30
|
if (isMounted) {
|
|
31
31
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
32
32
|
}
|
|
@@ -100,7 +100,9 @@ export const useOidcAccessToken = (configurationName = defaultConfigurationName)
|
|
|
100
100
|
name === OidcClient.eventNames.logout_from_another_tab ||
|
|
101
101
|
name === OidcClient.eventNames.logout_from_same_tab ||
|
|
102
102
|
name === OidcClient.eventNames.refreshTokensAsync_error ||
|
|
103
|
-
name === OidcClient.eventNames.syncTokensAsync_error
|
|
103
|
+
name === OidcClient.eventNames.syncTokensAsync_error ||
|
|
104
|
+
name == OidcClient.eventNames.tryKeepExistingSessionAsync_end
|
|
105
|
+
) {
|
|
104
106
|
if (isMounted) {
|
|
105
107
|
const tokens = oidc.tokens;
|
|
106
108
|
setAccessToken(tokens != null ? { accessToken: tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload } : accessTokenInitialState);
|
|
@@ -151,7 +153,8 @@ export const useOidcIdToken = (configurationName = defaultConfigurationName) =>
|
|
|
151
153
|
name === OidcClient.eventNames.logout_from_another_tab ||
|
|
152
154
|
name === OidcClient.eventNames.logout_from_same_tab ||
|
|
153
155
|
name === OidcClient.eventNames.refreshTokensAsync_error ||
|
|
154
|
-
name === OidcClient.eventNames.syncTokensAsync_error
|
|
156
|
+
name === OidcClient.eventNames.syncTokensAsync_error ||
|
|
157
|
+
name == OidcClient.eventNames.tryKeepExistingSessionAsync_end) {
|
|
155
158
|
if (isMounted) {
|
|
156
159
|
const tokens = oidc.tokens;
|
|
157
160
|
setIDToken(tokens != null ? { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload } : idTokenInitialState);
|
package/src/User.ts
CHANGED
|
@@ -34,7 +34,20 @@ export const useOidcUser = <T extends OidcUserInfo = OidcUserInfo>(configuration
|
|
|
34
34
|
} else {
|
|
35
35
|
setOidcUser({ user: null, status: OidcUserStatus.Unauthenticated });
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
|
|
39
|
+
console.log(`Event ${name} has been raised`);
|
|
40
|
+
if (name == OidcClient.eventNames.tryKeepExistingSessionAsync_end) {
|
|
41
|
+
if (isMounted) {
|
|
42
|
+
reloadOidcUser();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
isMounted = false;
|
|
49
|
+
oidc.removeEventSubscription(newSubscriptionId);
|
|
50
|
+
};
|
|
38
51
|
}, [oidcUserId]);
|
|
39
52
|
|
|
40
53
|
const reloadOidcUser = () => {
|