@axa-fr/oidc-client 7.26.5 → 7.26.7

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/README.md CHANGED
@@ -122,6 +122,13 @@ trustedDomains.config_with_dpop = {
122
122
 
123
123
  // Setting allowMultiTabLogin to true will enable storing login-specific parameters (state, nonce, code verifier)
124
124
  // separately for each tab. This will prevent errors when logins are initiated from multiple tabs.
125
+ // IMPORTANT: When allowMultiTabLogin is true, you MUST use the OIDC fetch provided by
126
+ // oidcClient.fetchWithTokens(fetch) for API requests. The service worker embeds a tab-specific
127
+ // token placeholder in the Authorization header, which it then replaces with the real access token.
128
+ // Using a plain fetch or axios without the OIDC fetch wrapper will result in requests being sent
129
+ // without an Authorization header (401 errors), because the service worker cannot determine which
130
+ // tab's token to inject without the placeholder.
131
+ // Example with axios: configure it to use the OIDC fetch as its adapter or use the OIDC fetch directly.
125
132
  trustedDomains.config_multi_tab_login = {
126
133
  domains: ['https://demo.duendesoftware.com'],
127
134
  allowMultiTabLogin: true,
package/dist/index.js CHANGED
@@ -244,7 +244,7 @@ const ie = (e, n = null, t) => {
244
244
  setInterval: setInterval.bind(e),
245
245
  clearInterval: clearInterval.bind(e)
246
246
  };
247
- })(), X = "7.26.5";
247
+ })(), X = "7.26.7";
248
248
  let ge = null, q;
249
249
  const ae = ({ milliseconds: e }) => new Promise((n) => D.setTimeout(n, e)), Te = (e = "/") => {
250
250
  try {
@@ -890,10 +890,10 @@ const J = (e, n, t = null, s = null) => {
890
890
  const S = {};
891
891
  if (g && g.extras)
892
892
  for (const [v, h] of Object.entries(g.extras))
893
- S[v] = h;
893
+ h != null && (S[v] = h);
894
894
  if (i)
895
895
  for (const [v, h] of Object.entries(i))
896
- S[v] = h;
896
+ h != null && (S[v] = h);
897
897
  S.prompt = "none", r && (S.scope = r);
898
898
  const T = await w(S);
899
899
  return T ? T.error ? (n(null), e.publishEvent(p.refreshTokensAsync_error, {
@@ -1041,7 +1041,7 @@ const J = (e, n, t = null, s = null) => {
1041
1041
  let r = "";
1042
1042
  if (o && (s == null && (s = {}), s.state = o), i != null && (s == null && (s = {}), s.scope = i), s != null)
1043
1043
  for (const [l, d] of Object.entries(s))
1044
- r === "" ? r = `?${encodeURIComponent(l)}=${encodeURIComponent(d)}` : r += `&${encodeURIComponent(l)}=${encodeURIComponent(d)}`;
1044
+ d != null && (r === "" ? r = `?${encodeURIComponent(l)}=${encodeURIComponent(d)}` : r += `&${encodeURIComponent(l)}=${encodeURIComponent(d)}`);
1045
1045
  const a = n.silent_login_uri + r, c = a.indexOf("/", a.indexOf("//") + 2), f = a.substring(0, c), u = document.createElement("iframe");
1046
1046
  return u.width = "0px", u.height = "0px", u.id = `${e}_oidc_iframe`, u.setAttribute("src", a), u.style.display = "none", document.body.appendChild(u), new Promise((l, d) => {
1047
1047
  let _ = !1;
@@ -1,2 +1,2 @@
1
- (function(I,R){typeof exports=="object"&&typeof module<"u"?R(exports):typeof define=="function"&&define.amd?define(["exports"],R):(I=typeof globalThis<"u"?globalThis:I||self,R(I["oidc-client"]={}))})(this,(function(I){"use strict";class R{open(n){window.location.href=n}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 de=2e3,U=console;class De{constructor(n,t,s,o=de,i=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||de,this._stopOnError=i;const r=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substring(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=s}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"?(U.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(U.debug(n),U.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):U.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){U.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(U.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_acquired:"token_acquired",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",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},N=(e,n=sessionStorage)=>{const t=h=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:h}),delete n[`oidc.${e}.userInfo`],Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const h=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:h.tokens,status:h.status})},o=h=>{n[`oidc.${e}`]=JSON.stringify({tokens:h})},i=async h=>{n[`oidc.session_state.${e}`]=h},r=async()=>n[`oidc.session_state.${e}`],a=h=>{n[`oidc.nonce.${e}`]=h.nonce},c=h=>{n[`oidc.jwk.${e}`]=JSON.stringify(h)},f=()=>JSON.parse(n[`oidc.jwk.${e}`]),u=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async h=>{n[`oidc.dpop_nonce.${e}`]=h},d=()=>n[`oidc.dpop_nonce.${e}`],_=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null,w={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:_,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:a,getNonceAsync:u,setLoginParams:h=>{w[e]=h,n[`oidc.login.${e}`]=JSON.stringify(h)},getLoginParams:()=>{const h=n[`oidc.login.${e}`];return h?(w[e]||(w[e]=JSON.parse(h)),w[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 h=>{n[`oidc.state.${e}`]=h},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async h=>{n[`oidc.code_verifier.${e}`]=h},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:d,setDemonstratingProofOfPossessionJwkAsync:c,getDemonstratingProofOfPossessionJwkAsync:f}};var V=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(V||{});const Re=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),$e=e=>JSON.parse(Re(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),he=e=>{try{return e&&Ke(e,".")===2?$e(e.split(".")[1]):null}catch(n){console.warn(n)}return null},Ke=(e,n)=>e.split(n).length-1,q={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 Ue(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const Z=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=he(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:he(i),a=r&&r.exp?r.exp:Number.MAX_VALUE,c=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Ue(e,s,r);let f;e.expiresAt?f=e.expiresAt:t===q.access_token_invalid?f=c:t===q.id_token_invalid?f=a:f=a<c?a:c;const u={...e,idTokenPayload:r,accessTokenPayload:s,expiresAt:f,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...u,refreshToken:l}}return u},ee=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={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&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),Z(s,n,t)},B=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},Ve=(e,n=0)=>e?B(n,e.expiresAt)>0:!1,ge=async(e,n=200,t=50)=>{let s=t,o=await e.syncTokensInfoAsync();for(;[E.REQUIRE_SYNC_TOKENS,E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,E.TOKENS_INVALID].includes(o)&&s>0;){if(e.configuration.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await te({milliseconds:n});s=s-1,o=await e.syncTokensInfoAsync()}return{isTokensValid:Ve(e.getTokens()),tokens:e.getTokens(),numberWaited:s-t}},ye=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const i=3600*24*7;if(s.iat&&s.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+i} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},$=(function(){const e=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}})(),ne="7.26.5";let ke=null,Y;const te=({milliseconds:e})=>new Promise(n=>$.setTimeout(n,e)),me=(e="/")=>{try{Y=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Y.signal}).catch(s=>{console.log(s)}),te({milliseconds:150*1e3}).then(()=>me(e))}catch(n){console.log(n)}},se=()=>{Y&&Y.abort()},we=e=>{const n=`oidc.tabId.${e}`,t=sessionStorage.getItem(n);if(t)return t;const s=globalThis.crypto.randomUUID();return sessionStorage.setItem(n,s),s},Fe=5e3,Me=e=>navigator.serviceWorker.controller??e.active??e.waiting??e.installing??null,O=(e,n)=>t=>{const s=n?.timeoutMs??Fe;return new Promise((o,i)=>{const r=Me(e);if(!r){i(new Error("Service worker target not available (controller/active/waiting/installing missing)"));return}const a=new MessageChannel;let c=null;const f=()=>{try{c!=null&&($.clearTimeout(c),c=null),a.port1.onmessage=null,a.port1.close(),a.port2.close()}catch(u){console.error(u)}};c=$.setTimeout(()=>{f(),i(new Error(`Service worker did not respond within ${s}ms (type=${t?.type})`))},s),a.port1.onmessage=u=>{f(),u?.data?.error?i(u.data.error):o(u.data)};try{const u=t?.configurationName;r.postMessage({...t,tabId:we(u??"default")},[a.port2])}catch(u){f(),i(u)}})},Be=async e=>navigator.serviceWorker.controller?navigator.serviceWorker.controller:new Promise(n=>{let t=!1;const s=()=>{t||(t=!0,navigator.serviceWorker.removeEventListener("controllerchange",s),n(navigator.serviceWorker.controller??null))};navigator.serviceWorker.addEventListener("controllerchange",s),$.setTimeout(()=>{t||(t=!0,navigator.serviceWorker.removeEventListener("controllerchange",s),n(navigator.serviceWorker.controller??null))},e)}),C=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;const s=`${t}?v=${ne}`;let o=null;e.service_worker_register?o=await e.service_worker_register(t):o=await navigator.serviceWorker.register(s,{updateViaCache:"none"});try{await o.update()}catch(k){console.error(k)}o.addEventListener("updatefound",()=>{const k=o.installing;se(),k?.addEventListener("statechange",async()=>{if(k.state==="installed"&&navigator.serviceWorker.controller){se(),console.log("New SW waiting – SKIP_WAITING");try{await O(o,{timeoutMs:8e3})({type:"SKIP_WAITING",configurationName:n,data:null})}catch(b){console.warn("SKIP_WAITING failed",b)}}})});const i=`oidc.sw.controllerchange.reloaded.${n}`;navigator.serviceWorker.addEventListener("controllerchange",()=>{try{if(sessionStorage.getItem(i)==="1")return;sessionStorage.setItem(i,"1")}catch{}console.log("SW controller changed – reloading page"),se(),window.location.reload()});try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||(await O(o,{timeoutMs:8e3})({type:"claim",configurationName:n,data:null}),await Be(2e3))}catch(k){return console.warn(`Failed init ServiceWorker ${k?.toString?.()??String(k)}`),null}const r=async k=>O(o)({type:"clear",data:{status:k},configurationName:n}),a=async(k,b,m)=>{const D=await O(o)({type:"init",data:{oidcServerConfiguration:k,where:b,oidcConfiguration:{token_renew_mode:m.token_renew_mode,service_worker_convert_all_requests_to_cors:m.service_worker_convert_all_requests_to_cors}},configurationName:n}),G=D.version;return G!==ne&&console.warn(`Service worker ${G} version mismatch with js client version ${ne}, unregistering and reloading`),{tokens:ee(D.tokens,null,m.token_renew_mode),status:D.status}},c=(k="/")=>{ke==null&&(ke="not_null",me(k))},f=k=>O(o)({type:"setSessionState",data:{sessionState:k},configurationName:n}),u=async()=>(await O(o)({type:"getSessionState",data:null,configurationName:n})).sessionState,l=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,O(o)({type:"setNonce",data:{nonce:k},configurationName:n})),d=async(k=!0)=>{let m=(await O(o)({type:"getNonce",data:null,configurationName:n})).nonce;return m||(m=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage"),k&&(await l(m),m=(await d(!1)).nonce)),{nonce:m}},_={},w=k=>{_[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},A=()=>{const k=localStorage[`oidc.login.${n}`];return _[n]||(_[n]=JSON.parse(k)),_[n]},g=async k=>{await O(o)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},y=async()=>(await O(o)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,S=async k=>{const b=JSON.stringify(k);await O(o)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:b},configurationName:n})},T=async()=>{const k=await O(o)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null},v=async(k=!0)=>{let m=(await O(o)({type:"getState",data:null,configurationName:n})).state;return m||(m=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage"),k&&(await h(m),m=await v(!1))),m},h=async k=>(sessionStorage[`oidc.state.${n}`]=k,O(o)({type:"setState",data:{state:k},configurationName:n})),P=async(k=!0)=>{let m=(await O(o)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return m||(m=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage"),k&&(await L(m),m=await P(!1))),m},L=async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,O(o)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n}));return{clearAsync:r,initAsync:a,startKeepAliveServiceWorker:()=>c(e.service_worker_keep_alive_path),setSessionStateAsync:f,getSessionStateAsync:u,setNonceAsync:l,getNonceAsync:d,setLoginParams:w,getLoginParams:A,getStateAsync:v,setStateAsync:h,getCodeVerifierAsync:P,setCodeVerifierAsync:L,setDemonstratingProofOfPossessionNonce:g,getDemonstratingProofOfPossessionNonce:y,setDemonstratingProofOfPossessionJwkAsync:S,getDemonstratingProofOfPossessionJwkAsync:T}},F={},Je=(e,n=window.sessionStorage,t)=>{if(!F[e]&&n){const o=n.getItem(e);o&&(F[e]=JSON.parse(o))}const s=1e3*t;return F[e]&&F[e].timestamp+s>Date.now()?F[e].result:null},He=(e,n,t=window.sessionStorage)=>{const s=Date.now();F[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function pe(e){return new TextEncoder().encode(e)}function Ae(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function je(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const oe=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),Ae(n)};function Se(e){return Ae(je(e))}const Ge={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"},qe={sign:e=>async(n,t,s,o,i="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=i,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const r={protected:Se(JSON.stringify(t)),payload:Se(JSON.stringify(s))},a=o.importKeyAlgorithm,c=!0,f=["sign"],u=await e.crypto.subtle.importKey("jwk",n,a,c,f),l=pe(`${r.protected}.${r.payload}`),d=o.signAlgorithm,_=await e.crypto.subtle.sign(d,u,l);return r.signature=oe(new Uint8Array(_)),`${r.protected}.${r.payload}.${r.signature}`}},Ye={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],i=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",i.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}},Xe={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,pe(s));return oe(new Uint8Array(o))}},ze=e=>async n=>await Ye.generate(e)(n),Te=e=>n=>async(t,s="POST",o,i={})=>{const r={jti:btoa(Qe()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...i},a=await Xe.thumbprint(e)(t,n.digestAlgorithm);return await qe.sign(e)(t,{kid:a},r,n)},Qe=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},ve=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Ze=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%ie.length;n.push(ie[s])}return n.join("")},re=e=>{const n=new Uint8Array(e),{hasCrypto:t}=ve();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*ie.length|0;return Ze(n)};function en(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Ee(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",en(e)).then(s=>n(oe(new Uint8Array(s))),s=>t(s))})}const nn=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=ve();return n?Ee(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},tn=3600,sn=e=>async(n,t=tn,s=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,a=Je(r,s,t);if(a)return new _e(a);const c=await J(e)(i,{},o);if(c.status!==200)return null;const f=await c.json();return He(r,f,s),new _e(f)},J=e=>async(n,t={},s=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),s),i=await e(n,{...t,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await J(e)(n,t,s,o+1);throw r}else throw console.error(r.message),r}return i},ae={refresh_token:"refresh_token",access_token:"access_token"},Oe=e=>async(n,t,s=ae.refresh_token,o,i={},r=1e4)=>{const a={token:t,token_type_hint:s,client_id:o};for(const[l,d]of Object.entries(i))a[l]===void 0&&(a[l]=d);const c=[];for(const l in a){const d=encodeURIComponent(l),_=encodeURIComponent(a[l]);c.push(`${d}=${_}`)}const f=c.join("&");return(await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:f},r)).status!==200?{success:!1}:{success:!0}},on=e=>async(n,t,s,o,i={},r,a=1e4)=>{for(const[_,w]of Object.entries(s))t[_]===void 0&&(t[_]=w);const c=[];for(const _ in t){const w=encodeURIComponent(_),A=encodeURIComponent(t[_]);c.push(`${w}=${A}`)}const f=c.join("&"),u=await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:f},a);if(u.status!==200)return{success:!1,status:u.status,demonstratingProofOfPossessionNonce:null};const l=await u.json();let d=null;return u.headers.has(X)&&(d=u.headers.get(X)),{success:!0,status:u.status,data:ee(l,o,r),demonstratingProofOfPossessionNonce:d}},rn=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=re(128),i=await nn(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=i,s.code_challenge_method="S256";let r="";if(s)for(const[a,c]of Object.entries(s))r===""?r+="?":r+="&",r+=`${a}=${encodeURIComponent(c)}`;n.open(`${t}${r}`)},X="DPoP-Nonce",an=e=>async(n,t,s,o,i=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const l in t){const d=encodeURIComponent(l),_=encodeURIComponent(t[l]);r.push(`${d}=${_}`)}const a=r.join("&"),c=await J(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:a},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),c.status!==200)return{success:!1,status:c.status};let f=null;c.headers.has(X)&&(f=c.headers.get(X));const u=await c.json();return{success:!0,data:{state:t.state,tokens:ee(u,null,o),demonstratingProofOfPossessionNonce:f}}};async function be(e,n,t,s=null){const o=c=>{e.tokens=c},{tokens:i,status:r}=await z(e)(o,0,0,n,t,s);return await C(e.configuration,e.configurationName)||N(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?i:(await e.destroyAsync(r),null)}async function Pe(e,n=!1,t=null,s=null){const o=e.configuration,i=`${o.client_id}_${e.configurationName}_${o.authority}`;let r;const a=await C(e.configuration,e.configurationName);if(o?.storage===window?.sessionStorage&&!a||!navigator.locks)r=await be(e,n,t,s);else{let c="retry";for(;c==="retry";)c=await navigator.locks.request(i,{ifAvailable:!0},async f=>f?await be(e,n,t,s):(e.publishEvent(W.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),"retry"));r=c}return r?(e.timeoutId&&(e.timeoutId=H(e,e.tokens.expiresAt,t,s)),e.tokens):null}const H=(e,n,t=null,s=null)=>{const o=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&$.clearTimeout(e.timeoutId),$.setTimeout(async()=>{const r={timeLeft:B(o,n)};e.publishEvent(W.eventNames.token_timer,r),await Pe(e,!1,t,s)},1e3)},E={FORCE_REFRESH:"FORCE_REFRESH",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",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS",TOKENS_INVALID:"TOKENS_INVALID"},ce=e=>async(n,t,s,o=!1)=>{const i={nonce:null};if(!s)return{tokens:null,status:E.NOT_CONNECTED,nonce:i};let r=i;const a=await e.initAsync(n.authority,n.authority_configuration),c=await C(n,t);if(c){const{status:l,tokens:d}=await c.initAsync(a,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:E.LOGOUT_FROM_ANOTHER_TAB,nonce:i};if(l==="SESSIONS_LOST")return{tokens:null,status:E.SESSION_LOST,nonce:i};if(!l||!d)return{tokens:null,status:E.REQUIRE_SYNC_TOKENS,nonce:i};if(d.issuedAt!==s.issuedAt){const w=B(n.refresh_time_before_tokens_expiration_in_second,d.expiresAt)>0?E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,A=await c.getNonceAsync();return{tokens:d,status:w,nonce:A}}r=await c.getNonceAsync()}else{const l=N(t,n.storage??sessionStorage),d=await l.initAsync();let{tokens:_}=d;const{status:w}=d;if(_&&(_=Z(_,e.tokens,n.token_renew_mode)),_){if(w==="SESSIONS_LOST")return{tokens:null,status:E.SESSION_LOST,nonce:i};if(_.issuedAt!==s.issuedAt){const g=B(n.refresh_time_before_tokens_expiration_in_second,_.expiresAt)>0?E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,y=await l.getNonceAsync();return{tokens:_,status:g,nonce:y}}}else return{tokens:null,status:E.LOGOUT_FROM_ANOTHER_TAB,nonce:i};r=await l.getNonceAsync()}const u=B(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:r}:{tokens:s,status:u,nonce:r}},z=e=>async(n,t=0,s=0,o=!1,i=null,r=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let a=6;const c=o?2:5,f=5;for(;!navigator.onLine&&a>0;)await te({milliseconds:1e3}),a--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${a}`});const u=document.hidden,l=u?t:t+1,d=u?s+1:s;if(t>=c||s>=f)return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token"}),{tokens:null,status:"SESSION_LOST"};i||(i={});const _=e.configuration,w=(g,y=null,S=null)=>le(e.configurationName,e.configuration,e.publishEvent.bind(e))(g,y,S),A=async()=>{try{let g;const y=await C(_,e.configurationName);y?g=y.getLoginParams():g=N(e.configurationName,_.storage).getLoginParams();const S={};if(g&&g.extras)for(const[v,h]of Object.entries(g.extras))S[v]=h;if(i)for(const[v,h]of Object.entries(i))S[v]=h;S.prompt="none",r&&(S.scope=r);const T=await w(S);return T?T.error?(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(n(T.tokens),e.publishEvent(W.eventNames.token_renewed,{}),{tokens:T.tokens,status:"LOGGED"}):(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(g){return console.error(g),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:g.message}),await z(e)(n,l,d,o,i,r)}};try{const{status:g,tokens:y,nonce:S}=await ce(e)(_,e.configurationName,e.tokens,o);switch(g){case E.SESSION_LOST:return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case E.NOT_CONNECTED:return n(null),{tokens:null,status:null};case E.TOKENS_VALID:return n(y),{tokens:y,status:"LOGGED_IN"};case E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(y),e.publishEvent(W.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:y,status:"LOGGED_IN"};case E.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case E.REQUIRE_SYNC_TOKENS:return _.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted&&!o?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:t}),await A());default:{if(_.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted&&E.FORCE_REFRESH!==g)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:y.refreshToken,status:g,tryNumber:t,backgroundTry:s}),!y.refreshToken)return await A();const T=_.client_id,v=_.redirect_uri,h=_.authority,L={..._.token_request_extras?_.token_request_extras:{}};for(const[b,m]of Object.entries(i))b.endsWith(":token_request")&&(L[b.replace(":token_request","")]=m);return await(async()=>{const b={client_id:T,redirect_uri:v,grant_type:"refresh_token",refresh_token:y.refreshToken},m=await e.initAsync(h,_.authority_configuration),D=document.hidden?1e4:3e4*10,G=m.tokenEndpoint,We={};_.demonstrating_proof_of_possession&&(We.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(y.accessToken,G,"POST"));const x=await on(e.getFetch())(G,b,L,y,We,_.token_renew_mode,D);if(x.success){const{isValid:On,reason:bn}=ye(x.data,S.nonce,m);if(!On)return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${bn}`}),{tokens:null,status:"SESSION_LOST"};if(n(x.data),x.demonstratingProofOfPossessionNonce){const Le=await C(_,e.configurationName);Le?await Le.setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce):await N(e.configurationName,_.storage).setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:x.success}),e.publishEvent(W.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:x.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:x}),x.status>=400&&x.status<500?(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${x.status}`}),{tokens:null,status:"SESSION_LOST"}):await z(e)(n,l,d,o,i,r)})()}}}catch(g){return console.error(g),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:g.message}),new Promise((y,S)=>{setTimeout(()=>{z(e)(n,l,d,o,i,r).then(y).catch(S)},1e3)})}},le=(e,n,t)=>(s=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let r="";if(o&&(s==null&&(s={}),s.state=o),i!=null&&(s==null&&(s={}),s.scope=i),s!=null)for(const[l,d]of Object.entries(s))r===""?r=`?${encodeURIComponent(l)}=${encodeURIComponent(d)}`:r+=`&${encodeURIComponent(l)}=${encodeURIComponent(d)}`;const a=n.silent_login_uri+r,c=a.indexOf("/",a.indexOf("//")+2),f=a.substring(0,c),u=document.createElement("iframe");return u.width="0px",u.height="0px",u.id=`${e}_oidc_iframe`,u.setAttribute("src",a),u.style.display="none",document.body.appendChild(u),new Promise((l,d)=>{let _=!1;const w=()=>{window.removeEventListener("message",A),u.remove(),_=!0},A=g=>{if(g.origin===f&&g.source===u.contentWindow){const y=`${e}_oidc_tokens:`,S=`${e}_oidc_error:`,T=`${e}_oidc_exception:`,v=g.data;if(v&&typeof v=="string"&&!_){if(v.startsWith(y)){const h=JSON.parse(g.data.replace(y,""));t(p.silentLoginAsync_end,{}),l(h),w()}else if(v.startsWith(S)){const h=JSON.parse(g.data.replace(S,""));t(p.silentLoginAsync_error,h),l({error:"oidc_"+h.error,tokens:null,sessionState:null}),w()}else if(v.startsWith(T)){const h=JSON.parse(g.data.replace(T,""));t(p.silentLoginAsync_error,h),d(new Error(h.error)),w()}}}};try{window.addEventListener("message",A);const g=n.silent_login_timeout;setTimeout(()=>{_||(w(),t(p.silentLoginAsync_error,{reason:"timeout"}),d(new Error("timeout")))},g)}catch(g){w(),t(p.silentLoginAsync_error,g),d(g)}})}catch(r){throw t(p.silentLoginAsync_error,r),r}},cn=(e,n,t,s,o)=>(i=null,r=void 0)=>{i={...i};const a=(f,u,l)=>le(n,t,s.bind(o))(f,u,l);return(async()=>{o.timeoutId&&$.clearTimeout(o.timeoutId);let f;i&&"state"in i&&(f=i.state,delete i.state);try{const u=t.extras?{...t.extras,...i}:i,l=await a({...u,prompt:"none"},f,r);if(l)return o.tokens=l.tokens,s(p.token_acquired,{}),o.timeoutId=H(o,o.tokens.expiresAt,i,r),{}}catch(u){return u}})()},ln=(e,n,t)=>(s,o,i,r=!1)=>{const a=(c,f=void 0,u=void 0)=>le(e.configurationName,t,e.publishEvent.bind(e))(c,f,u);return new Promise((c,f)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&i&&!r){const u=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const d=l.idToken,_=l.idTokenPayload;return a({prompt:"none",id_token_hint:d,scope:t.scope||"openid"}).then(w=>{if(w.error)throw new Error(w.error);const A=w.tokens.idTokenPayload;if(_.sub===A.sub){const g=w.sessionState;e.checkSessionIFrame.start(w.sessionState),_.sid===A.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",g):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",g)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",A.sub)}).catch(async w=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",w);for(const[,A]of Object.entries(n))await A.logoutOtherTabAsync(t.client_id,_.sub)})};e.checkSessionIFrame=new De(u,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),c(e.checkSessionIFrame)}).catch(l=>{f(l)})}else c(null)})},un=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),_n=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;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 a in i){const c=i[a];if(c.r.test(t)){o=c.s;break}}let r=s;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(t)[1];break;case"iOS":{const a=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);a!=null&&a.length>2&&(r=a[1]+"."+a[2]+"."+(parseInt(a[3])|0));break}}return{os:o,osVersion:r}};function fn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const dn=()=>{const{name:e,version:n}=fn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=_n(navigator);return!un(t)},hn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await C(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=H(e,e.tokens.expiresAt,i.extras,i.scope);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.checkSessionIframe,t.client_id,r),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=N(e.configurationName,t.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=Z(i,null,t.token_renew_mode);const r=o.getLoginParams();e.timeoutId=H(e,e.tokens.expiresAt,r.extras,r.scope);const a=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.checkSessionIframe,t.client_id,a),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},gn=e=>{const n=Ie(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},Q=e=>{const n=Ie(e),{search:t}=n;return yn(t)},yn=e=>{const n={};let t,s,o;const i=e.split("&");for(s=0,o=i.length;s<o;s++)t=i[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},kn=(e,n,t,s,o)=>(i=void 0,r=null,a=!1,c=void 0)=>{const f=r;return r={...r},(async()=>{const l=i||o.getPath();if("state"in r||(r.state=re(16)),t(p.loginAsync_begin,{}),r)for(const d of Object.keys(r))d.endsWith(":token_request")&&delete r[d];try{const d=a?n.silent_redirect_uri:n.redirect_uri;c||(c=n.scope);const _=n.extras?{...n.extras,...r}:r;_.nonce||(_.nonce=re(12));const w={nonce:_.nonce},A=await C(n,e),g=await s(n.authority,n.authority_configuration);let y;if(A)A.setLoginParams({callbackPath:l,extras:f,scope:c}),await A.initAsync(g,"loginAsync",n),await A.setNonceAsync(w),A.startKeepAliveServiceWorker(),y=A;else{const T=N(e,n.storage??sessionStorage);T.setLoginParams({callbackPath:l,extras:f,scope:c}),await T.setNonceAsync(w),y=T}const S={client_id:n.client_id,redirect_uri:d,scope:c,response_type:"code",..._};await rn(y,o)(g.authorizationEndpoint,S)}catch(d){throw t(p.loginAsync_error,d),d}})()},mn=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,i=t.authority,r=t.token_request_timeout,a=await e.initAsync(i,t.authority_configuration),c=e.location.getCurrentHref(),f=Q(c),u=f.session_state,l=await C(t,e.configurationName);let d,_,w,A;if(l)await l.initAsync(a,"loginCallbackAsync",t),await l.setSessionStateAsync(u),_=await l.getNonceAsync(),w=l.getLoginParams(),A=await l.getStateAsync(),l.startKeepAliveServiceWorker(),d=l;else{const m=N(e.configurationName,t.storage??sessionStorage);await m.setSessionStateAsync(u),_=await m.getNonceAsync(),w=m.getLoginParams(),A=await m.getStateAsync(),d=m}if(f.error||f.error_description)throw new Error(`Error from OIDC server: ${f.error} - ${f.error_description}`);if(f.iss&&f.iss!==a.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${a.issuer}, received: ${f.iss})`);if(f.state&&f.state!==A)throw new Error(`State not valid (expected: ${A}, received: ${f.state})`);const g={code:f.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},y={};if(t.token_request_extras)for(const[m,D]of Object.entries(t.token_request_extras))y[m]=D;if(w?.extras)for(const[m,D]of Object.entries(w.extras))m.endsWith(":token_request")&&(y[m.replace(":token_request","")]=D);const S=a.tokenEndpoint,T={};if(t.demonstrating_proof_of_possession)if(l)T.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const m=await ze(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await N(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(m),T.DPoP=await Te(window)(t.demonstrating_proof_of_possession_configuration)(m,"POST",S)}const v=await an(d)(S,{...g,...y},T,e.configuration.token_renew_mode,r);if(!v.success)throw new Error("Token request failed");let h;const P=v.data.tokens,L=v.data.demonstratingProofOfPossessionNonce;if(v.data.state!==y.state)throw new Error("state is not valid");const{isValid:k,reason:b}=ye(P,_.nonce,a);if(!k)throw new Error(`Tokens are not OpenID valid, reason: ${b}`);if(l){if(P.refreshToken&&!P.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(L&&P?.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(a,"syncTokensAsync",t),h=l.getLoginParams(),L&&await l.setDemonstratingProofOfPossessionNonce(L);else{const m=N(e.configurationName,t.storage);h=m.getLoginParams(),L&&await m.setDemonstratingProofOfPossessionNonce(L)}return await e.startCheckSessionAsync(a.checkSessionIframe,s,u,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:P,state:"request.state",callbackPath:h.callbackPath,scope:f.scope,extras:h.extras}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Ne={access_token:"access_token",refresh_token:"refresh_token"},ue=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const i=s.replace(n,"");t[i]=o}return t}return t},wn=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},pn=e=>async n=>{$.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await C(e.configuration,e.configurationName);t?await t.clearAsync(n):await N(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},An=(e,n,t,s,o)=>async(i=void 0,r=null)=>{const a=e.configuration,c=await e.initAsync(a.authority,a.authority_configuration);i&&typeof i!="string"&&(i=void 0,s.warn("callbackPathOrUrl path is not a string"));const f=i??o.getPath();let u=!1;i&&(u=i.includes("https://")||i.includes("http://"));const l=u?i:o.getOrigin()+f,d=e.tokens?e.tokens.idToken:"";try{const y=c.revocationEndpoint;if(y){const S=[],T=e.tokens?e.tokens.accessToken:null;if(T&&a.logout_tokens_to_invalidate.includes(Ne.access_token)){const h=ue(r,":revoke_access_token"),P=Oe(t)(y,T,ae.access_token,a.client_id,h);S.push(P)}const v=e.tokens?e.tokens.refreshToken:null;if(v&&a.logout_tokens_to_invalidate.includes(Ne.refresh_token)){const h=ue(r,":revoke_refresh_token"),P=Oe(t)(y,v,ae.refresh_token,a.client_id,h);S.push(P)}S.length>0&&await Promise.all(S)}}catch(y){s.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),s.warn(y)}const _=e.tokens?.idTokenPayload?.sub??null;await e.destroyAsync("LOGGED_OUT");for(const[,y]of Object.entries(n))y!==e?await e.logoutSameTabAsync(e.configuration.client_id,_):e.publishEvent(p.logout_from_same_tab,{});const w=ue(r,":oidc");if(w&&w.no_reload==="true")return;const g=wn(r);if(c.endSessionEndpoint){"id_token_hint"in g||(g.id_token_hint=d),!("post_logout_redirect_uri"in g)&&i!==null&&(g.post_logout_redirect_uri=l);let y="";for(const[S,T]of Object.entries(g))T!=null&&(y===""?y+="?":y+="&",y+=`${S}=${encodeURIComponent(T)}`);o.open(`${c.endSessionEndpoint}${y}`)}else o.reload()},Ce=(e,n,t=!1)=>async(...s)=>{const[o,i,...r]=s,a=i?{...i}:{method:"GET"};let c=new Headers;a.headers&&(c=a.headers instanceof Headers?a.headers:new Headers(a.headers));const f={getTokens:()=>n.tokens,configuration:{token_automatic_renew_mode:n.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:n.configuration.refresh_time_before_tokens_expiration_in_second},syncTokensInfoAsync:async()=>{const{status:_}=await ce(n)(n.configuration,n.configurationName,n.tokens,!1);return _},renewTokensAsync:n.renewTokensAsync.bind(n)},l=(await ge(f))?.tokens?.accessToken;if(c.has("Accept")||c.set("Accept","application/json"),l){if(n.configuration.demonstrating_proof_of_possession&&t){const _=await n.generateDemonstrationOfProofOfPossessionAsync(l,o.toString(),a.method);c.set("Authorization",`DPoP ${l}`),c.set("DPoP",_)}else c.set("Authorization",`Bearer ${l}`);a.credentials||(a.credentials="same-origin")}const d={...a,headers:c};return await e(o,d,...r)},Sn=e=>async(n=!1,t=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const s=!n&&e.configuration.storage?.getItem(`oidc.${e.configurationName}.userInfo`);if(s)return e.userInfo=JSON.parse(s),e.userInfo;const o=e.configuration,r=(await e.initAsync(o.authority,o.authority_configuration)).userInfoEndpoint,c=await(async()=>{const u=await Ce(fetch,e,t)(r);return u.status!==200?null:u.json()})();return e.userInfo=c,c&&e.configuration.storage?.setItem(`oidc.${e.configurationName}.userInfo`,JSON.stringify(c)),c},xe=()=>fetch;class _e{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 K={},Tn=(e,n=new R)=>(t,s="default")=>(K[s]||(K[s]=new W(t,s,e,n)),K[s]),vn=async e=>{const{parsedTokens:n,callbackPath:t,extras:s,scope:o}=await e.loginCallbackAsync();return e.timeoutId=H(e,n.expiresAt,s,o),{callbackPath:t}},En=e=>Math.floor(Math.random()*e),j=class j{constructor(n,t="default",s,o=new R){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 R,this.configuration={...n,silent_login_uri:i,token_automatic_renew_mode:n.token_automatic_renew_mode??V.AutomaticBeforeTokenExpiration,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??q.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_activate:n.service_worker_activate??dn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ge,preload_user_info:n.preload_user_info??!1},this.getFetch=s??xe,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,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 t=En(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(K,n)&&t)throw Error(`OIDC library does seem initialized.
1
+ (function(I,R){typeof exports=="object"&&typeof module<"u"?R(exports):typeof define=="function"&&define.amd?define(["exports"],R):(I=typeof globalThis<"u"?globalThis:I||self,R(I["oidc-client"]={}))})(this,(function(I){"use strict";class R{open(n){window.location.href=n}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 de=2e3,U=console;class De{constructor(n,t,s,o=de,i=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||de,this._stopOnError=i;const r=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substring(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=s}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"?(U.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(U.debug(n),U.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):U.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){U.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(U.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_acquired:"token_acquired",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",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},N=(e,n=sessionStorage)=>{const t=h=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:h}),delete n[`oidc.${e}.userInfo`],Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const h=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:h.tokens,status:h.status})},o=h=>{n[`oidc.${e}`]=JSON.stringify({tokens:h})},i=async h=>{n[`oidc.session_state.${e}`]=h},r=async()=>n[`oidc.session_state.${e}`],a=h=>{n[`oidc.nonce.${e}`]=h.nonce},c=h=>{n[`oidc.jwk.${e}`]=JSON.stringify(h)},f=()=>JSON.parse(n[`oidc.jwk.${e}`]),u=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async h=>{n[`oidc.dpop_nonce.${e}`]=h},d=()=>n[`oidc.dpop_nonce.${e}`],_=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null,w={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:_,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:a,getNonceAsync:u,setLoginParams:h=>{w[e]=h,n[`oidc.login.${e}`]=JSON.stringify(h)},getLoginParams:()=>{const h=n[`oidc.login.${e}`];return h?(w[e]||(w[e]=JSON.parse(h)),w[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 h=>{n[`oidc.state.${e}`]=h},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async h=>{n[`oidc.code_verifier.${e}`]=h},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:d,setDemonstratingProofOfPossessionJwkAsync:c,getDemonstratingProofOfPossessionJwkAsync:f}};var V=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(V||{});const Re=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),$e=e=>JSON.parse(Re(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),he=e=>{try{return e&&Ke(e,".")===2?$e(e.split(".")[1]):null}catch(n){console.warn(n)}return null},Ke=(e,n)=>e.split(n).length-1,q={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 Ue(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const Z=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=he(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:he(i),a=r&&r.exp?r.exp:Number.MAX_VALUE,c=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Ue(e,s,r);let f;e.expiresAt?f=e.expiresAt:t===q.access_token_invalid?f=c:t===q.id_token_invalid?f=a:f=a<c?a:c;const u={...e,idTokenPayload:r,accessTokenPayload:s,expiresAt:f,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...u,refreshToken:l}}return u},ee=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={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&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),Z(s,n,t)},B=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},Ve=(e,n=0)=>e?B(n,e.expiresAt)>0:!1,ge=async(e,n=200,t=50)=>{let s=t,o=await e.syncTokensInfoAsync();for(;[E.REQUIRE_SYNC_TOKENS,E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,E.TOKENS_INVALID].includes(o)&&s>0;){if(e.configuration.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await te({milliseconds:n});s=s-1,o=await e.syncTokensInfoAsync()}return{isTokensValid:Ve(e.getTokens()),tokens:e.getTokens(),numberWaited:s-t}},ye=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const i=3600*24*7;if(s.iat&&s.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+i} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},$=(function(){const e=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}})(),ne="7.26.7";let ke=null,Y;const te=({milliseconds:e})=>new Promise(n=>$.setTimeout(n,e)),me=(e="/")=>{try{Y=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Y.signal}).catch(s=>{console.log(s)}),te({milliseconds:150*1e3}).then(()=>me(e))}catch(n){console.log(n)}},se=()=>{Y&&Y.abort()},we=e=>{const n=`oidc.tabId.${e}`,t=sessionStorage.getItem(n);if(t)return t;const s=globalThis.crypto.randomUUID();return sessionStorage.setItem(n,s),s},Fe=5e3,Me=e=>navigator.serviceWorker.controller??e.active??e.waiting??e.installing??null,O=(e,n)=>t=>{const s=n?.timeoutMs??Fe;return new Promise((o,i)=>{const r=Me(e);if(!r){i(new Error("Service worker target not available (controller/active/waiting/installing missing)"));return}const a=new MessageChannel;let c=null;const f=()=>{try{c!=null&&($.clearTimeout(c),c=null),a.port1.onmessage=null,a.port1.close(),a.port2.close()}catch(u){console.error(u)}};c=$.setTimeout(()=>{f(),i(new Error(`Service worker did not respond within ${s}ms (type=${t?.type})`))},s),a.port1.onmessage=u=>{f(),u?.data?.error?i(u.data.error):o(u.data)};try{const u=t?.configurationName;r.postMessage({...t,tabId:we(u??"default")},[a.port2])}catch(u){f(),i(u)}})},Be=async e=>navigator.serviceWorker.controller?navigator.serviceWorker.controller:new Promise(n=>{let t=!1;const s=()=>{t||(t=!0,navigator.serviceWorker.removeEventListener("controllerchange",s),n(navigator.serviceWorker.controller??null))};navigator.serviceWorker.addEventListener("controllerchange",s),$.setTimeout(()=>{t||(t=!0,navigator.serviceWorker.removeEventListener("controllerchange",s),n(navigator.serviceWorker.controller??null))},e)}),C=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;const s=`${t}?v=${ne}`;let o=null;e.service_worker_register?o=await e.service_worker_register(t):o=await navigator.serviceWorker.register(s,{updateViaCache:"none"});try{await o.update()}catch(k){console.error(k)}o.addEventListener("updatefound",()=>{const k=o.installing;se(),k?.addEventListener("statechange",async()=>{if(k.state==="installed"&&navigator.serviceWorker.controller){se(),console.log("New SW waiting – SKIP_WAITING");try{await O(o,{timeoutMs:8e3})({type:"SKIP_WAITING",configurationName:n,data:null})}catch(b){console.warn("SKIP_WAITING failed",b)}}})});const i=`oidc.sw.controllerchange.reloaded.${n}`;navigator.serviceWorker.addEventListener("controllerchange",()=>{try{if(sessionStorage.getItem(i)==="1")return;sessionStorage.setItem(i,"1")}catch{}console.log("SW controller changed – reloading page"),se(),window.location.reload()});try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||(await O(o,{timeoutMs:8e3})({type:"claim",configurationName:n,data:null}),await Be(2e3))}catch(k){return console.warn(`Failed init ServiceWorker ${k?.toString?.()??String(k)}`),null}const r=async k=>O(o)({type:"clear",data:{status:k},configurationName:n}),a=async(k,b,m)=>{const D=await O(o)({type:"init",data:{oidcServerConfiguration:k,where:b,oidcConfiguration:{token_renew_mode:m.token_renew_mode,service_worker_convert_all_requests_to_cors:m.service_worker_convert_all_requests_to_cors}},configurationName:n}),G=D.version;return G!==ne&&console.warn(`Service worker ${G} version mismatch with js client version ${ne}, unregistering and reloading`),{tokens:ee(D.tokens,null,m.token_renew_mode),status:D.status}},c=(k="/")=>{ke==null&&(ke="not_null",me(k))},f=k=>O(o)({type:"setSessionState",data:{sessionState:k},configurationName:n}),u=async()=>(await O(o)({type:"getSessionState",data:null,configurationName:n})).sessionState,l=k=>(sessionStorage[`oidc.nonce.${n}`]=k.nonce,O(o)({type:"setNonce",data:{nonce:k},configurationName:n})),d=async(k=!0)=>{let m=(await O(o)({type:"getNonce",data:null,configurationName:n})).nonce;return m||(m=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage"),k&&(await l(m),m=(await d(!1)).nonce)),{nonce:m}},_={},w=k=>{_[n]=k,localStorage[`oidc.login.${n}`]=JSON.stringify(k)},A=()=>{const k=localStorage[`oidc.login.${n}`];return _[n]||(_[n]=JSON.parse(k)),_[n]},g=async k=>{await O(o)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:k},configurationName:n})},y=async()=>(await O(o)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,S=async k=>{const b=JSON.stringify(k);await O(o)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:b},configurationName:n})},T=async()=>{const k=await O(o)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return k.demonstratingProofOfPossessionJwkJson?JSON.parse(k.demonstratingProofOfPossessionJwkJson):null},v=async(k=!0)=>{let m=(await O(o)({type:"getState",data:null,configurationName:n})).state;return m||(m=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage"),k&&(await h(m),m=await v(!1))),m},h=async k=>(sessionStorage[`oidc.state.${n}`]=k,O(o)({type:"setState",data:{state:k},configurationName:n})),P=async(k=!0)=>{let m=(await O(o)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return m||(m=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage"),k&&(await L(m),m=await P(!1))),m},L=async k=>(sessionStorage[`oidc.code_verifier.${n}`]=k,O(o)({type:"setCodeVerifier",data:{codeVerifier:k},configurationName:n}));return{clearAsync:r,initAsync:a,startKeepAliveServiceWorker:()=>c(e.service_worker_keep_alive_path),setSessionStateAsync:f,getSessionStateAsync:u,setNonceAsync:l,getNonceAsync:d,setLoginParams:w,getLoginParams:A,getStateAsync:v,setStateAsync:h,getCodeVerifierAsync:P,setCodeVerifierAsync:L,setDemonstratingProofOfPossessionNonce:g,getDemonstratingProofOfPossessionNonce:y,setDemonstratingProofOfPossessionJwkAsync:S,getDemonstratingProofOfPossessionJwkAsync:T}},F={},Je=(e,n=window.sessionStorage,t)=>{if(!F[e]&&n){const o=n.getItem(e);o&&(F[e]=JSON.parse(o))}const s=1e3*t;return F[e]&&F[e].timestamp+s>Date.now()?F[e].result:null},He=(e,n,t=window.sessionStorage)=>{const s=Date.now();F[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function pe(e){return new TextEncoder().encode(e)}function Ae(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function je(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const oe=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),Ae(n)};function Se(e){return Ae(je(e))}const Ge={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"},qe={sign:e=>async(n,t,s,o,i="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=i,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const r={protected:Se(JSON.stringify(t)),payload:Se(JSON.stringify(s))},a=o.importKeyAlgorithm,c=!0,f=["sign"],u=await e.crypto.subtle.importKey("jwk",n,a,c,f),l=pe(`${r.protected}.${r.payload}`),d=o.signAlgorithm,_=await e.crypto.subtle.sign(d,u,l);return r.signature=oe(new Uint8Array(_)),`${r.protected}.${r.payload}.${r.signature}`}},Ye={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],i=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",i.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}},Xe={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,pe(s));return oe(new Uint8Array(o))}},ze=e=>async n=>await Ye.generate(e)(n),Te=e=>n=>async(t,s="POST",o,i={})=>{const r={jti:btoa(Qe()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...i},a=await Xe.thumbprint(e)(t,n.digestAlgorithm);return await qe.sign(e)(t,{kid:a},r,n)},Qe=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},ve=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Ze=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%ie.length;n.push(ie[s])}return n.join("")},re=e=>{const n=new Uint8Array(e),{hasCrypto:t}=ve();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*ie.length|0;return Ze(n)};function en(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Ee(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",en(e)).then(s=>n(oe(new Uint8Array(s))),s=>t(s))})}const nn=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=ve();return n?Ee(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},tn=3600,sn=e=>async(n,t=tn,s=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,a=Je(r,s,t);if(a)return new _e(a);const c=await J(e)(i,{},o);if(c.status!==200)return null;const f=await c.json();return He(r,f,s),new _e(f)},J=e=>async(n,t={},s=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),s),i=await e(n,{...t,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await J(e)(n,t,s,o+1);throw r}else throw console.error(r.message),r}return i},ae={refresh_token:"refresh_token",access_token:"access_token"},Oe=e=>async(n,t,s=ae.refresh_token,o,i={},r=1e4)=>{const a={token:t,token_type_hint:s,client_id:o};for(const[l,d]of Object.entries(i))a[l]===void 0&&(a[l]=d);const c=[];for(const l in a){const d=encodeURIComponent(l),_=encodeURIComponent(a[l]);c.push(`${d}=${_}`)}const f=c.join("&");return(await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:f},r)).status!==200?{success:!1}:{success:!0}},on=e=>async(n,t,s,o,i={},r,a=1e4)=>{for(const[_,w]of Object.entries(s))t[_]===void 0&&(t[_]=w);const c=[];for(const _ in t){const w=encodeURIComponent(_),A=encodeURIComponent(t[_]);c.push(`${w}=${A}`)}const f=c.join("&"),u=await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:f},a);if(u.status!==200)return{success:!1,status:u.status,demonstratingProofOfPossessionNonce:null};const l=await u.json();let d=null;return u.headers.has(X)&&(d=u.headers.get(X)),{success:!0,status:u.status,data:ee(l,o,r),demonstratingProofOfPossessionNonce:d}},rn=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=re(128),i=await nn(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=i,s.code_challenge_method="S256";let r="";if(s)for(const[a,c]of Object.entries(s))r===""?r+="?":r+="&",r+=`${a}=${encodeURIComponent(c)}`;n.open(`${t}${r}`)},X="DPoP-Nonce",an=e=>async(n,t,s,o,i=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const l in t){const d=encodeURIComponent(l),_=encodeURIComponent(t[l]);r.push(`${d}=${_}`)}const a=r.join("&"),c=await J(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:a},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),c.status!==200)return{success:!1,status:c.status};let f=null;c.headers.has(X)&&(f=c.headers.get(X));const u=await c.json();return{success:!0,data:{state:t.state,tokens:ee(u,null,o),demonstratingProofOfPossessionNonce:f}}};async function be(e,n,t,s=null){const o=c=>{e.tokens=c},{tokens:i,status:r}=await z(e)(o,0,0,n,t,s);return await C(e.configuration,e.configurationName)||N(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?i:(await e.destroyAsync(r),null)}async function Pe(e,n=!1,t=null,s=null){const o=e.configuration,i=`${o.client_id}_${e.configurationName}_${o.authority}`;let r;const a=await C(e.configuration,e.configurationName);if(o?.storage===window?.sessionStorage&&!a||!navigator.locks)r=await be(e,n,t,s);else{let c="retry";for(;c==="retry";)c=await navigator.locks.request(i,{ifAvailable:!0},async f=>f?await be(e,n,t,s):(e.publishEvent(W.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),"retry"));r=c}return r?(e.timeoutId&&(e.timeoutId=H(e,e.tokens.expiresAt,t,s)),e.tokens):null}const H=(e,n,t=null,s=null)=>{const o=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&$.clearTimeout(e.timeoutId),$.setTimeout(async()=>{const r={timeLeft:B(o,n)};e.publishEvent(W.eventNames.token_timer,r),await Pe(e,!1,t,s)},1e3)},E={FORCE_REFRESH:"FORCE_REFRESH",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",TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS",TOKENS_INVALID:"TOKENS_INVALID"},ce=e=>async(n,t,s,o=!1)=>{const i={nonce:null};if(!s)return{tokens:null,status:E.NOT_CONNECTED,nonce:i};let r=i;const a=await e.initAsync(n.authority,n.authority_configuration),c=await C(n,t);if(c){const{status:l,tokens:d}=await c.initAsync(a,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:E.LOGOUT_FROM_ANOTHER_TAB,nonce:i};if(l==="SESSIONS_LOST")return{tokens:null,status:E.SESSION_LOST,nonce:i};if(!l||!d)return{tokens:null,status:E.REQUIRE_SYNC_TOKENS,nonce:i};if(d.issuedAt!==s.issuedAt){const w=B(n.refresh_time_before_tokens_expiration_in_second,d.expiresAt)>0?E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,A=await c.getNonceAsync();return{tokens:d,status:w,nonce:A}}r=await c.getNonceAsync()}else{const l=N(t,n.storage??sessionStorage),d=await l.initAsync();let{tokens:_}=d;const{status:w}=d;if(_&&(_=Z(_,e.tokens,n.token_renew_mode)),_){if(w==="SESSIONS_LOST")return{tokens:null,status:E.SESSION_LOST,nonce:i};if(_.issuedAt!==s.issuedAt){const g=B(n.refresh_time_before_tokens_expiration_in_second,_.expiresAt)>0?E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,y=await l.getNonceAsync();return{tokens:_,status:g,nonce:y}}}else return{tokens:null,status:E.LOGOUT_FROM_ANOTHER_TAB,nonce:i};r=await l.getNonceAsync()}const u=B(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:r}:{tokens:s,status:u,nonce:r}},z=e=>async(n,t=0,s=0,o=!1,i=null,r=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let a=6;const c=o?2:5,f=5;for(;!navigator.onLine&&a>0;)await te({milliseconds:1e3}),a--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${a}`});const u=document.hidden,l=u?t:t+1,d=u?s+1:s;if(t>=c||s>=f)return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token"}),{tokens:null,status:"SESSION_LOST"};i||(i={});const _=e.configuration,w=(g,y=null,S=null)=>le(e.configurationName,e.configuration,e.publishEvent.bind(e))(g,y,S),A=async()=>{try{let g;const y=await C(_,e.configurationName);y?g=y.getLoginParams():g=N(e.configurationName,_.storage).getLoginParams();const S={};if(g&&g.extras)for(const[v,h]of Object.entries(g.extras))h!=null&&(S[v]=h);if(i)for(const[v,h]of Object.entries(i))h!=null&&(S[v]=h);S.prompt="none",r&&(S.scope=r);const T=await w(S);return T?T.error?(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(n(T.tokens),e.publishEvent(W.eventNames.token_renewed,{}),{tokens:T.tokens,status:"LOGGED"}):(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(g){return console.error(g),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:g.message}),await z(e)(n,l,d,o,i,r)}};try{const{status:g,tokens:y,nonce:S}=await ce(e)(_,e.configurationName,e.tokens,o);switch(g){case E.SESSION_LOST:return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case E.NOT_CONNECTED:return n(null),{tokens:null,status:null};case E.TOKENS_VALID:return n(y),{tokens:y,status:"LOGGED_IN"};case E.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(y),e.publishEvent(W.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:y,status:"LOGGED_IN"};case E.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case E.REQUIRE_SYNC_TOKENS:return _.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted&&!o?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:t}),await A());default:{if(_.token_automatic_renew_mode==V.AutomaticOnlyWhenFetchExecuted&&E.FORCE_REFRESH!==g)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:y.refreshToken,status:g,tryNumber:t,backgroundTry:s}),!y.refreshToken)return await A();const T=_.client_id,v=_.redirect_uri,h=_.authority,L={..._.token_request_extras?_.token_request_extras:{}};for(const[b,m]of Object.entries(i))b.endsWith(":token_request")&&(L[b.replace(":token_request","")]=m);return await(async()=>{const b={client_id:T,redirect_uri:v,grant_type:"refresh_token",refresh_token:y.refreshToken},m=await e.initAsync(h,_.authority_configuration),D=document.hidden?1e4:3e4*10,G=m.tokenEndpoint,We={};_.demonstrating_proof_of_possession&&(We.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(y.accessToken,G,"POST"));const x=await on(e.getFetch())(G,b,L,y,We,_.token_renew_mode,D);if(x.success){const{isValid:On,reason:bn}=ye(x.data,S.nonce,m);if(!On)return n(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${bn}`}),{tokens:null,status:"SESSION_LOST"};if(n(x.data),x.demonstratingProofOfPossessionNonce){const Le=await C(_,e.configurationName);Le?await Le.setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce):await N(e.configurationName,_.storage).setDemonstratingProofOfPossessionNonce(x.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:x.success}),e.publishEvent(W.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:x.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:x}),x.status>=400&&x.status<500?(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${x.status}`}),{tokens:null,status:"SESSION_LOST"}):await z(e)(n,l,d,o,i,r)})()}}}catch(g){return console.error(g),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:g.message}),new Promise((y,S)=>{setTimeout(()=>{z(e)(n,l,d,o,i,r).then(y).catch(S)},1e3)})}},le=(e,n,t)=>(s=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let r="";if(o&&(s==null&&(s={}),s.state=o),i!=null&&(s==null&&(s={}),s.scope=i),s!=null)for(const[l,d]of Object.entries(s))d!=null&&(r===""?r=`?${encodeURIComponent(l)}=${encodeURIComponent(d)}`:r+=`&${encodeURIComponent(l)}=${encodeURIComponent(d)}`);const a=n.silent_login_uri+r,c=a.indexOf("/",a.indexOf("//")+2),f=a.substring(0,c),u=document.createElement("iframe");return u.width="0px",u.height="0px",u.id=`${e}_oidc_iframe`,u.setAttribute("src",a),u.style.display="none",document.body.appendChild(u),new Promise((l,d)=>{let _=!1;const w=()=>{window.removeEventListener("message",A),u.remove(),_=!0},A=g=>{if(g.origin===f&&g.source===u.contentWindow){const y=`${e}_oidc_tokens:`,S=`${e}_oidc_error:`,T=`${e}_oidc_exception:`,v=g.data;if(v&&typeof v=="string"&&!_){if(v.startsWith(y)){const h=JSON.parse(g.data.replace(y,""));t(p.silentLoginAsync_end,{}),l(h),w()}else if(v.startsWith(S)){const h=JSON.parse(g.data.replace(S,""));t(p.silentLoginAsync_error,h),l({error:"oidc_"+h.error,tokens:null,sessionState:null}),w()}else if(v.startsWith(T)){const h=JSON.parse(g.data.replace(T,""));t(p.silentLoginAsync_error,h),d(new Error(h.error)),w()}}}};try{window.addEventListener("message",A);const g=n.silent_login_timeout;setTimeout(()=>{_||(w(),t(p.silentLoginAsync_error,{reason:"timeout"}),d(new Error("timeout")))},g)}catch(g){w(),t(p.silentLoginAsync_error,g),d(g)}})}catch(r){throw t(p.silentLoginAsync_error,r),r}},cn=(e,n,t,s,o)=>(i=null,r=void 0)=>{i={...i};const a=(f,u,l)=>le(n,t,s.bind(o))(f,u,l);return(async()=>{o.timeoutId&&$.clearTimeout(o.timeoutId);let f;i&&"state"in i&&(f=i.state,delete i.state);try{const u=t.extras?{...t.extras,...i}:i,l=await a({...u,prompt:"none"},f,r);if(l)return o.tokens=l.tokens,s(p.token_acquired,{}),o.timeoutId=H(o,o.tokens.expiresAt,i,r),{}}catch(u){return u}})()},ln=(e,n,t)=>(s,o,i,r=!1)=>{const a=(c,f=void 0,u=void 0)=>le(e.configurationName,t,e.publishEvent.bind(e))(c,f,u);return new Promise((c,f)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&i&&!r){const u=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const d=l.idToken,_=l.idTokenPayload;return a({prompt:"none",id_token_hint:d,scope:t.scope||"openid"}).then(w=>{if(w.error)throw new Error(w.error);const A=w.tokens.idTokenPayload;if(_.sub===A.sub){const g=w.sessionState;e.checkSessionIFrame.start(w.sessionState),_.sid===A.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",g):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",g)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",A.sub)}).catch(async w=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",w);for(const[,A]of Object.entries(n))await A.logoutOtherTabAsync(t.client_id,_.sub)})};e.checkSessionIFrame=new De(u,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),c(e.checkSessionIFrame)}).catch(l=>{f(l)})}else c(null)})},un=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),_n=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;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 a in i){const c=i[a];if(c.r.test(t)){o=c.s;break}}let r=s;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(t)[1];break;case"iOS":{const a=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);a!=null&&a.length>2&&(r=a[1]+"."+a[2]+"."+(parseInt(a[3])|0));break}}return{os:o,osVersion:r}};function fn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const dn=()=>{const{name:e,version:n}=fn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=_n(navigator);return!un(t)},hn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await C(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=H(e,e.tokens.expiresAt,i.extras,i.scope);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.checkSessionIframe,t.client_id,r),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=N(e.configurationName,t.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=Z(i,null,t.token_renew_mode);const r=o.getLoginParams();e.timeoutId=H(e,e.tokens.expiresAt,r.extras,r.scope);const a=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.checkSessionIframe,t.client_id,a),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},gn=e=>{const n=Ie(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},Q=e=>{const n=Ie(e),{search:t}=n;return yn(t)},yn=e=>{const n={};let t,s,o;const i=e.split("&");for(s=0,o=i.length;s<o;s++)t=i[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},kn=(e,n,t,s,o)=>(i=void 0,r=null,a=!1,c=void 0)=>{const f=r;return r={...r},(async()=>{const l=i||o.getPath();if("state"in r||(r.state=re(16)),t(p.loginAsync_begin,{}),r)for(const d of Object.keys(r))d.endsWith(":token_request")&&delete r[d];try{const d=a?n.silent_redirect_uri:n.redirect_uri;c||(c=n.scope);const _=n.extras?{...n.extras,...r}:r;_.nonce||(_.nonce=re(12));const w={nonce:_.nonce},A=await C(n,e),g=await s(n.authority,n.authority_configuration);let y;if(A)A.setLoginParams({callbackPath:l,extras:f,scope:c}),await A.initAsync(g,"loginAsync",n),await A.setNonceAsync(w),A.startKeepAliveServiceWorker(),y=A;else{const T=N(e,n.storage??sessionStorage);T.setLoginParams({callbackPath:l,extras:f,scope:c}),await T.setNonceAsync(w),y=T}const S={client_id:n.client_id,redirect_uri:d,scope:c,response_type:"code",..._};await rn(y,o)(g.authorizationEndpoint,S)}catch(d){throw t(p.loginAsync_error,d),d}})()},mn=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,i=t.authority,r=t.token_request_timeout,a=await e.initAsync(i,t.authority_configuration),c=e.location.getCurrentHref(),f=Q(c),u=f.session_state,l=await C(t,e.configurationName);let d,_,w,A;if(l)await l.initAsync(a,"loginCallbackAsync",t),await l.setSessionStateAsync(u),_=await l.getNonceAsync(),w=l.getLoginParams(),A=await l.getStateAsync(),l.startKeepAliveServiceWorker(),d=l;else{const m=N(e.configurationName,t.storage??sessionStorage);await m.setSessionStateAsync(u),_=await m.getNonceAsync(),w=m.getLoginParams(),A=await m.getStateAsync(),d=m}if(f.error||f.error_description)throw new Error(`Error from OIDC server: ${f.error} - ${f.error_description}`);if(f.iss&&f.iss!==a.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${a.issuer}, received: ${f.iss})`);if(f.state&&f.state!==A)throw new Error(`State not valid (expected: ${A}, received: ${f.state})`);const g={code:f.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},y={};if(t.token_request_extras)for(const[m,D]of Object.entries(t.token_request_extras))y[m]=D;if(w?.extras)for(const[m,D]of Object.entries(w.extras))m.endsWith(":token_request")&&(y[m.replace(":token_request","")]=D);const S=a.tokenEndpoint,T={};if(t.demonstrating_proof_of_possession)if(l)T.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const m=await ze(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await N(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(m),T.DPoP=await Te(window)(t.demonstrating_proof_of_possession_configuration)(m,"POST",S)}const v=await an(d)(S,{...g,...y},T,e.configuration.token_renew_mode,r);if(!v.success)throw new Error("Token request failed");let h;const P=v.data.tokens,L=v.data.demonstratingProofOfPossessionNonce;if(v.data.state!==y.state)throw new Error("state is not valid");const{isValid:k,reason:b}=ye(P,_.nonce,a);if(!k)throw new Error(`Tokens are not OpenID valid, reason: ${b}`);if(l){if(P.refreshToken&&!P.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(L&&P?.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(a,"syncTokensAsync",t),h=l.getLoginParams(),L&&await l.setDemonstratingProofOfPossessionNonce(L);else{const m=N(e.configurationName,t.storage);h=m.getLoginParams(),L&&await m.setDemonstratingProofOfPossessionNonce(L)}return await e.startCheckSessionAsync(a.checkSessionIframe,s,u,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:P,state:"request.state",callbackPath:h.callbackPath,scope:f.scope,extras:h.extras}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Ne={access_token:"access_token",refresh_token:"refresh_token"},ue=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const i=s.replace(n,"");t[i]=o}return t}return t},wn=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},pn=e=>async n=>{$.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await C(e.configuration,e.configurationName);t?await t.clearAsync(n):await N(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},An=(e,n,t,s,o)=>async(i=void 0,r=null)=>{const a=e.configuration,c=await e.initAsync(a.authority,a.authority_configuration);i&&typeof i!="string"&&(i=void 0,s.warn("callbackPathOrUrl path is not a string"));const f=i??o.getPath();let u=!1;i&&(u=i.includes("https://")||i.includes("http://"));const l=u?i:o.getOrigin()+f,d=e.tokens?e.tokens.idToken:"";try{const y=c.revocationEndpoint;if(y){const S=[],T=e.tokens?e.tokens.accessToken:null;if(T&&a.logout_tokens_to_invalidate.includes(Ne.access_token)){const h=ue(r,":revoke_access_token"),P=Oe(t)(y,T,ae.access_token,a.client_id,h);S.push(P)}const v=e.tokens?e.tokens.refreshToken:null;if(v&&a.logout_tokens_to_invalidate.includes(Ne.refresh_token)){const h=ue(r,":revoke_refresh_token"),P=Oe(t)(y,v,ae.refresh_token,a.client_id,h);S.push(P)}S.length>0&&await Promise.all(S)}}catch(y){s.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),s.warn(y)}const _=e.tokens?.idTokenPayload?.sub??null;await e.destroyAsync("LOGGED_OUT");for(const[,y]of Object.entries(n))y!==e?await e.logoutSameTabAsync(e.configuration.client_id,_):e.publishEvent(p.logout_from_same_tab,{});const w=ue(r,":oidc");if(w&&w.no_reload==="true")return;const g=wn(r);if(c.endSessionEndpoint){"id_token_hint"in g||(g.id_token_hint=d),!("post_logout_redirect_uri"in g)&&i!==null&&(g.post_logout_redirect_uri=l);let y="";for(const[S,T]of Object.entries(g))T!=null&&(y===""?y+="?":y+="&",y+=`${S}=${encodeURIComponent(T)}`);o.open(`${c.endSessionEndpoint}${y}`)}else o.reload()},Ce=(e,n,t=!1)=>async(...s)=>{const[o,i,...r]=s,a=i?{...i}:{method:"GET"};let c=new Headers;a.headers&&(c=a.headers instanceof Headers?a.headers:new Headers(a.headers));const f={getTokens:()=>n.tokens,configuration:{token_automatic_renew_mode:n.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:n.configuration.refresh_time_before_tokens_expiration_in_second},syncTokensInfoAsync:async()=>{const{status:_}=await ce(n)(n.configuration,n.configurationName,n.tokens,!1);return _},renewTokensAsync:n.renewTokensAsync.bind(n)},l=(await ge(f))?.tokens?.accessToken;if(c.has("Accept")||c.set("Accept","application/json"),l){if(n.configuration.demonstrating_proof_of_possession&&t){const _=await n.generateDemonstrationOfProofOfPossessionAsync(l,o.toString(),a.method);c.set("Authorization",`DPoP ${l}`),c.set("DPoP",_)}else c.set("Authorization",`Bearer ${l}`);a.credentials||(a.credentials="same-origin")}const d={...a,headers:c};return await e(o,d,...r)},Sn=e=>async(n=!1,t=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const s=!n&&e.configuration.storage?.getItem(`oidc.${e.configurationName}.userInfo`);if(s)return e.userInfo=JSON.parse(s),e.userInfo;const o=e.configuration,r=(await e.initAsync(o.authority,o.authority_configuration)).userInfoEndpoint,c=await(async()=>{const u=await Ce(fetch,e,t)(r);return u.status!==200?null:u.json()})();return e.userInfo=c,c&&e.configuration.storage?.setItem(`oidc.${e.configurationName}.userInfo`,JSON.stringify(c)),c},xe=()=>fetch;class _e{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 K={},Tn=(e,n=new R)=>(t,s="default")=>(K[s]||(K[s]=new W(t,s,e,n)),K[s]),vn=async e=>{const{parsedTokens:n,callbackPath:t,extras:s,scope:o}=await e.loginCallbackAsync();return e.timeoutId=H(e,n.expiresAt,s,o),{callbackPath:t}},En=e=>Math.floor(Math.random()*e),j=class j{constructor(n,t="default",s,o=new R){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 R,this.configuration={...n,silent_login_uri:i,token_automatic_renew_mode:n.token_automatic_renew_mode??V.AutomaticBeforeTokenExpiration,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??q.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_activate:n.service_worker_activate??dn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ge,preload_user_info:n.preload_user_info??!1},this.getFetch=s??xe,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,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 t=En(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(K,n)&&t)throw Error(`OIDC library does seem initialized.
2
2
  Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return K[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,t=Q(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const t=this.location,s=Q(t.getCurrentHref());s.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,t.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,t){if(this.initPromise!==null)return this.initPromise;const s=async()=>{if(t!=null)return new _e({authorization_endpoint:t.authorization_endpoint,end_session_endpoint:t.end_session_endpoint,revocation_endpoint:t.revocation_endpoint,token_endpoint:t.token_endpoint,userinfo_endpoint:t.userinfo_endpoint,check_session_iframe:t.check_session_iframe,issuer:t.issuer});const i=await C(this.configuration,this.configurationName)?this.configuration.storage||window.sessionStorage:this.configuration.storage;return await sn(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??3600,i,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=s(),this.initPromise.finally(()=>{this.initPromise=null})}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=hn(this),this.tryKeepExistingSessionPromise.finally(()=>{this.tryKeepExistingSessionPromise=null}))}async startCheckSessionAsync(n,t,s,o=!1){await ln(this,K,this.configuration)(n,t,s,o)}async loginAsync(n=void 0,t=null,s=!1,o=void 0,i=!1){return this.logoutPromise&&await this.logoutPromise,this.loginPromise!==null?this.loginPromise:(i?this.loginPromise=cn(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,o):this.loginPromise=kn(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,t,s,o),this.loginPromise.finally(()=>{this.loginPromise=null}))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const t=async()=>{const s=await mn(this)(n),o=s.tokens;return this.tokens=o,await C(this.configuration,this.configurationName)||N(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(j.eventNames.token_acquired,o),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:o,state:s.state,callbackPath:s.callbackPath,scope:s.scope,extras:s.extras}};return this.loginCallbackPromise=t(),this.loginCallbackPromise.finally(()=>{this.loginCallbackPromise=null})}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){const i=this.configuration,r={ath:await Ee(n),...o};if(await C(i,this.configurationName))return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${we(this.configurationName)}`;const c=N(this.configurationName,i.storage),f=await c.getDemonstratingProofOfPossessionJwkAsync(),u=c.getDemonstratingProofOfPossessionNonce();return u&&(r.nonce=u),await Te(window)(i.demonstrating_proof_of_possession_configuration)(f,s,t,r)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=vn(this),this.loginCallbackWithAutoTokensRenewPromise.finally(()=>{this.loginCallbackWithAutoTokensRenewPromise=null}))}userInfoAsync(n=!1,t=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=Sn(this)(n,t),this.userInfoPromise.finally(()=>{this.userInfoPromise=null}))}async renewTokensAsync(n=null,t=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return $.clearTimeout(this.timeoutId),this.renewTokensPromise=Pe(this,!0,n,t),this.renewTokensPromise.finally(()=>{this.renewTokensPromise=null})}async destroyAsync(n){return await pn(this)(n)}async logoutSameTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_same_tab,{mmessage:"SessionMonitor",sub:t}))}async logoutOtherTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_another_tab,{message:"SessionMonitor",sub:t}))}async logoutAsync(n=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=An(this,K,this.getFetch(),console,this.location)(n,t),this.logoutPromise.finally(()=>{this.logoutPromise=null}))}};j.getOrCreate=(n,t)=>(s,o="default")=>Tn(n,t)(s,o),j.eventNames=p;let W=j;const M=class M{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,t){this._oidc.publishEvent(n,t)}static get(n="default"){return new M(W.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,t=null,s=!1,o=void 0,i=!1){return this._oidc.loginAsync(n,t,s,o,i)}logoutAsync(n=void 0,t=null){return this._oidc.logoutAsync(n,t)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null,t=null){return this._oidc.renewTokensAsync(n,t)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,t,s,o)}async getValidTokenAsync(n=200,t=50){const s=this._oidc,o={getTokens:()=>s.tokens,configuration:{token_automatic_renew_mode:s.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:s.configuration.refresh_time_before_tokens_expiration_in_second},syncTokensInfoAsync:async()=>{const{status:i}=await ce(s)(s.configuration,s.configurationName,s.tokens,!1);return i},renewTokensAsync:s.renewTokensAsync.bind(s)};return ge(o,n,t)}fetchWithTokens(n,t=!1){return Ce(n,this._oidc,t)}async userInfoAsync(n=!1,t=!1){return this._oidc.userInfoAsync(n,t)}userInfo(){return this._oidc.userInfo}};M.getOrCreate=(n,t=new R)=>(s,o="default")=>new M(W.getOrCreate(n,t)(s,o)),M.eventNames=W.eventNames;let fe=M;I.OidcClient=fe,I.OidcLocation=R,I.TokenAutomaticRenewMode=V,I.TokenRenewMode=q,I.getFetchDefault=xe,I.getParseQueryStringFromLocation=Q,I.getPath=gn,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
@@ -1 +1 @@
1
- {"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAE1B,mBAAmB,MAAM,EACzB,eAAe,iBAAiB,EAChC,cAAc,oBAAoB,MAGlC,SAAQ,SAAgB,EACxB,QAAO,MAAa,EACpB,QAAO,MAAa,KACnB,OAAO,CAAC,mBAAmB,CAsG7B,CAAC;AAEJ,eAAO,MAAM,uBAAuB,GAEhC,WAAM,EACN,sBAAiB,EACjB,eAAe,iBAAiB,EAChC,cAAc,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,EACnC,MAAM,GAAG,MAEV,SAAQ,SAAgB,EAAE,QAAO,MAAkB,qBA6CnD,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAE1B,mBAAmB,MAAM,EACzB,eAAe,iBAAiB,EAChC,cAAc,oBAAoB,MAGlC,SAAQ,SAAgB,EACxB,QAAO,MAAa,EACpB,QAAO,MAAa,KACnB,OAAO,CAAC,mBAAmB,CAyG7B,CAAC;AAEJ,eAAO,MAAM,uBAAuB,GAEhC,WAAM,EACN,sBAAiB,EACjB,eAAe,iBAAiB,EAChC,cAAc,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,EACnC,MAAM,GAAG,MAEV,SAAQ,SAAgB,EAAE,QAAO,MAAkB,qBA6CnD,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "7.26.5";
1
+ declare const _default: "7.26.7";
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.26.5",
3
+ "version": "7.26.7",
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.26.5"
23
+ "@axa-fr/oidc-client-service-worker": "7.26.7"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/dom": "10.4.1",
@@ -270,12 +270,16 @@ const synchroniseTokensAsync =
270
270
 
271
271
  if (loginParams && loginParams.extras) {
272
272
  for (const [key, value] of Object.entries(loginParams.extras)) {
273
- silentLoginInput[key] = value;
273
+ if (value != null) {
274
+ silentLoginInput[key] = value;
275
+ }
274
276
  }
275
277
  }
276
278
  if (extras) {
277
279
  for (const [key, value] of Object.entries(extras)) {
278
- silentLoginInput[key] = value;
280
+ if (value != null) {
281
+ silentLoginInput[key] = value;
282
+ }
279
283
  }
280
284
  }
281
285
  silentLoginInput['prompt'] = 'none';
@@ -45,6 +45,9 @@ export const _silentLoginAsync =
45
45
 
46
46
  if (extras != null) {
47
47
  for (const [key, value] of Object.entries(extras)) {
48
+ if (value == null) {
49
+ continue;
50
+ }
48
51
  if (queries === '') {
49
52
  queries = `?${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
50
53
  } else {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '7.26.5';
1
+ export default '7.26.7';