@axa-fr/oidc-client 7.15.2 → 7.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ const m = {
86
86
  },
87
87
  getLoginParams: () => {
88
88
  const p = s[`oidc.login.${e}`];
89
- return p ? (g[e] || (g[e] = JSON.parse(p)), g[e]) : (console.warn(`storage[oidc.login.${e}] is empty`), null);
89
+ return p ? (g[e] || (g[e] = JSON.parse(p)), g[e]) : (console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`), null);
90
90
  },
91
91
  getStateAsync: async () => s[`oidc.state.${e}`],
92
92
  setStateAsync: async (p) => {
@@ -284,7 +284,7 @@ const z = (e, s = null, n) => {
284
284
  setInterval: r,
285
285
  clearInterval: c
286
286
  };
287
- }(), ce = "7.15.2";
287
+ }(), ce = "7.15.3";
288
288
  let le = null, j;
289
289
  const K = ({ milliseconds: e }) => new Promise((s) => J.setTimeout(s, e)), ge = (e = "/") => {
290
290
  try {
@@ -1,2 +1,2 @@
1
- (function(C,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(C=typeof globalThis<"u"?globalThis:C||self,G(C["oidc-client"]={}))})(this,function(C){"use strict";const D=console;class Ie{constructor(n,s,t,o=2e3,i=!0){this._callback=n,this._client_id=s,this._url=t,this._interval=o||2e3,this._stopOnError=i;const r=t.indexOf("/",t.indexOf("//")+2);this._frame_origin=t.substr(0,r),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=t}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(D.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(D.debug(n),D.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):D.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){D.debug("CheckSessionIFrame.start :"+n),this.stop();const s=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};s(),this._timer=window.setInterval(s,this._interval)}stop(){this._timer&&(D.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const m={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error"},O=(e,n=sessionStorage)=>{const s=p=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:p}),Promise.resolve()),t=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const p=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:p.tokens,status:p.status})},o=p=>{n[`oidc.${e}`]=JSON.stringify({tokens:p})},i=async p=>{n[`oidc.session_state.${e}`]=p},r=async()=>n[`oidc.session_state.${e}`],c=p=>{n[`oidc.nonce.${e}`]=p.nonce},a=p=>{n[`oidc.jwk.${e}`]=JSON.stringify(p)},f=()=>JSON.parse(n[`oidc.jwk.${e}`]),d=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async p=>{n[`oidc.dpop_nonce.${e}`]=p},u=()=>n[`oidc.dpop_nonce.${e}`],y=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let g={};return{clearAsync:s,initAsync:t,setTokens:o,getTokens:y,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:c,getNonceAsync:d,setLoginParams:p=>{g[e]=p,n[`oidc.login.${e}`]=JSON.stringify(p)},getLoginParams:()=>{const p=n[`oidc.login.${e}`];return p?(g[e]||(g[e]=JSON.parse(p)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async p=>{n[`oidc.state.${e}`]=p},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async p=>{n[`oidc.code_verifier.${e}`]=p},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:u,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:f}},Ce=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),Ne=e=>JSON.parse(Ce(e.replace(/-/g,"+").replace(/_/g,"/"))),le=e=>{try{return e&&xe(e,".")===2?Ne(e.split(".")[1]):null}catch(n){console.warn(n)}return null},xe=(e,n)=>e.split(n).length-1,Y={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,s){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:s&&s.iat?s.iat:new Date().getTime()/1e3;return e.issuedAt}const X=(e,n=null,s)=>{if(!e)return null;let t;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?t=e.accessTokenPayload:t=le(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:le(i),c=r&&r.exp?r.exp:Number.MAX_VALUE,a=t&&t.exp?t.exp:e.issuedAt+o;e.issuedAt=Le(e,t,r);let f;e.expiresAt?f=e.expiresAt:s===Y.access_token_invalid?f=a:s===Y.id_token_invalid?f=c:f=c<a?c:a;const d={...e,idTokenPayload:r,accessTokenPayload:t,expiresAt:f,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...d,refreshToken:l}}return d},ne=(e,n,s)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const t={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(t.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(t.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(t.idTokenPayload=e.idTokenPayload),X(t,n,s)},V=(e,n)=>{const s=new Date().getTime()/1e3,t=n-s;return Math.round(t-e)},se=e=>e?V(0,e.expiresAt)>0:!1,We=async(e,n=200,s=50)=>{let t=s;if(!e.tokens)return null;for(;!se(e.tokens)&&t>0;)await $({milliseconds:n}),t=t-1;return{isTokensValid:se(e.tokens),tokens:e.tokens,numberWaited:t-s}},ue=(e,n,s)=>{if(e.idTokenPayload){const t=e.idTokenPayload;if(s.issuer!==t.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${s.issuer} !== (idTokenPayload issuer) ${t.iss}`};const o=new Date().getTime()/1e3;if(t.exp&&t.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${t.exp} < (currentTimeUnixSecond) ${o}`};const i=60*60*24*7;if(t.iat&&t.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${t.iat+i} < (currentTimeUnixSecond) ${o}`};if(t.nonce&&t.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},M=function(){const e=function(){let a,f;const d=(function(){const u={},y={setTimeout:function(h,_,A){u[_]=setTimeout(function(){h.postMessage(_),u[_]=null},A)},setInterval:function(h,_,A){u[_]=setInterval(function(){h.postMessage(_)},A)},clearTimeout:function(h,_){clearTimeout(u[_]),u[_]=null},clearInterval:function(h,_){clearInterval(u[_]),u[_]=null}};function g(h,_){const A=_.data[0],S=_.data[1],T=_.data[2];y[A]&&y[A](h,S,T)}this.onmessage=function(h){g(self,h)},this.onconnect=function(h){const _=h.ports[0];_.onmessage=function(A){g(_,A)}}}).toString();try{const u=new Blob(["(",d,")()"],{type:"application/javascript"});f=URL.createObjectURL(u)}catch{return null}const l=typeof process>"u";try{if(SharedWorker)return a=new SharedWorker(f),a.port}catch{l&&console.warn("SharedWorker not available")}try{if(Worker)return a=new Worker(f),a}catch{l&&console.warn("Worker not available")}return null}();if(!e){const a=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(a),clearTimeout:clearTimeout.bind(a),setInterval:setInterval.bind(a),clearInterval:clearInterval.bind(a)}}const n=function(){let a=0;return function(){return a++,a}}(),s={},t={};e.onmessage=function(a){const f=a.data,d=s[f];if(d){d(),s[f]=null;return}const l=t[f];l&&l()};function o(a,f){const d=n();return e.postMessage(["setTimeout",d,f]),s[d]=a,d}function i(a){e.postMessage(["clearTimeout",a]),s[a]=null}function r(a,f){const d=n();return e.postMessage(["setInterval",d,f]),t[d]=a,d}function c(a){e.postMessage(["clearInterval",a]),t[a]=null}return{setTimeout:o,clearTimeout:i,setInterval:r,clearInterval:c}}(),de="7.15.2";let fe=null,z;const $=({milliseconds:e})=>new Promise(n=>M.setTimeout(n,e)),he=(e="/")=>{try{z=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:z.signal}).catch(t=>{console.log(t)}),$({milliseconds:150*1e3}).then(he)}catch(n){console.log(n)}},De=()=>{z&&z.abort()},$e=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),Re=e=>async(n,s)=>{s(),await n.update();const t=await n.unregister();console.log(`Service worker unregistering ${t}`),await $({milliseconds:2e3}),e.reload()},b=e=>n=>new Promise(function(s,t){const o=new MessageChannel;o.port1.onmessage=function(i){i.data&&i.data.error?t(i.data.error):s(i.data)},e.active.postMessage(n,[o.port2])}),E=async(e,n)=>{const s=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!s||e.service_worker_activate()===!1)return null;let t=null;e.register?t=await e.service_worker_register(s):t=await navigator.serviceWorker.register(s);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await b(t)({type:"claim"})}catch{return null}const o=async k=>b(t)({type:"clear",data:{status:k},configurationName:n}),i=async(k,w,I)=>{const P=await b(t)({type:"init",data:{oidcServerConfiguration:k,where:w,oidcConfiguration:{token_renew_mode:I.token_renew_mode,service_worker_convert_all_requests_to_cors:I.service_worker_convert_all_requests_to_cors}},configurationName:n}),F=P.version;return F!==de&&(console.warn(`Service worker ${F} version mismatch with js client version ${de}, unregistering and reloading`),await I.service_worker_update_require_callback(t,De)),{tokens:ne(P.tokens,null,I.token_renew_mode),status:P.status}},r=(k="/")=>{fe==null&&(fe="not_null",he(k))},c=k=>b(t)({type:"setSessionState",data:{sessionState:k},configurationName:n}),a=async()=>(await b(t)({type:"getSessionState",data:null,configurationName:n})).sessionState,f=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,b(t)({type:"setNonce",data:{nonce:k},configurationName:n})),d=async()=>{let w=(await b(t)({type:"getNonce",data:null,configurationName:n})).nonce;return w||(w=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:w}};let l={};return{clearAsync:o,initAsync:i,startKeepAliveServiceWorker:()=>r(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>$e(e.service_worker_keep_alive_path),setSessionStateAsync:c,getSessionStateAsync:a,setNonceAsync:f,getNonceAsync:d,setLoginParams:k=>{l[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},getLoginParams:()=>{const k=localStorage[`oidc.login.${n}`];return l[n]||(l[n]=JSON.parse(k)),l[n]},getStateAsync:async()=>{let w=(await b(t)({type:"getState",data:null,configurationName:n})).state;return w||(w=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),w},setStateAsync:async k=>(sessionStorage[`oidc.state.${n}`]=k,b(t)({type:"setState",data:{state:k},configurationName:n})),getCodeVerifierAsync:async()=>{let w=(await b(t)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return w||(w=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),w},setCodeVerifierAsync:async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,b(t)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n})),setDemonstratingProofOfPossessionNonce:async k=>{await b(t)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await b(t)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async k=>{const w=JSON.stringify(k);b(t)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:w},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const k=await b(t)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null}}};async function _e(e,n,s){const t=c=>{e.tokens=c},{tokens:o,status:i}=await e.synchroniseTokensAsync(0,n,s,t);return await E(e.configuration,e.configurationName)||await O(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(i),null)}const Ke=async(e,n)=>{const s=await E(n,e.configurationName);if(s){const t=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await s.initAsync(t,"tryKeepExistingSessionAsync",n);return o}else{const t=O(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await t.initAsync();return o=X(o,e.tokens,n.token_renew_mode),o}};async function ye(e,n=!1,s=null){const t=e.configuration,o=`${t.client_id}_${e.configurationName}_${t.authority}`;let i;const r=await E(e.configuration,e.configurationName);return(t==null?void 0:t.storage)===(window==null?void 0:window.sessionStorage)&&!r?i=await _e(e,n,s):i=await navigator.locks.request(o,{ifAvailable:!0},async c=>c?await _e(e,n,s):(e.publishEvent(U.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await Ke(e,t))),i?(e.timeoutId&&(e.timeoutId=J(e,e.tokens.expiresAt,s)),e.tokens):null}const J=(e,n,s=null)=>{const t=e.configuration.refresh_time_before_tokens_expiration_in_second;return M.setTimeout(async()=>{const i={timeLeft:V(t,n)};e.publishEvent(U.eventNames.token_timer,i),await ye(e,!1,s)},1e3)},R={SESSION_LOST:"SESSION_LOST",NOT_CONNECTED:"NOT_CONNECTED",TOKENS_VALID:"TOKENS_VALID",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},Ue=e=>async(n,s,t,o=!1)=>{const i={nonce:null};if(!t)return{tokens:null,status:"NOT_CONNECTED",nonce:i};let r=i;const c=await e.initAsync(n.authority,n.authority_configuration),a=await E(n,s);if(a){const{status:l,tokens:u}=await a.initAsync(c,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};if(l==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(!l||!u)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:i};if(u.issuedAt!==t.issuedAt){const g=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",h=await a.getNonceAsync();return{tokens:u,status:g,nonce:h}}r=await a.getNonceAsync()}else{const l=O(s,n.storage??sessionStorage);let{tokens:u,status:y}=await l.initAsync();if(u&&(u=X(u,e.tokens,n.token_renew_mode)),u){if(y==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(u.issuedAt!==t.issuedAt){const h=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",_=await l.getNonceAsync();return{tokens:u,status:h,nonce:_}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};r=await l.getNonceAsync()}const d=V(n.refresh_time_before_tokens_expiration_in_second,t.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:t,status:"FORCE_REFRESH",nonce:r}:{tokens:t,status:d,nonce:r}},te=(e,n,s)=>(t=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{s(m.silentLoginAsync_begin,{});let r="";if(o&&(t==null&&(t={}),t.state=o),i&&(t==null&&(t={}),t.scope=i),t!=null)for(const[l,u]of Object.entries(t))r===""?r=`?${encodeURIComponent(l)}=${encodeURIComponent(u)}`:r+=`&${encodeURIComponent(l)}=${encodeURIComponent(u)}`;const c=n.silent_login_uri+r,a=c.indexOf("/",c.indexOf("//")+2),f=c.substr(0,a),d=document.createElement("iframe");return d.width="0px",d.height="0px",d.id=`${e}_oidc_iframe`,d.setAttribute("src",c),document.body.appendChild(d),new Promise((l,u)=>{try{let y=!1;window.onmessage=h=>{if(h.origin===f&&h.source===d.contentWindow){const _=`${e}_oidc_tokens:`,A=`${e}_oidc_error:`,S=h.data;if(S&&typeof S=="string"&&!y){if(S.startsWith(_)){const T=JSON.parse(h.data.replace(_,""));s(m.silentLoginAsync_end,{}),d.remove(),y=!0,l(T)}else if(S.startsWith(A)){const T=JSON.parse(h.data.replace(A,""));s(m.silentLoginAsync_error,T),d.remove(),y=!0,u(new Error("oidc_"+T.error))}}}};const g=n.silent_login_timeout;setTimeout(()=>{y||(s(m.silentLoginAsync_error,{reason:"timeout"}),d.remove(),y=!0,u(new Error("timeout")))},g)}catch(y){d.remove(),s(m.silentLoginAsync_error,y),u(y)}})}catch(r){throw s(m.silentLoginAsync_error,r),r}},Fe=(e,n,s,t,o)=>(i=null,r=void 0)=>{i={...i};const c=(f,d,l)=>te(n,s,t.bind(o))(f,d,l);return(async()=>{o.timeoutId&&M.clearTimeout(o.timeoutId);let f;i&&"state"in i&&(f=i.state,delete i.state);try{const d=s.extras?{...s.extras,...i}:i,l=await c({...d,prompt:"none"},f,r);if(l)return o.tokens=l.tokens,t(m.token_aquired,{}),o.timeoutId=J(o,o.tokens.expiresAt,i),{}}catch(d){return d}})()},Ve=(e,n,s)=>(t,o,i,r=!1)=>{const c=(a,f=void 0,d=void 0)=>te(e.configurationName,s,e.publishEvent.bind(e))(a,f,d);return new Promise((a,f)=>{if(s.silent_login_uri&&s.silent_redirect_uri&&s.monitor_session&&t&&i&&!r){const d=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const u=l.idToken,y=l.idTokenPayload;return c({prompt:"none",id_token_hint:u,scope:s.scope||"openid"}).then(g=>{const h=g.tokens.idTokenPayload;if(y.sub===h.sub){const _=g.sessionState;e.checkSessionIFrame.start(g.sessionState),y.sid===h.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",_):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",_)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",h.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[h,_]of Object.entries(n))await _.logoutOtherTabAsync(s.client_id,y.sub)})};e.checkSessionIFrame=new Ie(d,o,t),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),a(e.checkSessionIFrame)}).catch(l=>{f(l)})}else a(null)})};for(var Me=He,N=[],ge="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Q=0,Je=ge.length;Q<Je;++Q)N[Q]=ge[Q];function Be(e){return N[e>>18&63]+N[e>>12&63]+N[e>>6&63]+N[e&63]}function je(e,n,s){for(var t,o=[],i=n;i<s;i+=3)t=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(e[i+2]&255),o.push(Be(t));return o.join("")}function He(e){for(var n,s=e.length,t=s%3,o=[],i=16383,r=0,c=s-t;r<c;r+=i)o.push(je(e,r,r+i>c?c:r+i));return t===1?(n=e[s-1],o.push(N[n>>2]+N[n<<4&63]+"==")):t===2&&(n=(e[s-2]<<8)+e[s-1],o.push(N[n>>10]+N[n>>4&63]+N[n<<2&63]+"=")),o.join("")}const ke=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let s=0;s<e.byteLength;s+=1){const t=e[s]%oe.length;n.push(oe[t])}return n.join("")},Ge=e=>Me(new Uint8Array(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),ie=e=>{const n=new Uint8Array(e),{hasCrypto:s}=ke();if(s)window.crypto.getRandomValues(n);else for(let t=0;t<e;t+=1)n[t]=Math.random()*oe.length|0;return qe(n)};function Ye(e){const n=new ArrayBuffer(e.length),s=new Uint8Array(n);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s}function me(e){return new Promise((n,s)=>{crypto.subtle.digest("SHA-256",Ye(e)).then(t=>n(Ge(new Uint8Array(t))),t=>s(t))})}const Xe=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=ke();return n?me(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},K={},ze=(e,n=window.sessionStorage,s)=>{if(!K[e]&&n){const o=n.getItem(e);o&&(K[e]=JSON.parse(o))}const t=1e3*s;return K[e]&&K[e].timestamp+t>Date.now()?K[e].result:null},Qe=(e,n,s=window.sessionStorage)=>{const t=Date.now();K[e]={result:n,timestamp:t},s&&s.setItem(e,JSON.stringify({result:n,timestamp:t}))},Ze=60*60,en=e=>async(n,s=Ze,t=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,c=ze(r,t,s);if(c)return new ae(c);const a=await B(e)(i,{},o);if(a.status!==200)return null;const f=await a.json();return Qe(r,f,t),new ae(f)},B=e=>async(n,s={},t=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),t),i=await e(n,{...s,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await B(e)(n,s,t,o+1);throw r}else throw console.error(r.message),r}return i},re={refresh_token:"refresh_token",access_token:"access_token"},pe=e=>async(n,s,t=re.refresh_token,o,i=1e4)=>{const r={token:s,token_type_hint:t,client_id:o},c=[];for(const d in r){const l=encodeURIComponent(d),u=encodeURIComponent(r[d]);c.push(`${l}=${u}`)}const a=c.join("&");return(await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:a},i)).status!==200?{success:!1}:{success:!0}},nn=e=>async(n,s,t,o,i={},r,c=1e4)=>{for(const[y,g]of Object.entries(t))s[y]===void 0&&(s[y]=g);const a=[];for(const y in s){const g=encodeURIComponent(y),h=encodeURIComponent(s[y]);a.push(`${g}=${h}`)}const f=a.join("&"),d=await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:f},c);if(d.status!==200)return{success:!1,status:d.status,demonstratingProofOfPossessionNonce:null};const l=await d.json();let u=null;return d.headers.has(Z)&&(u=d.headers.get(Z)),{success:!0,data:ne(l,o,r),demonstratingProofOfPossessionNonce:u}},sn=(e,n)=>async(s,t)=>{t=t?{...t}:{};const o=ie(128),i=await Xe(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(t.state),t.code_challenge=i,t.code_challenge_method="S256";let r="";if(t)for(const[c,a]of Object.entries(t))r===""?r+="?":r+="&",r+=`${c}=${encodeURIComponent(a)}`;n.open(`${s}${r}`)},Z="DPoP-Nonce",tn=e=>async(n,s,t,o,i=1e4)=>{s=s?{...s}:{},s.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const l in s){const u=encodeURIComponent(l),y=encodeURIComponent(s[l]);r.push(`${u}=${y}`)}const c=r.join("&"),a=await B(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...t},body:c},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let f=null;a.headers.has(Z)&&(f=a.headers.get(Z));const d=await a.json();return{success:!0,data:{state:s.state,tokens:ne(d,null,o),demonstratingProofOfPossessionNonce:f}}},we=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let s=n[6],t=n[7];if(t){const o=t.split("?");o.length===2&&(t=o[0],s=o[1])}return s.startsWith("?")&&(s=s.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:s,hash:t}},on=e=>{const n=we(e);let{path:s}=n;s.endsWith("/")&&(s=s.slice(0,-1));let{hash:t}=n;return t==="#_=_"&&(t=""),t&&(s+=t),s},j=e=>{const n=we(e),{search:s}=n;return rn(s)},rn=e=>{const n={};let s,t,o;const i=e.split("&");for(t=0,o=i.length;t<o;t++)s=i[t].split("="),n[decodeURIComponent(s[0])]=decodeURIComponent(s[1]);return n};function Ae(e){return new TextEncoder().encode(e)}function Se(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function an(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,o){return String.fromCharCode(parseInt(o,16))})}function ve(e){let n="";return e.forEach(function(s){n+=String.fromCharCode(s)}),Se(n)}function Te(e){return Se(an(e))}const cn={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var ln={sign:async(e,n,s,t,o="dpop+jwt")=>{switch(e=Object.assign({},e),n.typ=o,n.alg=t.jwtHeaderAlgorithm,n.alg){case"ES256":n.jwk={kty:e.kty,crv:e.crv,x:e.x,y:e.y};break;case"RS256":n.jwk={kty:e.kty,n:e.n,e:e.e,kid:n.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:Te(JSON.stringify(n)),payload:Te(JSON.stringify(s))},r=t.importKeyAlgorithm,c=!0,a=["sign"],f=await window.crypto.subtle.importKey("jwk",e,r,c,a),d=Ae(`${i.protected}.${i.payload}`),l=t.signAlgorithm,u=await window.crypto.subtle.sign(l,f,d);return i.signature=ve(new Uint8Array(u)),`${i.protected}.${i.payload}.${i.signature}`}};const un={generate:async e=>{const n=e,s=!0,t=["sign","verify"],o=await window.crypto.subtle.generateKey(n,s,t);return await window.crypto.subtle.exportKey("jwk",o.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var dn={thumbprint:async(e,n)=>{let s;switch(e.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",e.crv).replace("X",e.x).replace("Y",e.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",e.e).replace("N",e.n);break;default:throw new Error("Unknown or not implemented JWK type")}const t=await window.crypto.subtle.digest(n,Ae(s));return ve(new Uint8Array(t))}};const fn=async e=>await un.generate(e),be=e=>async(n,s="POST",t,o={})=>{const i={jti:btoa(hn()),htm:s,htu:t,iat:Math.round(Date.now()/1e3),...o},r=await dn.thumbprint(n,e.digestAlgorithm);return await ln.sign(n,{kid:r},i,e)},hn=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let s=0,t="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(s=Math.random()*16|0),e[o]==="x"?t+=n[s]:e[o]==="y"?(s&=3,s|=8,t+=n[s]):t+=e[o];return t},_n=(e,n,s,t,o)=>(i=void 0,r=null,c=!1,a=void 0)=>{const f=r;return r={...r},(async()=>{const l=i||o.getPath();if("state"in r||(r.state=ie(16)),s(m.loginAsync_begin,{}),r)for(const u of Object.keys(r))u.endsWith(":token_request")&&delete r[u];try{const u=c?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const y=n.extras?{...n.extras,...r}:r;y.nonce||(y.nonce=ie(12));const g={nonce:y.nonce},h=await E(n,e),_=await t(n.authority,n.authority_configuration);let A;if(h)h.setLoginParams({callbackPath:l,extras:f}),await h.initAsync(_,"loginAsync",n),await h.setNonceAsync(g),h.startKeepAliveServiceWorker(),A=h;else{const T=O(e,n.storage??sessionStorage);T.setLoginParams({callbackPath:l,extras:f}),await T.setNonceAsync(g),A=T}const S={client_id:n.client_id,redirect_uri:u,scope:a,response_type:"code",...y};await sn(A,o)(_.authorizationEndpoint,S)}catch(u){throw s(m.loginAsync_error,u),u}})()},yn=e=>async(n=!1)=>{try{e.publishEvent(m.loginCallbackAsync_begin,{});const s=e.configuration,t=s.client_id,o=n?s.silent_redirect_uri:s.redirect_uri,i=s.authority,r=s.token_request_timeout,c=await e.initAsync(i,s.authority_configuration),a=e.location.getCurrentHref(),d=j(a).session_state,l=await E(s,e.configurationName);let u,y,g,h;if(l)await l.initAsync(c,"loginCallbackAsync",s),await l.setSessionStateAsync(d),y=await l.getNonceAsync(),g=l.getLoginParams(),h=await l.getStateAsync(),l.startKeepAliveServiceWorker(),u=l;else{const v=O(e.configurationName,s.storage??sessionStorage);await v.setSessionStateAsync(d),y=await v.getNonceAsync(),g=v.getLoginParams(),h=await v.getStateAsync(),u=v}const _=j(a);if(_.error||_.error_description)throw new Error(`Error from OIDC server: ${_.error} - ${_.error_description}`);if(_.iss&&_.iss!==c.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${c.issuer}, received: ${_.iss})`);if(_.state&&_.state!==h)throw new Error(`State not valid (expected: ${h}, received: ${_.state})`);const A={code:_.code,grant_type:"authorization_code",client_id:s.client_id,redirect_uri:o},S={};if(s.token_request_extras)for(const[v,W]of Object.entries(s.token_request_extras))S[v]=W;if(g&&g.extras)for(const[v,W]of Object.entries(g.extras))v.endsWith(":token_request")&&(S[v.replace(":token_request","")]=W);const T=c.tokenEndpoint,x={};if(s.demonstrating_proof_of_possession){const v=await fn(s.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);l?await l.setDemonstratingProofOfPossessionJwkAsync(v):await O(e.configurationName,s.storage).setDemonstratingProofOfPossessionJwkAsync(v),x.DPoP=await be(s.demonstrating_proof_of_possession_configuration)(v,"POST",T)}const p=await tn(u)(T,{...A,...S},x,e.configuration.token_renew_mode,r);if(!p.success)throw new Error("Token request failed");let k;const w=p.data.tokens,I=p.data.demonstratingProofOfPossessionNonce;if(p.data.state!==S.state)throw new Error("state is not valid");const{isValid:P,reason:F}=ue(w,y.nonce,c);if(!P)throw new Error(`Tokens are not OpenID valid, reason: ${F}`);if(l){if(w.refreshToken&&!w.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(I&&w.accessToken&&w.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(l)await l.initAsync(o,"syncTokensAsync",s),k=l.getLoginParams(),I&&await l.setDemonstratingProofOfPossessionNonce(I);else{const v=O(e.configurationName,s.storage);k=v.getLoginParams(),I&&await v.setDemonstratingProofOfPossessionNonce(I)}return await e.startCheckSessionAsync(c.checkSessionIframe,t,d,n),e.publishEvent(m.loginCallbackAsync_end,{}),{tokens:w,state:"request.state",callbackPath:k.callbackPath}}catch(s){throw console.error(s),e.publishEvent(m.loginCallbackAsync_error,s),s}},Pe={access_token:"access_token",refresh_token:"refresh_token"},gn=e=>async n=>{M.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const s=await E(e.configuration,e.configurationName);s?await s.clearAsync(n):await O(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},kn=(e,n,s,t,o)=>async(i=void 0,r=null)=>{const c=e.configuration,a=await e.initAsync(c.authority,c.authority_configuration);i&&typeof i!="string"&&(i=void 0,t.warn("callbackPathOrUrl path is not a string"));const f=i??o.getPath();let d=!1;i&&(d=i.includes("https://")||i.includes("http://"));const l=d?i:o.getOrigin()+f,u=e.tokens?e.tokens.idToken:"";try{const g=a.revocationEndpoint;if(g){const h=[],_=e.tokens?e.tokens.accessToken:null;if(_&&c.logout_tokens_to_invalidate.includes(Pe.access_token)){const S=pe(s)(g,_,re.access_token,c.client_id);h.push(S)}const A=e.tokens?e.tokens.refreshToken:null;if(A&&c.logout_tokens_to_invalidate.includes(Pe.refresh_token)){const S=pe(s)(g,A,re.refresh_token,c.client_id);h.push(S)}h.length>0&&await Promise.all(h)}}catch(g){t.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),t.warn(g)}const y=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;for(const[g,h]of Object.entries(n))h!==e?await e.logoutSameTabAsync(e.configuration.client_id,y):e.publishEvent(m.logout_from_same_tab,{});if(await e.destroyAsync("LOGGED_OUT"),a.endSessionEndpoint){r||(r={id_token_hint:u},i!==null&&(r.post_logout_redirect_uri=l));let g="";if(r)for(const[h,_]of Object.entries(r))g===""?g+="?":g+="&",g+=`${h}=${encodeURIComponent(_)}`;o.open(`${a.endSessionEndpoint}${g}`)}else o.reload()},mn=e=>async(n=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;for(;e.tokens&&!se(e.tokens);)await $({milliseconds:200});if(!e.tokens)return null;const s=e.tokens.accessToken;if(!s)return null;const t=e.configuration,i=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,c=await(async a=>{const f=await fetch(i,{headers:{authorization:`Bearer ${a}`}});return f.status!==200?null:f.json()})(s);return e.userInfo=c,c};class H{open(n){window.open(n,"_self")}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const pn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),wn=e=>{const n=e.appVersion,s=e.userAgent,t="-";let o=t;const i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const c in i){const a=i[c];if(a.r.test(s)){o=a.s;break}}let r=t;switch(/Windows/.test(o)&&(r=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":r=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];break;case"iOS":{const c=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);c!=null&&c.length>2&&(r=c[1]+"."+c[2]+"."+(parseInt(c[3])|0));break}}return{os:o,osVersion:r}};function An(){const e=navigator.userAgent;let n,s=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(s[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(s[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let t=n[1];if(!t){const o=e.split(n[0]+"/");o.length>1&&(t=o[1])}return{name:"opera",version:t}}return s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&s.splice(1,1,n[1]),{name:s[0].toLowerCase(),version:s[1]}}const Sn=()=>{const{name:e,version:n}=An();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const s=wn(navigator);return!pn(s)},vn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(m.tryKeepExistingSessionAsync_begin,{});try{const s=e.configuration,t=await e.initAsync(s.authority,s.authority_configuration);if(n=await E(s,e.configurationName),n){const{tokens:o}=await n.initAsync(t,"tryKeepExistingSessionAsync",s);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=J(e,e.tokens.expiresAt,i.extras);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,r),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{s.service_worker_relative_url&&e.publishEvent(m.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=O(e.configurationName,s.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=X(i,null,s.token_renew_mode);const r=o.getLoginParams();e.timeoutId=J(e,e.tokens.expiresAt,r.extras);const c=await o.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,c),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(s){return console.error(s),n&&await n.clearAsync(),e.publishEvent(m.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Oe=()=>fetch;class ae{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const L={},Tn=(e,n=new H)=>(s,t="default")=>(L[t]||(L[t]=new U(s,t,e,n)),L[t]),bn=async e=>{const{parsedTokens:n,callbackPath:s}=await e.loginCallbackAsync();return e.timeoutId=J(e,n.expiresAt),{callbackPath:s}},Pn=e=>Math.floor(Math.random()*e),ce=class q{constructor(n,s="default",t,o=new H){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let i=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(i=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let r=n.refresh_time_before_tokens_expiration_in_second??120;r>60&&(r=r-Math.floor(Math.random()*40)),this.location=o??new H;const c=n.service_worker_update_require_callback??Re(this.location);this.configuration={...n,silent_login_uri:i,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:r,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??Y.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:c,service_worker_activate:n.service_worker_activate??Sn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??cn},this.getFetch=t??Oe,this.configurationName=s,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.synchroniseTokensAsync.bind(this),this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const s=Pn(9999999999999).toString();return this.events.push({id:s,func:n}),s}removeEventSubscription(n){const s=this.events.filter(t=>t.id!==n);this.events=s}publishEvent(n,s){this.events.forEach(t=>{t.func(n,s)})}static get(n="default"){const s=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(L,n)&&s)throw Error(`OIDC library does seem initialized.
1
+ (function(C,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(C=typeof globalThis<"u"?globalThis:C||self,G(C["oidc-client"]={}))})(this,function(C){"use strict";const D=console;class Ie{constructor(n,s,t,o=2e3,i=!0){this._callback=n,this._client_id=s,this._url=t,this._interval=o||2e3,this._stopOnError=i;const r=t.indexOf("/",t.indexOf("//")+2);this._frame_origin=t.substr(0,r),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=t}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(D.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(D.debug(n),D.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):D.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){D.debug("CheckSessionIFrame.start :"+n),this.stop();const s=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};s(),this._timer=window.setInterval(s,this._interval)}stop(){this._timer&&(D.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const m={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error"},O=(e,n=sessionStorage)=>{const s=p=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:p}),Promise.resolve()),t=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const p=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:p.tokens,status:p.status})},o=p=>{n[`oidc.${e}`]=JSON.stringify({tokens:p})},i=async p=>{n[`oidc.session_state.${e}`]=p},r=async()=>n[`oidc.session_state.${e}`],c=p=>{n[`oidc.nonce.${e}`]=p.nonce},a=p=>{n[`oidc.jwk.${e}`]=JSON.stringify(p)},f=()=>JSON.parse(n[`oidc.jwk.${e}`]),d=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async p=>{n[`oidc.dpop_nonce.${e}`]=p},u=()=>n[`oidc.dpop_nonce.${e}`],y=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let g={};return{clearAsync:s,initAsync:t,setTokens:o,getTokens:y,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:c,getNonceAsync:d,setLoginParams:p=>{g[e]=p,n[`oidc.login.${e}`]=JSON.stringify(p)},getLoginParams:()=>{const p=n[`oidc.login.${e}`];return p?(g[e]||(g[e]=JSON.parse(p)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async p=>{n[`oidc.state.${e}`]=p},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async p=>{n[`oidc.code_verifier.${e}`]=p},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:u,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:f}},Ce=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),Ne=e=>JSON.parse(Ce(e.replace(/-/g,"+").replace(/_/g,"/"))),le=e=>{try{return e&&xe(e,".")===2?Ne(e.split(".")[1]):null}catch(n){console.warn(n)}return null},xe=(e,n)=>e.split(n).length-1,Y={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,s){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:s&&s.iat?s.iat:new Date().getTime()/1e3;return e.issuedAt}const X=(e,n=null,s)=>{if(!e)return null;let t;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?t=e.accessTokenPayload:t=le(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:le(i),c=r&&r.exp?r.exp:Number.MAX_VALUE,a=t&&t.exp?t.exp:e.issuedAt+o;e.issuedAt=Le(e,t,r);let f;e.expiresAt?f=e.expiresAt:s===Y.access_token_invalid?f=a:s===Y.id_token_invalid?f=c:f=c<a?c:a;const d={...e,idTokenPayload:r,accessTokenPayload:t,expiresAt:f,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...d,refreshToken:l}}return d},ne=(e,n,s)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const t={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(t.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(t.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(t.idTokenPayload=e.idTokenPayload),X(t,n,s)},V=(e,n)=>{const s=new Date().getTime()/1e3,t=n-s;return Math.round(t-e)},se=e=>e?V(0,e.expiresAt)>0:!1,We=async(e,n=200,s=50)=>{let t=s;if(!e.tokens)return null;for(;!se(e.tokens)&&t>0;)await $({milliseconds:n}),t=t-1;return{isTokensValid:se(e.tokens),tokens:e.tokens,numberWaited:t-s}},ue=(e,n,s)=>{if(e.idTokenPayload){const t=e.idTokenPayload;if(s.issuer!==t.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${s.issuer} !== (idTokenPayload issuer) ${t.iss}`};const o=new Date().getTime()/1e3;if(t.exp&&t.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${t.exp} < (currentTimeUnixSecond) ${o}`};const i=60*60*24*7;if(t.iat&&t.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${t.iat+i} < (currentTimeUnixSecond) ${o}`};if(t.nonce&&t.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},M=function(){const e=function(){let a,f;const d=(function(){const u={},y={setTimeout:function(h,_,A){u[_]=setTimeout(function(){h.postMessage(_),u[_]=null},A)},setInterval:function(h,_,A){u[_]=setInterval(function(){h.postMessage(_)},A)},clearTimeout:function(h,_){clearTimeout(u[_]),u[_]=null},clearInterval:function(h,_){clearInterval(u[_]),u[_]=null}};function g(h,_){const A=_.data[0],S=_.data[1],T=_.data[2];y[A]&&y[A](h,S,T)}this.onmessage=function(h){g(self,h)},this.onconnect=function(h){const _=h.ports[0];_.onmessage=function(A){g(_,A)}}}).toString();try{const u=new Blob(["(",d,")()"],{type:"application/javascript"});f=URL.createObjectURL(u)}catch{return null}const l=typeof process>"u";try{if(SharedWorker)return a=new SharedWorker(f),a.port}catch{l&&console.warn("SharedWorker not available")}try{if(Worker)return a=new Worker(f),a}catch{l&&console.warn("Worker not available")}return null}();if(!e){const a=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(a),clearTimeout:clearTimeout.bind(a),setInterval:setInterval.bind(a),clearInterval:clearInterval.bind(a)}}const n=function(){let a=0;return function(){return a++,a}}(),s={},t={};e.onmessage=function(a){const f=a.data,d=s[f];if(d){d(),s[f]=null;return}const l=t[f];l&&l()};function o(a,f){const d=n();return e.postMessage(["setTimeout",d,f]),s[d]=a,d}function i(a){e.postMessage(["clearTimeout",a]),s[a]=null}function r(a,f){const d=n();return e.postMessage(["setInterval",d,f]),t[d]=a,d}function c(a){e.postMessage(["clearInterval",a]),t[a]=null}return{setTimeout:o,clearTimeout:i,setInterval:r,clearInterval:c}}(),de="7.15.3";let fe=null,z;const $=({milliseconds:e})=>new Promise(n=>M.setTimeout(n,e)),he=(e="/")=>{try{z=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:z.signal}).catch(t=>{console.log(t)}),$({milliseconds:150*1e3}).then(he)}catch(n){console.log(n)}},De=()=>{z&&z.abort()},$e=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),Re=e=>async(n,s)=>{s(),await n.update();const t=await n.unregister();console.log(`Service worker unregistering ${t}`),await $({milliseconds:2e3}),e.reload()},b=e=>n=>new Promise(function(s,t){const o=new MessageChannel;o.port1.onmessage=function(i){i.data&&i.data.error?t(i.data.error):s(i.data)},e.active.postMessage(n,[o.port2])}),E=async(e,n)=>{const s=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!s||e.service_worker_activate()===!1)return null;let t=null;e.register?t=await e.service_worker_register(s):t=await navigator.serviceWorker.register(s);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await b(t)({type:"claim"})}catch{return null}const o=async k=>b(t)({type:"clear",data:{status:k},configurationName:n}),i=async(k,w,I)=>{const P=await b(t)({type:"init",data:{oidcServerConfiguration:k,where:w,oidcConfiguration:{token_renew_mode:I.token_renew_mode,service_worker_convert_all_requests_to_cors:I.service_worker_convert_all_requests_to_cors}},configurationName:n}),F=P.version;return F!==de&&(console.warn(`Service worker ${F} version mismatch with js client version ${de}, unregistering and reloading`),await I.service_worker_update_require_callback(t,De)),{tokens:ne(P.tokens,null,I.token_renew_mode),status:P.status}},r=(k="/")=>{fe==null&&(fe="not_null",he(k))},c=k=>b(t)({type:"setSessionState",data:{sessionState:k},configurationName:n}),a=async()=>(await b(t)({type:"getSessionState",data:null,configurationName:n})).sessionState,f=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,b(t)({type:"setNonce",data:{nonce:k},configurationName:n})),d=async()=>{let w=(await b(t)({type:"getNonce",data:null,configurationName:n})).nonce;return w||(w=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:w}};let l={};return{clearAsync:o,initAsync:i,startKeepAliveServiceWorker:()=>r(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>$e(e.service_worker_keep_alive_path),setSessionStateAsync:c,getSessionStateAsync:a,setNonceAsync:f,getNonceAsync:d,setLoginParams:k=>{l[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},getLoginParams:()=>{const k=localStorage[`oidc.login.${n}`];return l[n]||(l[n]=JSON.parse(k)),l[n]},getStateAsync:async()=>{let w=(await b(t)({type:"getState",data:null,configurationName:n})).state;return w||(w=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),w},setStateAsync:async k=>(sessionStorage[`oidc.state.${n}`]=k,b(t)({type:"setState",data:{state:k},configurationName:n})),getCodeVerifierAsync:async()=>{let w=(await b(t)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return w||(w=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),w},setCodeVerifierAsync:async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,b(t)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n})),setDemonstratingProofOfPossessionNonce:async k=>{await b(t)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await b(t)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async k=>{const w=JSON.stringify(k);b(t)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:w},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const k=await b(t)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null}}};async function _e(e,n,s){const t=c=>{e.tokens=c},{tokens:o,status:i}=await e.synchroniseTokensAsync(0,n,s,t);return await E(e.configuration,e.configurationName)||await O(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(i),null)}const Ke=async(e,n)=>{const s=await E(n,e.configurationName);if(s){const t=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await s.initAsync(t,"tryKeepExistingSessionAsync",n);return o}else{const t=O(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await t.initAsync();return o=X(o,e.tokens,n.token_renew_mode),o}};async function ye(e,n=!1,s=null){const t=e.configuration,o=`${t.client_id}_${e.configurationName}_${t.authority}`;let i;const r=await E(e.configuration,e.configurationName);return(t==null?void 0:t.storage)===(window==null?void 0:window.sessionStorage)&&!r?i=await _e(e,n,s):i=await navigator.locks.request(o,{ifAvailable:!0},async c=>c?await _e(e,n,s):(e.publishEvent(U.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await Ke(e,t))),i?(e.timeoutId&&(e.timeoutId=J(e,e.tokens.expiresAt,s)),e.tokens):null}const J=(e,n,s=null)=>{const t=e.configuration.refresh_time_before_tokens_expiration_in_second;return M.setTimeout(async()=>{const i={timeLeft:V(t,n)};e.publishEvent(U.eventNames.token_timer,i),await ye(e,!1,s)},1e3)},R={SESSION_LOST:"SESSION_LOST",NOT_CONNECTED:"NOT_CONNECTED",TOKENS_VALID:"TOKENS_VALID",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},Ue=e=>async(n,s,t,o=!1)=>{const i={nonce:null};if(!t)return{tokens:null,status:"NOT_CONNECTED",nonce:i};let r=i;const c=await e.initAsync(n.authority,n.authority_configuration),a=await E(n,s);if(a){const{status:l,tokens:u}=await a.initAsync(c,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};if(l==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(!l||!u)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:i};if(u.issuedAt!==t.issuedAt){const g=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",h=await a.getNonceAsync();return{tokens:u,status:g,nonce:h}}r=await a.getNonceAsync()}else{const l=O(s,n.storage??sessionStorage);let{tokens:u,status:y}=await l.initAsync();if(u&&(u=X(u,e.tokens,n.token_renew_mode)),u){if(y==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(u.issuedAt!==t.issuedAt){const h=V(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",_=await l.getNonceAsync();return{tokens:u,status:h,nonce:_}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};r=await l.getNonceAsync()}const d=V(n.refresh_time_before_tokens_expiration_in_second,t.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:t,status:"FORCE_REFRESH",nonce:r}:{tokens:t,status:d,nonce:r}},te=(e,n,s)=>(t=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{s(m.silentLoginAsync_begin,{});let r="";if(o&&(t==null&&(t={}),t.state=o),i&&(t==null&&(t={}),t.scope=i),t!=null)for(const[l,u]of Object.entries(t))r===""?r=`?${encodeURIComponent(l)}=${encodeURIComponent(u)}`:r+=`&${encodeURIComponent(l)}=${encodeURIComponent(u)}`;const c=n.silent_login_uri+r,a=c.indexOf("/",c.indexOf("//")+2),f=c.substr(0,a),d=document.createElement("iframe");return d.width="0px",d.height="0px",d.id=`${e}_oidc_iframe`,d.setAttribute("src",c),document.body.appendChild(d),new Promise((l,u)=>{try{let y=!1;window.onmessage=h=>{if(h.origin===f&&h.source===d.contentWindow){const _=`${e}_oidc_tokens:`,A=`${e}_oidc_error:`,S=h.data;if(S&&typeof S=="string"&&!y){if(S.startsWith(_)){const T=JSON.parse(h.data.replace(_,""));s(m.silentLoginAsync_end,{}),d.remove(),y=!0,l(T)}else if(S.startsWith(A)){const T=JSON.parse(h.data.replace(A,""));s(m.silentLoginAsync_error,T),d.remove(),y=!0,u(new Error("oidc_"+T.error))}}}};const g=n.silent_login_timeout;setTimeout(()=>{y||(s(m.silentLoginAsync_error,{reason:"timeout"}),d.remove(),y=!0,u(new Error("timeout")))},g)}catch(y){d.remove(),s(m.silentLoginAsync_error,y),u(y)}})}catch(r){throw s(m.silentLoginAsync_error,r),r}},Fe=(e,n,s,t,o)=>(i=null,r=void 0)=>{i={...i};const c=(f,d,l)=>te(n,s,t.bind(o))(f,d,l);return(async()=>{o.timeoutId&&M.clearTimeout(o.timeoutId);let f;i&&"state"in i&&(f=i.state,delete i.state);try{const d=s.extras?{...s.extras,...i}:i,l=await c({...d,prompt:"none"},f,r);if(l)return o.tokens=l.tokens,t(m.token_aquired,{}),o.timeoutId=J(o,o.tokens.expiresAt,i),{}}catch(d){return d}})()},Ve=(e,n,s)=>(t,o,i,r=!1)=>{const c=(a,f=void 0,d=void 0)=>te(e.configurationName,s,e.publishEvent.bind(e))(a,f,d);return new Promise((a,f)=>{if(s.silent_login_uri&&s.silent_redirect_uri&&s.monitor_session&&t&&i&&!r){const d=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const u=l.idToken,y=l.idTokenPayload;return c({prompt:"none",id_token_hint:u,scope:s.scope||"openid"}).then(g=>{const h=g.tokens.idTokenPayload;if(y.sub===h.sub){const _=g.sessionState;e.checkSessionIFrame.start(g.sessionState),y.sid===h.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",_):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",_)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",h.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[h,_]of Object.entries(n))await _.logoutOtherTabAsync(s.client_id,y.sub)})};e.checkSessionIFrame=new Ie(d,o,t),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),a(e.checkSessionIFrame)}).catch(l=>{f(l)})}else a(null)})};for(var Me=He,N=[],ge="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Q=0,Je=ge.length;Q<Je;++Q)N[Q]=ge[Q];function Be(e){return N[e>>18&63]+N[e>>12&63]+N[e>>6&63]+N[e&63]}function je(e,n,s){for(var t,o=[],i=n;i<s;i+=3)t=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(e[i+2]&255),o.push(Be(t));return o.join("")}function He(e){for(var n,s=e.length,t=s%3,o=[],i=16383,r=0,c=s-t;r<c;r+=i)o.push(je(e,r,r+i>c?c:r+i));return t===1?(n=e[s-1],o.push(N[n>>2]+N[n<<4&63]+"==")):t===2&&(n=(e[s-2]<<8)+e[s-1],o.push(N[n>>10]+N[n>>4&63]+N[n<<2&63]+"=")),o.join("")}const ke=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let s=0;s<e.byteLength;s+=1){const t=e[s]%oe.length;n.push(oe[t])}return n.join("")},Ge=e=>Me(new Uint8Array(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),ie=e=>{const n=new Uint8Array(e),{hasCrypto:s}=ke();if(s)window.crypto.getRandomValues(n);else for(let t=0;t<e;t+=1)n[t]=Math.random()*oe.length|0;return qe(n)};function Ye(e){const n=new ArrayBuffer(e.length),s=new Uint8Array(n);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s}function me(e){return new Promise((n,s)=>{crypto.subtle.digest("SHA-256",Ye(e)).then(t=>n(Ge(new Uint8Array(t))),t=>s(t))})}const Xe=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=ke();return n?me(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},K={},ze=(e,n=window.sessionStorage,s)=>{if(!K[e]&&n){const o=n.getItem(e);o&&(K[e]=JSON.parse(o))}const t=1e3*s;return K[e]&&K[e].timestamp+t>Date.now()?K[e].result:null},Qe=(e,n,s=window.sessionStorage)=>{const t=Date.now();K[e]={result:n,timestamp:t},s&&s.setItem(e,JSON.stringify({result:n,timestamp:t}))},Ze=60*60,en=e=>async(n,s=Ze,t=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,c=ze(r,t,s);if(c)return new ae(c);const a=await B(e)(i,{},o);if(a.status!==200)return null;const f=await a.json();return Qe(r,f,t),new ae(f)},B=e=>async(n,s={},t=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),t),i=await e(n,{...s,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await B(e)(n,s,t,o+1);throw r}else throw console.error(r.message),r}return i},re={refresh_token:"refresh_token",access_token:"access_token"},pe=e=>async(n,s,t=re.refresh_token,o,i=1e4)=>{const r={token:s,token_type_hint:t,client_id:o},c=[];for(const d in r){const l=encodeURIComponent(d),u=encodeURIComponent(r[d]);c.push(`${l}=${u}`)}const a=c.join("&");return(await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:a},i)).status!==200?{success:!1}:{success:!0}},nn=e=>async(n,s,t,o,i={},r,c=1e4)=>{for(const[y,g]of Object.entries(t))s[y]===void 0&&(s[y]=g);const a=[];for(const y in s){const g=encodeURIComponent(y),h=encodeURIComponent(s[y]);a.push(`${g}=${h}`)}const f=a.join("&"),d=await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:f},c);if(d.status!==200)return{success:!1,status:d.status,demonstratingProofOfPossessionNonce:null};const l=await d.json();let u=null;return d.headers.has(Z)&&(u=d.headers.get(Z)),{success:!0,data:ne(l,o,r),demonstratingProofOfPossessionNonce:u}},sn=(e,n)=>async(s,t)=>{t=t?{...t}:{};const o=ie(128),i=await Xe(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(t.state),t.code_challenge=i,t.code_challenge_method="S256";let r="";if(t)for(const[c,a]of Object.entries(t))r===""?r+="?":r+="&",r+=`${c}=${encodeURIComponent(a)}`;n.open(`${s}${r}`)},Z="DPoP-Nonce",tn=e=>async(n,s,t,o,i=1e4)=>{s=s?{...s}:{},s.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const l in s){const u=encodeURIComponent(l),y=encodeURIComponent(s[l]);r.push(`${u}=${y}`)}const c=r.join("&"),a=await B(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...t},body:c},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let f=null;a.headers.has(Z)&&(f=a.headers.get(Z));const d=await a.json();return{success:!0,data:{state:s.state,tokens:ne(d,null,o),demonstratingProofOfPossessionNonce:f}}},we=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let s=n[6],t=n[7];if(t){const o=t.split("?");o.length===2&&(t=o[0],s=o[1])}return s.startsWith("?")&&(s=s.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:s,hash:t}},on=e=>{const n=we(e);let{path:s}=n;s.endsWith("/")&&(s=s.slice(0,-1));let{hash:t}=n;return t==="#_=_"&&(t=""),t&&(s+=t),s},j=e=>{const n=we(e),{search:s}=n;return rn(s)},rn=e=>{const n={};let s,t,o;const i=e.split("&");for(t=0,o=i.length;t<o;t++)s=i[t].split("="),n[decodeURIComponent(s[0])]=decodeURIComponent(s[1]);return n};function Ae(e){return new TextEncoder().encode(e)}function Se(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function an(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,o){return String.fromCharCode(parseInt(o,16))})}function ve(e){let n="";return e.forEach(function(s){n+=String.fromCharCode(s)}),Se(n)}function Te(e){return Se(an(e))}const cn={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var ln={sign:async(e,n,s,t,o="dpop+jwt")=>{switch(e=Object.assign({},e),n.typ=o,n.alg=t.jwtHeaderAlgorithm,n.alg){case"ES256":n.jwk={kty:e.kty,crv:e.crv,x:e.x,y:e.y};break;case"RS256":n.jwk={kty:e.kty,n:e.n,e:e.e,kid:n.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:Te(JSON.stringify(n)),payload:Te(JSON.stringify(s))},r=t.importKeyAlgorithm,c=!0,a=["sign"],f=await window.crypto.subtle.importKey("jwk",e,r,c,a),d=Ae(`${i.protected}.${i.payload}`),l=t.signAlgorithm,u=await window.crypto.subtle.sign(l,f,d);return i.signature=ve(new Uint8Array(u)),`${i.protected}.${i.payload}.${i.signature}`}};const un={generate:async e=>{const n=e,s=!0,t=["sign","verify"],o=await window.crypto.subtle.generateKey(n,s,t);return await window.crypto.subtle.exportKey("jwk",o.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var dn={thumbprint:async(e,n)=>{let s;switch(e.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",e.crv).replace("X",e.x).replace("Y",e.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",e.e).replace("N",e.n);break;default:throw new Error("Unknown or not implemented JWK type")}const t=await window.crypto.subtle.digest(n,Ae(s));return ve(new Uint8Array(t))}};const fn=async e=>await un.generate(e),be=e=>async(n,s="POST",t,o={})=>{const i={jti:btoa(hn()),htm:s,htu:t,iat:Math.round(Date.now()/1e3),...o},r=await dn.thumbprint(n,e.digestAlgorithm);return await ln.sign(n,{kid:r},i,e)},hn=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let s=0,t="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(s=Math.random()*16|0),e[o]==="x"?t+=n[s]:e[o]==="y"?(s&=3,s|=8,t+=n[s]):t+=e[o];return t},_n=(e,n,s,t,o)=>(i=void 0,r=null,c=!1,a=void 0)=>{const f=r;return r={...r},(async()=>{const l=i||o.getPath();if("state"in r||(r.state=ie(16)),s(m.loginAsync_begin,{}),r)for(const u of Object.keys(r))u.endsWith(":token_request")&&delete r[u];try{const u=c?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const y=n.extras?{...n.extras,...r}:r;y.nonce||(y.nonce=ie(12));const g={nonce:y.nonce},h=await E(n,e),_=await t(n.authority,n.authority_configuration);let A;if(h)h.setLoginParams({callbackPath:l,extras:f}),await h.initAsync(_,"loginAsync",n),await h.setNonceAsync(g),h.startKeepAliveServiceWorker(),A=h;else{const T=O(e,n.storage??sessionStorage);T.setLoginParams({callbackPath:l,extras:f}),await T.setNonceAsync(g),A=T}const S={client_id:n.client_id,redirect_uri:u,scope:a,response_type:"code",...y};await sn(A,o)(_.authorizationEndpoint,S)}catch(u){throw s(m.loginAsync_error,u),u}})()},yn=e=>async(n=!1)=>{try{e.publishEvent(m.loginCallbackAsync_begin,{});const s=e.configuration,t=s.client_id,o=n?s.silent_redirect_uri:s.redirect_uri,i=s.authority,r=s.token_request_timeout,c=await e.initAsync(i,s.authority_configuration),a=e.location.getCurrentHref(),d=j(a).session_state,l=await E(s,e.configurationName);let u,y,g,h;if(l)await l.initAsync(c,"loginCallbackAsync",s),await l.setSessionStateAsync(d),y=await l.getNonceAsync(),g=l.getLoginParams(),h=await l.getStateAsync(),l.startKeepAliveServiceWorker(),u=l;else{const v=O(e.configurationName,s.storage??sessionStorage);await v.setSessionStateAsync(d),y=await v.getNonceAsync(),g=v.getLoginParams(),h=await v.getStateAsync(),u=v}const _=j(a);if(_.error||_.error_description)throw new Error(`Error from OIDC server: ${_.error} - ${_.error_description}`);if(_.iss&&_.iss!==c.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${c.issuer}, received: ${_.iss})`);if(_.state&&_.state!==h)throw new Error(`State not valid (expected: ${h}, received: ${_.state})`);const A={code:_.code,grant_type:"authorization_code",client_id:s.client_id,redirect_uri:o},S={};if(s.token_request_extras)for(const[v,W]of Object.entries(s.token_request_extras))S[v]=W;if(g&&g.extras)for(const[v,W]of Object.entries(g.extras))v.endsWith(":token_request")&&(S[v.replace(":token_request","")]=W);const T=c.tokenEndpoint,x={};if(s.demonstrating_proof_of_possession){const v=await fn(s.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);l?await l.setDemonstratingProofOfPossessionJwkAsync(v):await O(e.configurationName,s.storage).setDemonstratingProofOfPossessionJwkAsync(v),x.DPoP=await be(s.demonstrating_proof_of_possession_configuration)(v,"POST",T)}const p=await tn(u)(T,{...A,...S},x,e.configuration.token_renew_mode,r);if(!p.success)throw new Error("Token request failed");let k;const w=p.data.tokens,I=p.data.demonstratingProofOfPossessionNonce;if(p.data.state!==S.state)throw new Error("state is not valid");const{isValid:P,reason:F}=ue(w,y.nonce,c);if(!P)throw new Error(`Tokens are not OpenID valid, reason: ${F}`);if(l){if(w.refreshToken&&!w.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(I&&w.accessToken&&w.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(l)await l.initAsync(o,"syncTokensAsync",s),k=l.getLoginParams(),I&&await l.setDemonstratingProofOfPossessionNonce(I);else{const v=O(e.configurationName,s.storage);k=v.getLoginParams(),I&&await v.setDemonstratingProofOfPossessionNonce(I)}return await e.startCheckSessionAsync(c.checkSessionIframe,t,d,n),e.publishEvent(m.loginCallbackAsync_end,{}),{tokens:w,state:"request.state",callbackPath:k.callbackPath}}catch(s){throw console.error(s),e.publishEvent(m.loginCallbackAsync_error,s),s}},Pe={access_token:"access_token",refresh_token:"refresh_token"},gn=e=>async n=>{M.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const s=await E(e.configuration,e.configurationName);s?await s.clearAsync(n):await O(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},kn=(e,n,s,t,o)=>async(i=void 0,r=null)=>{const c=e.configuration,a=await e.initAsync(c.authority,c.authority_configuration);i&&typeof i!="string"&&(i=void 0,t.warn("callbackPathOrUrl path is not a string"));const f=i??o.getPath();let d=!1;i&&(d=i.includes("https://")||i.includes("http://"));const l=d?i:o.getOrigin()+f,u=e.tokens?e.tokens.idToken:"";try{const g=a.revocationEndpoint;if(g){const h=[],_=e.tokens?e.tokens.accessToken:null;if(_&&c.logout_tokens_to_invalidate.includes(Pe.access_token)){const S=pe(s)(g,_,re.access_token,c.client_id);h.push(S)}const A=e.tokens?e.tokens.refreshToken:null;if(A&&c.logout_tokens_to_invalidate.includes(Pe.refresh_token)){const S=pe(s)(g,A,re.refresh_token,c.client_id);h.push(S)}h.length>0&&await Promise.all(h)}}catch(g){t.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),t.warn(g)}const y=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;for(const[g,h]of Object.entries(n))h!==e?await e.logoutSameTabAsync(e.configuration.client_id,y):e.publishEvent(m.logout_from_same_tab,{});if(await e.destroyAsync("LOGGED_OUT"),a.endSessionEndpoint){r||(r={id_token_hint:u},i!==null&&(r.post_logout_redirect_uri=l));let g="";if(r)for(const[h,_]of Object.entries(r))g===""?g+="?":g+="&",g+=`${h}=${encodeURIComponent(_)}`;o.open(`${a.endSessionEndpoint}${g}`)}else o.reload()},mn=e=>async(n=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;for(;e.tokens&&!se(e.tokens);)await $({milliseconds:200});if(!e.tokens)return null;const s=e.tokens.accessToken;if(!s)return null;const t=e.configuration,i=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,c=await(async a=>{const f=await fetch(i,{headers:{authorization:`Bearer ${a}`}});return f.status!==200?null:f.json()})(s);return e.userInfo=c,c};class H{open(n){window.open(n,"_self")}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const pn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),wn=e=>{const n=e.appVersion,s=e.userAgent,t="-";let o=t;const i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const c in i){const a=i[c];if(a.r.test(s)){o=a.s;break}}let r=t;switch(/Windows/.test(o)&&(r=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":r=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];break;case"iOS":{const c=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);c!=null&&c.length>2&&(r=c[1]+"."+c[2]+"."+(parseInt(c[3])|0));break}}return{os:o,osVersion:r}};function An(){const e=navigator.userAgent;let n,s=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(s[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(s[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let t=n[1];if(!t){const o=e.split(n[0]+"/");o.length>1&&(t=o[1])}return{name:"opera",version:t}}return s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&s.splice(1,1,n[1]),{name:s[0].toLowerCase(),version:s[1]}}const Sn=()=>{const{name:e,version:n}=An();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const s=wn(navigator);return!pn(s)},vn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(m.tryKeepExistingSessionAsync_begin,{});try{const s=e.configuration,t=await e.initAsync(s.authority,s.authority_configuration);if(n=await E(s,e.configurationName),n){const{tokens:o}=await n.initAsync(t,"tryKeepExistingSessionAsync",s);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=J(e,e.tokens.expiresAt,i.extras);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,r),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{s.service_worker_relative_url&&e.publishEvent(m.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=O(e.configurationName,s.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=X(i,null,s.token_renew_mode);const r=o.getLoginParams();e.timeoutId=J(e,e.tokens.expiresAt,r.extras);const c=await o.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,c),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(s){return console.error(s),n&&await n.clearAsync(),e.publishEvent(m.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Oe=()=>fetch;class ae{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const L={},Tn=(e,n=new H)=>(s,t="default")=>(L[t]||(L[t]=new U(s,t,e,n)),L[t]),bn=async e=>{const{parsedTokens:n,callbackPath:s}=await e.loginCallbackAsync();return e.timeoutId=J(e,n.expiresAt),{callbackPath:s}},Pn=e=>Math.floor(Math.random()*e),ce=class q{constructor(n,s="default",t,o=new H){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let i=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(i=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let r=n.refresh_time_before_tokens_expiration_in_second??120;r>60&&(r=r-Math.floor(Math.random()*40)),this.location=o??new H;const c=n.service_worker_update_require_callback??Re(this.location);this.configuration={...n,silent_login_uri:i,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:r,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??Y.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:c,service_worker_activate:n.service_worker_activate??Sn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??cn},this.getFetch=t??Oe,this.configurationName=s,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.synchroniseTokensAsync.bind(this),this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const s=Pn(9999999999999).toString();return this.events.push({id:s,func:n}),s}removeEventSubscription(n){const s=this.events.filter(t=>t.id!==n);this.events=s}publishEvent(n,s){this.events.forEach(t=>{t.func(n,s)})}static get(n="default"){const s=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(L,n)&&s)throw Error(`OIDC library does seem initialized.
2
2
  Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> compoment.`);return L[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,s=j(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:s.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,s=j(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,n.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame()}}async initAsync(n,s){if(this.initPromise!==null)return this.initPromise;const t=async()=>{if(s!=null)return new ae({authorization_endpoint:s.authorization_endpoint,end_session_endpoint:s.end_session_endpoint,revocation_endpoint:s.revocation_endpoint,token_endpoint:s.token_endpoint,userinfo_endpoint:s.userinfo_endpoint,check_session_iframe:s.check_session_iframe,issuer:s.issuer});const i=await E(this.configuration,this.configurationName)?window.localStorage:null;return await en(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??60*60,i,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=t(),this.initPromise.then(o=>(this.initPromise=null,o))}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=vn(this),this.tryKeepExistingSessionPromise.then(n=>(this.tryKeepExistingSessionPromise=null,n)))}async startCheckSessionAsync(n,s,t,o=!1){await Ve(this,L,this.configuration)(n,s,t,o)}async loginAsync(n=void 0,s=null,t=!1,o=void 0,i=!1){return this.loginPromise!==null?this.loginPromise:i?Fe(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(s,o):(this.loginPromise=_n(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,s,t,o),this.loginPromise.then(r=>(this.loginPromise=null,r)))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const s=async()=>{const t=await yn(this)(n),o=t.tokens;return this.tokens=o,await E(this.configuration,this.configurationName)||O(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(q.eventNames.token_aquired,o),{parsedTokens:o,state:t.state,callbackPath:t.callbackPath}};return this.loginCallbackPromise=s(),this.loginCallbackPromise.then(t=>(this.loginCallbackPromise=null,t))}async synchroniseTokensAsync(n=0,s=!1,t=null,o){for(;!navigator.onLine&&document.hidden;)await $({milliseconds:1e3}),this.publishEvent(m.refreshTokensAsync,{message:"wait because navigator is offline and hidden"});let i=6;for(;!navigator.onLine&&i>0;)await $({milliseconds:1e3}),i--,this.publishEvent(m.refreshTokensAsync,{message:`wait because navigator is offline try ${i}`});const c=document.hidden?n:n+1;t||(t={});const a=this.configuration,f=(l,u=null,y=null)=>te(this.configurationName,this.configuration,this.publishEvent.bind(this))(l,u,y),d=async()=>{try{let l;const u=await E(a,this.configurationName);u?l=u.getLoginParams():l=O(this.configurationName,a.storage).getLoginParams();const y=await f({...l.extras,...t,prompt:"none"});if(y)return o(y.tokens),this.publishEvent(q.eventNames.token_renewed,{}),{tokens:y.tokens,status:"LOGGED"}}catch(l){if(console.error(l),this.publishEvent(m.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:l.message}),l&&l.message&&l.message.startsWith("oidc"))return o(null),this.publishEvent(m.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}}return this.publishEvent(m.refreshTokensAsync_error,{message:"refresh token silent return"}),await this.synchroniseTokensAsync(c,s,t,o)};if(n>4)return o(null),this.publishEvent(m.refreshTokensAsync_error,{message:"refresh token"}),{tokens:null,status:"SESSION_LOST"};try{const{status:l,tokens:u,nonce:y}=await Ue(this)(a,this.configurationName,this.tokens,s);switch(l){case R.SESSION_LOST:return o(null),this.publishEvent(m.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case R.NOT_CONNECTED:return o(null),{tokens:null,status:null};case R.TOKENS_VALID:return o(u),{tokens:u,status:"LOGGED_IN"};case R.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return o(u),this.publishEvent(q.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:u,status:"LOGGED_IN"};case R.LOGOUT_FROM_ANOTHER_TAB:return o(null),this.publishEvent(m.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case R.REQUIRE_SYNC_TOKENS:return this.publishEvent(m.refreshTokensAsync_begin,{refreshToken:u.refreshToken,status:l,tryNumber:n}),await d();default:{if(this.publishEvent(m.refreshTokensAsync_begin,{refreshToken:u.refreshToken,status:l,tryNumber:n}),!u.refreshToken)return await d();const g=a.client_id,h=a.redirect_uri,_=a.authority,S={...a.token_request_extras?a.token_request_extras:{}};for(const[x,p]of Object.entries(t))x.endsWith(":token_request")&&(S[x.replace(":token_request","")]=p);return await(async()=>{const x={client_id:g,redirect_uri:h,grant_type:"refresh_token",refresh_token:u.refreshToken},p=await this.initAsync(_,a.authority_configuration),k=document.hidden?1e4:3e4*10,w=p.tokenEndpoint,I={};a.demonstrating_proof_of_possession&&(I.DPoP=await this.generateDemonstrationOfProofOfPossessionAsync(u.accessToken,w,"POST"));const P=await nn(this.getFetch())(w,x,S,u,I,a.token_renew_mode,k);if(P.success){const{isValid:F,reason:v}=ue(P.data,y.nonce,p);if(!F)return o(null),this.publishEvent(m.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${v}`}),{tokens:null,status:"SESSION_LOST"};if(o(P.data),P.demonstratingProofOfPossessionNonce){const W=await E(a,this.configurationName);W?await W.setDemonstratingProofOfPossessionNonce(P.demonstratingProofOfPossessionNonce):await O(this.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(P.demonstratingProofOfPossessionNonce)}return this.publishEvent(m.refreshTokensAsync_end,{success:P.success}),this.publishEvent(q.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:P.data,status:"LOGGED_IN"}}else return this.publishEvent(m.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:P}),await this.synchroniseTokensAsync(c,s,t,o)})()}}}catch(l){return console.error(l),this.publishEvent(m.refreshTokensAsync_silent_error,{message:"exception",exception:l.message}),this.synchroniseTokensAsync(c,s,t,o)}}async generateDemonstrationOfProofOfPossessionAsync(n,s,t){const o=this.configuration,i={ath:await me(n)},r=await E(o,this.configurationName);let c,a;if(r)c=await r.getDemonstratingProofOfPossessionNonce(),a=await r.getDemonstratingProofOfPossessionJwkAsync();else{const f=O(this.configurationName,o.storage);a=await f.getDemonstratingProofOfPossessionJwkAsync(),c=await f.getDemonstratingProofOfPossessionNonce()}return c&&(i.nonce=c),await be(o.demonstrating_proof_of_possession_configuration)(a,t,s,i)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=bn(this),this.loginCallbackWithAutoTokensRenewPromise.then(n=>(this.loginCallbackWithAutoTokensRenewPromise=null,n)))}userInfoAsync(n=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=mn(this)(n),this.userInfoPromise.then(s=>(this.userInfoPromise=null,s)))}async renewTokensAsync(n=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return M.clearTimeout(this.timeoutId),this.renewTokensPromise=ye(this,!0,n),this.renewTokensPromise.then(s=>(this.renewTokensPromise=null,s))}async destroyAsync(n){return await gn(this)(n)}async logoutSameTabAsync(n,s){this.configuration.monitor_session&&this.configuration.client_id===n&&s&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===s&&(this.publishEvent(m.logout_from_same_tab,{mmessage:"SessionMonitor",sub:s}),await this.destroyAsync("LOGGED_OUT"))}async logoutOtherTabAsync(n,s){this.configuration.monitor_session&&this.configuration.client_id===n&&s&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===s&&(this.publishEvent(m.logout_from_another_tab,{message:"SessionMonitor",sub:s}),await this.destroyAsync("LOGGED_OUT"))}async logoutAsync(n=void 0,s=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=kn(this,L,this.getFetch(),console,this.location)(n,s),this.logoutPromise.then(t=>(this.logoutPromise=null,t)))}};ce.getOrCreate=(e,n)=>(s,t="default")=>Tn(e,n)(s,t),ce.eventNames=m;let U=ce;const On=(e,n)=>async(...s)=>{var u;const[t,o,...i]=s,r=o?{...o}:{method:"GET"};let c=new Headers;r.headers&&(c=r.headers instanceof Headers?r.headers:new Headers(r.headers));const a=n,f=await a.getValidTokenAsync(),d=(u=f==null?void 0:f.tokens)==null?void 0:u.accessToken;if(c.has("Accept")||c.set("Accept","application/json"),d){if(a.configuration.demonstrating_proof_of_possession){const y=await a.generateDemonstrationOfProofOfPossessionAsync(d,t.toString(),r.method);c.set("Authorization",`PoP ${d}`),c.set("DPoP",y)}else c.set("Authorization",`Bearer ${d}`);r.credentials||(r.credentials="same-origin")}const l={...r,headers:c};return await e(t,l,...i)},ee=class Ee{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,s){this._oidc.publishEvent(n,s)}static get(n="default"){return new Ee(U.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,s=null,t=!1,o=void 0,i=!1){return this._oidc.loginAsync(n,s,t,o,i)}logoutAsync(n=void 0,s=null){return this._oidc.logoutAsync(n,s)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null){return this._oidc.renewTokensAsync(n)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,s,t){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,s,t)}async getValidTokenAsync(n=200,s=50){return We(this._oidc,n,s)}fetchWithTokens(n){return On(n,this)}async userInfoAsync(n=!1){return this._oidc.userInfoAsync(n)}};ee.getOrCreate=(e,n=new H)=>(s,t="default")=>new ee(U.getOrCreate(e,n)(s,t)),ee.eventNames=U.eventNames;let En=ee;C.OidcClient=En,C.OidcLocation=H,C.TokenRenewMode=Y,C.getFetchDefault=Oe,C.getParseQueryStringFromLocation=j,C.getPath=on,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "7.15.2";
1
+ declare const _default: "7.15.3";
2
2
  export default _default;
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/oidc-client",
3
- "version": "7.15.2",
3
+ "version": "7.15.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/AxaFrance/oidc-client.git"
21
21
  },
22
22
  "dependencies": {
23
- "@axa-fr/oidc-client-service-worker": "7.15.2"
23
+ "@axa-fr/oidc-client-service-worker": "7.15.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/dom": "^9.3.3",
@@ -66,7 +66,7 @@ export const initSession = (configurationName, storage = sessionStorage) => {
66
66
  const dataString = storage[`oidc.login.${configurationName}`];
67
67
 
68
68
  if(!dataString){
69
- console.warn(`storage[oidc.login.${configurationName}] is empty`);
69
+ console.warn(`storage[oidc.login.${configurationName}] is empty, you should have an bad OIDC or code configuration somewhere.`);
70
70
  return null;
71
71
  }
72
72
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '7.15.2';
1
+ export default '7.15.3';