@axa-fr/oidc-client 7.29.7 → 7.30.0

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.
Files changed (72) hide show
  1. package/README.md +226 -0
  2. package/dist/events.d.ts +3 -0
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/fetch.d.ts +2 -2
  5. package/dist/fetch.d.ts.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1353 -873
  9. package/dist/index.umd.cjs +2 -2
  10. package/dist/initSession.d.ts +2 -0
  11. package/dist/initSession.d.ts.map +1 -1
  12. package/dist/initWorker.d.ts +1 -25
  13. package/dist/initWorker.d.ts.map +1 -1
  14. package/dist/jwt.d.ts.map +1 -1
  15. package/dist/legacyCompatibility.spec.d.ts +2 -0
  16. package/dist/legacyCompatibility.spec.d.ts.map +1 -0
  17. package/dist/login.d.ts +2 -1
  18. package/dist/login.d.ts.map +1 -1
  19. package/dist/logout.d.ts.map +1 -1
  20. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcServiceWorker.js +1049 -0
  21. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcTrustedDomains.js +31 -0
  22. package/dist/oidc.d.ts +6 -1
  23. package/dist/oidc.d.ts.map +1 -1
  24. package/dist/oidcClient.d.ts +13 -2
  25. package/dist/oidcClient.d.ts.map +1 -1
  26. package/dist/oidcError.d.ts +5 -0
  27. package/dist/oidcError.d.ts.map +1 -1
  28. package/dist/parseTokens.d.ts +10 -0
  29. package/dist/parseTokens.d.ts.map +1 -1
  30. package/dist/protocol.d.ts +7 -1
  31. package/dist/protocol.d.ts.map +1 -1
  32. package/dist/renewTokens.d.ts +0 -6
  33. package/dist/renewTokens.d.ts.map +1 -1
  34. package/dist/requests.d.ts +3 -3
  35. package/dist/requests.d.ts.map +1 -1
  36. package/dist/resourceParameters.d.ts +9 -0
  37. package/dist/resourceParameters.d.ts.map +1 -0
  38. package/dist/resourceTokens.d.ts +34 -0
  39. package/dist/resourceTokens.d.ts.map +1 -0
  40. package/dist/resourceTokens.spec.d.ts +2 -0
  41. package/dist/resourceTokens.spec.d.ts.map +1 -0
  42. package/dist/silentLogin.d.ts +2 -1
  43. package/dist/silentLogin.d.ts.map +1 -1
  44. package/dist/types.d.ts +28 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/version.d.ts +1 -1
  47. package/package.json +3 -3
  48. package/src/events.ts +3 -0
  49. package/src/fetch.ts +115 -15
  50. package/src/index.ts +4 -0
  51. package/src/initSession.ts +9 -0
  52. package/src/initWorker.ts +65 -13
  53. package/src/jwt.spec.ts +17 -0
  54. package/src/jwt.ts +4 -1
  55. package/src/legacyCompatibility.spec.ts +142 -0
  56. package/src/login.ts +91 -29
  57. package/src/logout.ts +36 -0
  58. package/src/oidc.ts +71 -20
  59. package/src/oidcClient.ts +48 -3
  60. package/src/oidcError.ts +7 -0
  61. package/src/parseTokens.ts +14 -1
  62. package/src/protocol.ts +16 -1
  63. package/src/renewTokens.ts +32 -16
  64. package/src/renewTokensError.spec.ts +111 -0
  65. package/src/requests.ts +13 -11
  66. package/src/resourceParameters.ts +85 -0
  67. package/src/resourceTokens.spec.ts +1271 -0
  68. package/src/resourceTokens.ts +708 -0
  69. package/src/silentLogin.spec.ts +87 -1
  70. package/src/silentLogin.ts +24 -22
  71. package/src/types.ts +34 -0
  72. package/src/version.ts +1 -1
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`oidc-client`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t={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`,loginCallbackAsync_navigated:`loginCallbackAsync_navigated`,loginCallbackAsync_navigation_error:`loginCallbackAsync_navigation_error`,logoutAsync_error:`logoutAsync_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`,userInfoAsync_error:`userInfoAsync_error`,apiRequest_error:`apiRequest_error`,syncTokensAsync_begin:`syncTokensAsync_begin`,syncTokensAsync_lock_not_available:`syncTokensAsync_lock_not_available`,syncTokensAsync_end:`syncTokensAsync_end`,syncTokensAsync_error:`syncTokensAsync_error`,tokensInvalidAndWaitingActionsToRefresh:`tokensInvalidAndWaitingActionsToRefresh`,loadingTimeout_error:`loadingTimeout_error`},n=(e,t,n)=>{n==null?delete e[t]:e[t]=JSON.stringify(n)},r=(e,t,n)=>{n==null?delete e[t]:e[t]=n},i=e=>{if(typeof e!=`string`||e===`undefined`||e===`null`||e===``)return null;try{return JSON.parse(e)}catch{return null}},a=(e,t=sessionStorage,a)=>{let o=a??t,s=r=>(n(t,`oidc.${e}`,{tokens:null,status:r}),delete t[`oidc.${e}.userInfo`],a&&a!==t&&(delete o[`oidc.login.${e}`],delete o[`oidc.state.${e}`],delete o[`oidc.code_verifier.${e}`],delete o[`oidc.nonce.${e}`]),Promise.resolve()),c=async()=>{let r=i(t[`oidc.${e}`]);return r?Promise.resolve({tokens:r.tokens,status:r.status}):(n(t,`oidc.${e}`,{tokens:null,status:null}),{tokens:null,status:null})},l=r=>{n(t,`oidc.${e}`,{tokens:r})},u=async n=>{r(t,`oidc.session_state.${e}`,n)},d=async()=>t[`oidc.session_state.${e}`],f=t=>{r(o,`oidc.nonce.${e}`,t?.nonce)},p=r=>{n(t,`oidc.jwk.${e}`,r)},m=()=>i(t[`oidc.jwk.${e}`]),h=async()=>({nonce:o[`oidc.nonce.${e}`]}),g=async n=>{r(t,`oidc.dpop_nonce.${e}`,n)},_=()=>t[`oidc.dpop_nonce.${e}`],v=()=>{let n=i(t[`oidc.${e}`]);return n?JSON.stringify({tokens:n.tokens}):null},y={};return{clearAsync:s,initAsync:c,setTokens:l,getTokens:v,setSessionStateAsync:u,getSessionStateAsync:d,setNonceAsync:f,getNonceAsync:h,setLoginParams:t=>{t==null?(delete y[e],delete o[`oidc.login.${e}`]):(y[e]=t,n(o,`oidc.login.${e}`,t))},getLoginParams:()=>{if(y[e])return y[e];let t=i(o[`oidc.login.${e}`]);return t===null?(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null):(y[e]=t,t)},getStateAsync:async()=>o[`oidc.state.${e}`],setStateAsync:async t=>{r(o,`oidc.state.${e}`,t)},getCodeVerifierAsync:async()=>o[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async t=>{r(o,`oidc.code_verifier.${e}`,t)},setDemonstratingProofOfPossessionNonce:g,getDemonstratingProofOfPossessionNonce:_,setDemonstratingProofOfPossessionJwkAsync:p,getDemonstratingProofOfPossessionJwkAsync:m}},o=2e3,s=console,c=class{constructor(e,t,n,r=o,i=!0){this._callback=e,this._client_id=t,this._url=n,this._interval=r||o,this._stopOnError=i;let a=n.indexOf(`/`,n.indexOf(`//`)+2);this._frame_origin=n.substring(0,a),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=n}load(){return new Promise(e=>{this._frame.onload=()=>{e()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener(`message`,this._boundMessageEvent,!1)})}_message(e){e.origin===this._frame_origin&&e.source===this._frame.contentWindow&&(e.data===`error`?(s.error(`CheckSessionIFrame: error message from check session op iframe`),this._stopOnError&&this.stop()):e.data===`changed`?(s.debug(e),s.debug(`CheckSessionIFrame: changed message from check session op iframe`),this.stop(),this._callback()):s.debug(`CheckSessionIFrame: `+e.data+` message from check session op iframe`))}start(e){s.debug(`CheckSessionIFrame.start :`+e),this.stop();let t=()=>{this._frame.contentWindow.postMessage(this._client_id+` `+e,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&=(s.debug(`CheckSessionIFrame.stop`),window.clearInterval(this._timer),null)}},l={LOGIN_REQUIRED:`LOGIN_REQUIRED`,CONSENT_REQUIRED:`CONSENT_REQUIRED`,INTERACTION_REQUIRED:`INTERACTION_REQUIRED`,OAUTH_ERROR:`OAUTH_ERROR`,TOKEN_REQUEST_FAILED:`TOKEN_REQUEST_FAILED`,SILENT_LOGIN_TIMEOUT:`SILENT_LOGIN_TIMEOUT`,INVALID_STATE:`INVALID_STATE`,INVALID_NONCE:`INVALID_NONCE`,DPOP_NONCE_REQUIRED:`DPOP_NONCE_REQUIRED`,NETWORK_ERROR:`NETWORK_ERROR`,STATE_MISSING:`STATE_MISSING`,STATE_MISMATCH:`STATE_MISMATCH`,NONCE_MISSING:`NONCE_MISSING`,ENDPOINT_UNAVAILABLE:`ENDPOINT_UNAVAILABLE`,REQUEST_FAILED:`REQUEST_FAILED`,INVALID_RESPONSE:`INVALID_RESPONSE`},u=new Set(Object.values(l)),d=new Set([`login`,`callback`,`refresh`,`logout`,`userinfo`,`api_request`]),f=class extends Error{constructor(e,t,n){super(t),this.name=`OidcError`,this.code=e,this.phase=n.phase,this.oauthError=n.oauthError,this.oauthErrorDescription=n.oauthErrorDescription,this.retryable=n.retryable,this.status=n.status,this.cause=n.cause,Object.setPrototypeOf(this,new.target.prototype)}},p=e=>e instanceof f,m=e=>e===408||e===429||e!==void 0&&e>=500,h=e=>{switch(e){case`login_required`:return l.LOGIN_REQUIRED;case`consent_required`:return l.CONSENT_REQUIRED;case`interaction_required`:return l.INTERACTION_REQUIRED;case`use_dpop_nonce`:return l.DPOP_NONCE_REQUIRED;default:return l.OAUTH_ERROR}},g=(e,t,n,r,i)=>{let a=h(e);return new f(a,n,{phase:r,retryable:a!==l.LOGIN_REQUIRED&&a!==l.CONSENT_REQUIRED&&a!==l.INTERACTION_REQUIRED&&(a===l.DPOP_NONCE_REQUIRED||e===`server_error`||e===`temporarily_unavailable`||m(i)),oauthError:e,oauthErrorDescription:t,status:i})},_=(e,t,n=`Network request failed`)=>{let r=e instanceof Error&&typeof e.message==`string`&&e.message?e.message:n;return new f(l.NETWORK_ERROR,r,{phase:t,retryable:!0,cause:e})},v=e=>e instanceof Error?e.name===`AbortError`||e.name===`NetworkError`||e.message===`Network request failed`||e.message===`Failed to fetch`||e.message===`fetch failed`:!1,y=e=>({name:e.name,message:e.message,code:e.code,phase:e.phase,retryable:e.retryable,oauthError:e.oauthError,oauthErrorDescription:e.oauthErrorDescription,status:e.status}),b=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.message!=`string`||typeof t.code!=`string`||!u.has(t.code)||typeof t.phase!=`string`||!d.has(t.phase)||typeof t.retryable!=`boolean`)return null;let n=new f(t.code,t.message,{phase:t.phase,retryable:t.retryable,oauthError:typeof t.oauthError==`string`?t.oauthError:void 0,oauthErrorDescription:typeof t.oauthErrorDescription==`string`?t.oauthErrorDescription:void 0,status:typeof t.status==`number`?t.status:void 0});return typeof t.name==`string`&&t.name&&(n.name=t.name),n},x=(function(){let e=typeof window>`u`?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}})(),S=(e,n,r,i=`login`)=>(a=null,o=null,s=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{r(t.silentLoginAsync_begin,{});let c=``;if(o&&(a??={},a.state=o),s!=null&&(a??={},a.scope=s),a!=null)for(let[e,t]of Object.entries(a))t!=null&&(c===``?c=`?${encodeURIComponent(e)}=${encodeURIComponent(t)}`:c+=`&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);let u=n.silent_login_uri+c,d=u.indexOf(`/`,u.indexOf(`//`)+2),p=u.substring(0,d),m=document.createElement(`iframe`);return m.width=`0px`,m.height=`0px`,m.id=`${e}_oidc_iframe`,m.setAttribute(`src`,u),m.style.display=`none`,document.body.appendChild(m),new Promise((a,o)=>{let s=!1,c=()=>{window.removeEventListener(`message`,u),m.remove(),s=!0},u=n=>{if(n.origin===p&&n.source===m.contentWindow){let l=`${e}_oidc_tokens:`,u=`${e}_oidc_error:`,d=`${e}_oidc_exception:`,f=n.data;if(f&&typeof f==`string`&&!s){if(f.startsWith(l)){let e=JSON.parse(n.data.replace(l,``));r(t.silentLoginAsync_end,{}),a(e),c()}else if(f.startsWith(u)){let e=JSON.parse(n.data.replace(u,``)),o=b(e.oidcError)??g(e.error,e.error_description,`Error from OIDC server: ${e.error} - ${e.error_description}`,i);r(t.silentLoginAsync_error,o),a({error:`oidc_`+e.error,tokens:null,sessionState:null,oidcError:o}),c()}else if(f.startsWith(d)){let e=JSON.parse(n.data.replace(d,``)),i=b(e.oidcError)??Error(e.error);r(t.silentLoginAsync_error,i),o(i),c()}}}};try{window.addEventListener(`message`,u);let e=n.silent_login_timeout;setTimeout(()=>{if(!s){c();let e=new f(l.SILENT_LOGIN_TIMEOUT,`timeout`,{phase:i,retryable:!0});r(t.silentLoginAsync_error,e),o(e)}},e)}catch(e){c(),r(t.silentLoginAsync_error,e),o(e)}})}catch(e){throw r(t.silentLoginAsync_error,e),e}},C=(e,n,r,i,a)=>(e=null,o=void 0)=>{e={...e};let s=(e,t,o)=>S(n,r,i.bind(a))(e,t,o);return(async()=>{a.timeoutId&&x.clearTimeout(a.timeoutId);let n;e&&`state`in e&&(n=e.state,delete e.state);try{let c=r.extras?{...r.extras,...e}:e,l=await s({...c,prompt:`none`},n,o);if(l)return a.tokens=l.tokens,i(t.token_acquired,{}),a.timeoutId=K(a,a.tokens.expiresAt,e,o),{}}catch(e){return e}})()},w=(e,t,n)=>(r,i,a,o=!1)=>{let s=(t,r=void 0,i=void 0)=>S(e.configurationName,n,e.publishEvent.bind(e))(t,r,i);return new Promise((l,u)=>{n.silent_login_uri&&n.silent_redirect_uri&&n.monitor_session&&r&&a&&!o?(e.checkSessionIFrame=new c(()=>{e.checkSessionIFrame.stop();let r=e.tokens;if(r===null)return;let i=r.idToken,a=r.idTokenPayload;return s({prompt:`none`,id_token_hint:i,scope:n.scope||`openid`}).then(t=>{if(t.error)throw Error(t.error);let n=t.tokens.idTokenPayload;if(a.sub===n.sub){let r=t.sessionState;e.checkSessionIFrame.start(t.sessionState),a.sid===n.sid?console.debug(`SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:`,r):console.debug(`SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:`,r)}else console.debug(`SessionMonitor._callback: Different subject signed into OP:`,n.sub)}).catch(async e=>{console.warn(`SessionMonitor._callback: Silent login failed, logging out other tabs:`,e);for(let[,e]of Object.entries(t))await e.logoutOtherTabAsync(n.client_id,a.sub)})},i,r),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(a),l(e.checkSessionIFrame)}).catch(e=>{u(e)})):l(null)})};function T(e){return new TextEncoder().encode(e)}function E(e){return btoa(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+/g,``)}function D(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))})}var O=e=>{let t=``;return e.forEach(function(e){t+=String.fromCharCode(e)}),E(t)};function k(e){return E(D(e))}var ee={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`},te={sign:e=>async(t,n,r,i,a=`dpop+jwt`)=>{switch(t=Object.assign({},t),n.typ=a,n.alg=i.jwtHeaderAlgorithm,n.alg){case`ES256`:n.jwk={kty:t.kty,crv:t.crv,x:t.x,y:t.y};break;case`RS256`:n.jwk={kty:t.kty,n:t.n,e:t.e,kid:n.kid};break;default:throw Error(`Unknown or not implemented JWS algorithm`)}let o={protected:k(JSON.stringify(n)),payload:k(JSON.stringify(r))},s=i.importKeyAlgorithm,c=await e.crypto.subtle.importKey(`jwk`,t,s,!0,[`sign`]),l=T(`${o.protected}.${o.payload}`),u=i.signAlgorithm,d=await e.crypto.subtle.sign(u,c,l);return o.signature=O(new Uint8Array(d)),`${o.protected}.${o.payload}.${o.signature}`}},ne={generate:e=>async t=>{let n=t,r=await e.crypto.subtle.generateKey(n,!0,[`sign`,`verify`]);return await e.crypto.subtle.exportKey(`jwk`,r.privateKey)},neuter:e=>{let t=Object.assign({},e);return delete t.d,t.key_ops=[`verify`],t}},re={thumbprint:e=>async(t,n)=>{let r;switch(t.kty){case`EC`:r=`{"crv":"CRV","kty":"EC","x":"X","y":"Y"}`.replace(`CRV`,t.crv).replace(`X`,t.x).replace(`Y`,t.y);break;case`RSA`:r=`{"e":"E","kty":"RSA","n":"N"}`.replace(`E`,t.e).replace(`N`,t.n);break;default:throw Error(`Unknown or not implemented JWK type`)}let i=await e.crypto.subtle.digest(n,T(r));return O(new Uint8Array(i))}},ie=e=>async t=>await ne.generate(e)(t),ae=e=>t=>async(n,r=`POST`,i,a={})=>{let o={jti:btoa(e.crypto.randomUUID()),htm:r,htu:i,iat:Math.round(Date.now()/1e3),...a},s=await re.thumbprint(e)(n,t.digestAlgorithm);return await te.sign(e)(n,{kid:s},o,t)},oe=()=>typeof globalThis<`u`?globalThis.crypto:void 0,se=()=>{let e=oe();return{hasCrypto:!!e,hasSubtleCrypto:!!e?.subtle}},ce=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,le=e=>{let t=[];for(let n=0;n<e.byteLength;n+=1){let r=e[n]%62;t.push(ce[r])}return t.join(``)},A=e=>{let t=new Uint8Array(e),n=oe();if(!n?.getRandomValues)throw Error(`Web Crypto API is unavailable; secure random values cannot be generated.`);return n.getRandomValues(t),le(t)};function ue(e){let t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}function de(e){return new Promise((t,n)=>{crypto.subtle.digest(`SHA-256`,ue(e)).then(e=>t(O(new Uint8Array(e))),e=>n(e))})}var fe=e=>{if(e.length<43||e.length>128)return Promise.reject(Error(`Invalid code length.`));let{hasSubtleCrypto:t}=se();return t?de(e):Promise.reject(Error(`window.crypto.subtle is unavailable.`))},pe=e=>!!(e.os===`iOS`&&e.osVersion.startsWith(`12`)||e.os===`Mac OS X`&&e.osVersion.startsWith(`10_15_6`)),me=e=>{let t=e.appVersion,n=e.userAgent,r=`-`,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(let e in i){let t=i[e];if(t.r.test(n)){r=t.s;break}}let a=`-`;switch(/Windows/.test(r)&&(a=/Windows (.*)/.exec(r)[1],r=`Windows`),r){case`Mac OS`:case`Mac OS X`:case`Android`:a=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(n)[1];break;case`iOS`:{let e=/OS (\d+)_(\d+)_?(\d+)?/.exec(t);e!=null&&e.length>2&&(a=e[1]+`.`+e[2]+`.`+(parseInt(e[3])|0));break}}return{os:r,osVersion:a}};function he(){let e=navigator.userAgent,t,n=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(n[1]))return t=/\brv[ :]+(\d+)/g.exec(e)||[],{name:`ie`,version:t[1]||``};if(n[1]===`Chrome`&&(t=e.match(/\bOPR|Edge\/(\d+)/),t!=null)){let n=t[1];if(!n){let r=e.split(t[0]+`/`);r.length>1&&(n=r[1])}return{name:`opera`,version:n}}return n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,`-?`],(t=e.match(/version\/(\d+)/i))!=null&&n.splice(1,1,t[1]),{name:n[0].toLowerCase(),version:n[1]}}var ge=()=>{let{name:e,version:t}=he();return e===`chrome`&&parseInt(t)<=70||e===`opera`&&(!t||parseInt(t.split(`.`)[0])<80)||e===`ie`?!1:!pe(me(navigator))},_e=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(t.tryKeepExistingSessionAsync_begin,{});try{let r=e.configuration,i=await e.initAsync(r.authority,r.authority_configuration);if(n=await $(r,e.configurationName),n){let{tokens:a}=await n.initAsync(i,`tryKeepExistingSessionAsync`,r);if(a){n.startKeepAliveServiceWorker(),e.tokens=a;let o=n.getLoginParams(e.configurationName);e.timeoutId=K(e,e.tokens.expiresAt,o.extras,o.scope);let s=await n.getSessionStateAsync();return await e.startCheckSessionAsync(i.checkSessionIframe,r.client_id,s),r.preload_user_info&&await e.userInfoAsync(),e.publishEvent(t.tryKeepExistingSessionAsync_end,{success:!0,message:`tokens inside ServiceWorker are valid`}),!0}e.publishEvent(t.tryKeepExistingSessionAsync_end,{success:!1,message:`no exiting session found`})}else{r.service_worker_relative_url&&e.publishEvent(t.service_worker_not_supported_by_browser,{message:`service worker is not supported by this browser`});let n=a(e.configurationName,r.storage??sessionStorage,r.login_state_storage??r.storage??sessionStorage),{tokens:o}=await n.initAsync();if(o){e.tokens=ot(o,null,r.token_renew_mode);let a=n.getLoginParams();e.timeoutId=K(e,e.tokens.expiresAt,a.extras,a.scope);let s=await n.getSessionStateAsync();return await e.startCheckSessionAsync(i.checkSessionIframe,r.client_id,s),r.preload_user_info&&await e.userInfoAsync(),e.publishEvent(t.tryKeepExistingSessionAsync_end,{success:!0,message:`tokens inside storage are valid`}),!0}}return e.publishEvent(t.tryKeepExistingSessionAsync_end,{success:!1,message:n?`service worker sessions not retrieved`:`session storage sessions not retrieved`}),!1}catch(r){return console.error(r),n&&await n.clearAsync(),e.publishEvent(t.tryKeepExistingSessionAsync_error,`tokens inside ServiceWorker are invalid`),!1}},j=class{open(e){window.location.href=e}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){let e=window.location;return e.pathname+(e.search||``)+(e.hash||``)}getOrigin(){return window.origin}},M={STATE_MISSING:`STATE_MISSING`,STATE_MISMATCH:`STATE_MISMATCH`,NONCE_MISSING:`NONCE_MISSING`},ve=new Set(Object.values(M)),ye=e=>typeof e==`string`&&ve.has(e),N=class e extends f{constructor(t,n,r=`callback`){super(t,n,{phase:r,retryable:!1}),this.name=`OidcStateError`,Object.setPrototypeOf(this,e.prototype)}},be=e=>e instanceof N||p(e)&&ye(e.code),P={ENDPOINT_UNAVAILABLE:`ENDPOINT_UNAVAILABLE`,REQUEST_FAILED:`REQUEST_FAILED`,INVALID_RESPONSE:`INVALID_RESPONSE`},F=class e extends f{constructor(t,n,r={}){super(t,n,{phase:`login`,retryable:r.cause!==void 0||m(r.status),status:r.status,oauthError:r.oauthError,oauthErrorDescription:r.oauthErrorDescription,cause:r.cause}),this.name=`PushedAuthorizationRequestError`,Object.setPrototypeOf(this,e.prototype)}},xe=e=>e instanceof F,I={},Se=(e,t=window.sessionStorage,n)=>{if(!I[e]&&t){let n=t.getItem(e);n&&(I[e]=JSON.parse(n))}let r=I[e],i=1e3*n;return r&&r.timestamp+i>Date.now()?r.result:null},Ce=(e,t,n=window.sessionStorage)=>{let r={result:t,timestamp:Date.now()};I[e]=r,n&&n.setItem(e,JSON.stringify(r))},we=3600,Te=e=>async(t,n=we,r=window.sessionStorage,i=1e4)=>{let a=`${t}/.well-known/openid-configuration`,o=`oidc.server:${t}`,s=Se(o,r,n);if(s)return new qe(s);let c=await L(e)(a,{},i);if(c.status!==200)return null;let l=await c.json();return Ce(o,l,r),new qe(l)},L=e=>async(t,n={},r=1e4,i=0)=>{let a;try{let i=new AbortController,o=setTimeout(()=>i.abort(),r);try{a=await e(t,{...n,signal:i.signal})}finally{clearTimeout(o)}}catch(a){if(a.name===`AbortError`||a.message===`Network request failed`){if(i<=1)return await L(e)(t,n,r,i+1);throw a}throw console.error(a.message),a}return a},Ee={refresh_token:`refresh_token`,access_token:`access_token`},R=e=>{let t=[];for(let n in e)t.push(`${encodeURIComponent(n)}=${encodeURIComponent(e[n])}`);return t.join(`&`)},De=e=>async(t,n,r=Ee.refresh_token,i,a={},o=1e4)=>{let s={token:n,token_type_hint:r,client_id:i};for(let[e,t]of Object.entries(a))s[e]===void 0&&(s[e]=t);let c=R(s),l=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`},body:c},o);if(l.status!==200){let e=await z(l);return{success:!1,status:l.status,oauthError:typeof e?.error==`string`?e.error:void 0,oauthErrorDescription:typeof e?.error_description==`string`?e.error_description:void 0}}return{success:!0,status:l.status}},z=async e=>{try{return await e.json()}catch{return null}},Oe=e=>async(t,n,r=1e4)=>{if(n.request_uri!==void 0)throw new F(P.REQUEST_FAILED,`The request_uri parameter must not be included in a pushed authorization request.`);let i=R(n),a;try{a=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`},body:i},r)}catch(e){throw new F(P.REQUEST_FAILED,`The pushed authorization request could not be sent.`,{cause:e})}let o=await z(a);if(a.status!==201){let e=typeof o?.error==`string`?o.error:void 0,t=typeof o?.error_description==`string`?o.error_description:void 0,n=[e,t].filter(Boolean).join(`: `);throw new F(P.REQUEST_FAILED,`The pushed authorization request failed with HTTP status ${a.status}${n?` (${n})`:``}.`,{status:a.status,oauthError:e,oauthErrorDescription:t})}if(typeof o?.request_uri!=`string`||o.request_uri.length===0||!Number.isInteger(o?.expires_in)||o.expires_in<=0)throw new F(P.INVALID_RESPONSE,`The pushed authorization response must contain a non-empty request_uri and a positive integer expires_in.`,{status:a.status});return{request_uri:o.request_uri,expires_in:o.expires_in}},ke=e=>async(t,n,r,i,a={},o,s=1e4)=>{for(let[e,t]of Object.entries(r))n[e]===void 0&&(n[e]=t);let c=R(n),l=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`,...a},body:c},s);if(l.status!==200){let e=await z(l);return{success:!1,status:l.status,data:e,oauthError:typeof e?.error==`string`?e.error:void 0,oauthErrorDescription:typeof e?.error_description==`string`?e.error_description:void 0,demonstratingProofOfPossessionNonce:l.headers?.has(B)?l.headers.get(B):null}}let u=await l.json(),d=null;return l.headers.has(B)&&(d=l.headers.get(B)),{success:!0,status:l.status,data:st(u,i,o),demonstratingProofOfPossessionNonce:d}},Ae=(e,t)=>async(n,r,i)=>{r=r?{...r}:{};let a=A(128),o=await fe(a);if(await e.setCodeVerifierAsync(a),await e.setStateAsync(r.state),r.code_challenge=o,r.code_challenge_method=`S256`,i){let e=await Oe(i.fetch)(i.endpoint,r,i.timeoutMs);t.open(`${n}?client_id=${encodeURIComponent(r.client_id)}&request_uri=${encodeURIComponent(e.request_uri)}`);return}let s=``;if(r)for(let[e,t]of Object.entries(r))s+=s===``?`?`:`&`,s+=`${e}=${encodeURIComponent(t)}`;t.open(`${n}${s}`)},B=`DPoP-Nonce`,je=e=>async(t,n,r,i,a=1e4,o=!1)=>{n=n?{...n}:{},n.code_verifier=await e.getCodeVerifierAsync();let s=R(n),c=await L(fetch)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`,...r},body:s},a);if(c.status!==200){let t=await z(c),n=typeof t?.error==`string`?t.error:void 0;return o&&n===`use_dpop_nonce`||await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),{success:!1,status:c.status,data:t,oauthError:n,oauthErrorDescription:typeof t?.error_description==`string`?t.error_description:void 0,demonstratingProofOfPossessionNonce:c.headers?.has(B)?c.headers.get(B):null}}await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]);let l=null;c.headers.has(B)&&(l=c.headers.get(B));let u=await c.json();return{success:!0,data:{state:n.state,tokens:st(u,null,i),demonstratingProofOfPossessionNonce:l}}},Me=e=>{let t=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!t)throw Error(`Invalid URL`);let n=t[6],r=t[7];if(r){let e=r.split(`?`);e.length===2&&(r=e[0],n=e[1])}return n.startsWith(`?`)&&(n=n.slice(1)),{href:e,protocol:t[1],host:t[2],hostname:t[3],port:t[4],path:t[5],search:n,hash:r}},Ne=e=>{let t=Me(e),{path:n}=t;n.endsWith(`/`)&&(n=n.slice(0,-1));let{hash:r}=t;return(r===`#`||r===`#_=_`)&&(r=``),r&&(n+=r),n},V=e=>{let{search:t}=Me(e);return Pe(t)},Pe=e=>{let t={};for(let n of e.split(`&`)){let[e,r]=n.split(`=`);t[decodeURIComponent(e)]=decodeURIComponent(r)}return t},Fe=(e,n,r,i,o,s=()=>window.fetch)=>(c=void 0,l=null,u=!1,d=void 0)=>{let f=l;return l={...l},(async()=>{let p=c||o.getPath();if(`state`in l||(l.state=A(16)),r(t.loginAsync_begin,{}),l)for(let e of Object.keys(l))e.endsWith(`:token_request`)&&delete l[e];try{let t=u?n.silent_redirect_uri:n.redirect_uri;d||=n.scope;let r=n.extras?{...n.extras,...l}:l;r.nonce||=A(12);let c={nonce:r.nonce},m=await $(n,e),h=await i(n.authority,n.authority_configuration),g;if(m)m.setLoginParams({callbackPath:p,extras:f,scope:d}),await m.initAsync(h,`loginAsync`,n),await m.setNonceAsync(c),m.startKeepAliveServiceWorker(),g=m;else{let t=a(e,n.storage??sessionStorage,n.login_state_storage??n.storage??sessionStorage);t.setLoginParams({callbackPath:p,extras:f,scope:d}),await t.setNonceAsync(c),g=t}let _={client_id:n.client_id,redirect_uri:t,scope:d,response_type:`code`,...r},v=n.par??`disabled`,y=h.pushedAuthorizationRequestEndpoint,b=h.requirePushedAuthorizationRequests;if(!y&&(v===`required`||v===`auto`&&b))throw new F(P.ENDPOINT_UNAVAILABLE,`Pushed Authorization Requests are required, but the authorization server metadata does not provide a pushed_authorization_request_endpoint.`);let x=v!==`disabled`&&y?{endpoint:y,fetch:s(),timeoutMs:n.par_request_timeout}:void 0;await Ae(g,o)(h.authorizationEndpoint,_,x)}catch(e){let n=v(e)?_(e,`login`):e;throw r(t.loginAsync_error,n),n}})()},Ie=e=>async(n=!1)=>{try{e.publishEvent(t.loginCallbackAsync_begin,{});let r=e.configuration,i=r.client_id,o=n?r.silent_redirect_uri:r.redirect_uri,s=r.authority,c=r.token_request_timeout,u=await e.initAsync(s,r.authority_configuration),d=V(e.location.getCurrentHref()),p=d.session_state,h=await $(r,e.configurationName),_,v,y,b;if(h)await h.initAsync(u,`loginCallbackAsync`,r),await h.setSessionStateAsync(p),v=await h.getNonceAsync(),y=h.getLoginParams(),b=await h.getStateAsync(),h.startKeepAliveServiceWorker(),_=h;else{let t=a(e.configurationName,r.storage??sessionStorage,r.login_state_storage??r.storage??sessionStorage);await t.setSessionStateAsync(p),v=await t.getNonceAsync(),y=t.getLoginParams(),b=await t.getStateAsync(),_=t}if(d.error||d.error_description)throw g(d.error,d.error_description,`Error from OIDC server: ${d.error} - ${d.error_description}`,n?`refresh`:`callback`);if(d.iss&&d.iss!==u.issuer)throw console.error(),Error(`Issuer not valid (expected: ${u.issuer}, received: ${d.iss})`);if(d.state){if(!b)throw new N(M.STATE_MISSING,`OIDC state is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).`,n?`refresh`:`callback`);if(d.state!==b)throw new N(M.STATE_MISMATCH,`OIDC state does not match the stored one (expected: ${b}, received: ${d.state}).`,n?`refresh`:`callback`)}if(!v||!v.nonce)throw new N(M.NONCE_MISSING,`OIDC nonce is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).`,n?`refresh`:`callback`);let x={code:d.code,grant_type:`authorization_code`,client_id:r.client_id,redirect_uri:o},S={};if(r.token_request_extras)for(let[e,t]of Object.entries(r.token_request_extras))S[e]=t;if(y?.extras)for(let[e,t]of Object.entries(y.extras))e.endsWith(`:token_request`)&&(S[e.replace(`:token_request`,``)]=t);let C=u.tokenEndpoint,w={},T;r.demonstrating_proof_of_possession&&(h?w.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`:(T=await ie(window)(r.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm),await a(e.configurationName,r.storage,r.login_state_storage??r.storage).setDemonstratingProofOfPossessionJwkAsync(T),w.DPoP=await ae(window)(r.demonstrating_proof_of_possession_configuration)(T,`POST`,C)));let E=await je(_)(C,{...x,...S},w,e.configuration.token_renew_mode,c,r.demonstrating_proof_of_possession);if(!E.success&&E.oauthError===`use_dpop_nonce`&&E.demonstratingProofOfPossessionNonce&&r.demonstrating_proof_of_possession?(await _.setDemonstratingProofOfPossessionNonce(E.demonstratingProofOfPossessionNonce),h||(w.DPoP=await ae(window)(r.demonstrating_proof_of_possession_configuration)(T,`POST`,C,{nonce:E.demonstratingProofOfPossessionNonce})),E=await je(_)(C,{...x,...S},w,e.configuration.token_renew_mode,c)):!E.success&&r.demonstrating_proof_of_possession&&await Promise.all([_.setCodeVerifierAsync(null),_.setStateAsync(null)]),!E.success){let e=E.oauthError===`use_dpop_nonce`?l.DPOP_NONCE_REQUIRED:l.TOKEN_REQUEST_FAILED;throw new f(e,`Token request failed`,{phase:n?`refresh`:`callback`,retryable:e===l.DPOP_NONCE_REQUIRED||m(E.status),status:E.status,oauthError:E.oauthError,oauthErrorDescription:E.oauthErrorDescription})}let D,O=E.data.tokens,k=E.data.demonstratingProofOfPossessionNonce;if(E.data.state!==S.state)throw new f(l.INVALID_STATE,`state is not valid`,{phase:n?`refresh`:`callback`,retryable:!1});let{isValid:ee,reason:te}=ut(O,v.nonce,u);if(!ee){let e=`Tokens are not OpenID valid, reason: ${te}`;throw te.startsWith(`Nonce does not match`)?new f(l.INVALID_NONCE,e,{phase:n?`refresh`:`callback`,retryable:!1}):Error(e)}if(h){if(O.refreshToken&&!O.refreshToken.includes(`SECURED_BY_OIDC_SERVICE_WORKER`))throw Error(`Refresh token should be hidden by service worker`);if(k&&O?.accessToken.includes(`SECURED_BY_OIDC_SERVICE_WORKER`))throw Error(`Demonstration of proof of possession require Access token not hidden by service worker`)}if(h)await h.initAsync(u,`syncTokensAsync`,r),D=h.getLoginParams(),k&&await h.setDemonstratingProofOfPossessionNonce(k);else{let t=a(e.configurationName,r.storage,r.login_state_storage??r.storage);D=t.getLoginParams(),k&&await t.setDemonstratingProofOfPossessionNonce(k)}return await e.startCheckSessionAsync(u.checkSessionIframe,i,p,n),e.publishEvent(t.loginCallbackAsync_end,{}),{tokens:O,state:`request.state`,callbackPath:D.callbackPath,scope:d.scope,extras:D.extras}}catch(r){let i=!p(r)&&v(r)?_(r,n?`refresh`:`callback`):r;throw console.error(i),e.publishEvent(t.loginCallbackAsync_error,i),i}},Le={access_token:`access_token`,refresh_token:`refresh_token`},Re=(e,t)=>{let n={};if(e){for(let[r,i]of Object.entries(e))if(r.endsWith(t)){let e=r.replace(t,``);n[e]=i}return n}return n},ze=e=>{let t={};if(e){for(let[n,r]of Object.entries(e))n.includes(`:`)||(t[n]=r);return t}return t},Be=e=>async t=>{x.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();let n=await $(e.configuration,e.configurationName);n?await n.clearAsync(t):await a(e.configurationName,e.configuration.storage,e.configuration.login_state_storage??e.configuration.storage).clearAsync(t),e.tokens=null,e.userInfo=null},Ve=(e,n)=>async()=>{let r=e.tokens?.idTokenPayload?.sub??null;await e.destroyAsync(`LOGGED_OUT`);for(let[,i]of Object.entries(n))i===e?e.publishEvent(t.logout_from_same_tab,{}):await e.logoutSameTabAsync(e.configuration.client_id,r)},He=(e,t,n,r)=>{`id_token_hint`in t||(t.id_token_hint=n),!(`post_logout_redirect_uri`in t)&&r!==null&&(t.post_logout_redirect_uri=r);let i=``;for(let[e,n]of Object.entries(t))n!=null&&(i+=i===``?`?`:`&`,i+=`${e}=${encodeURIComponent(n)}`);return`${e}${i}`},Ue=(e,n,r,i,a)=>async(o=void 0,s=null)=>{let c=e.configuration,u;try{u=await e.initAsync(c.authority,c.authority_configuration)}catch(n){let r=v(n)?_(n,`logout`):n;throw e.publishEvent(t.logoutAsync_error,r),r}o&&typeof o!=`string`&&(o=void 0,i.warn(`callbackPathOrUrl path is not a string`));let d=o??a.getPath(),h=!1;o&&(h=o.includes(`https://`)||o.includes(`http://`));let g=o===null?null:h?o:a.getOrigin()+d,y=e.tokens?e.tokens.idToken:``;e.isLoggingOut=!0;try{try{let n=u.revocationEndpoint;if(n){let i=[],a=e.tokens?e.tokens.accessToken:null;if(a&&c.logout_tokens_to_invalidate.includes(Le.access_token)){let e=Re(s,`:revoke_access_token`),t=De(r)(n,a,Ee.access_token,c.client_id,e);i.push(t)}let o=e.tokens?e.tokens.refreshToken:null;if(o&&c.logout_tokens_to_invalidate.includes(Le.refresh_token)){let e=Re(s,`:revoke_refresh_token`),t=De(r)(n,o,Ee.refresh_token,c.client_id,e);i.push(t)}if(i.length>0){let n=await Promise.all(i);for(let r of n)r.success||e.publishEvent(t.logoutAsync_error,new f(l.REQUEST_FAILED,`Token revocation request failed`,{phase:`logout`,retryable:m(r.status),status:r.status,oauthError:r.oauthError,oauthErrorDescription:r.oauthErrorDescription}))}}}catch(n){let r=!p(n)&&v(n)?_(n,`logout`):n;e.publishEvent(t.logoutAsync_error,r),i.warn(`logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error`),i.warn(r)}let o=Re(s,`:oidc`);if(o&&o.no_reload===`true`){await Ve(e,n)(),e.isLoggingOut=!1;return}let d=ze(s);if(u.endSessionEndpoint){let e=He(u.endSessionEndpoint,d,y,g);a.open(e)}else a.reload();await Ve(e,n)()}catch(n){e.isLoggingOut=!1;let r=!p(n)&&v(n)?_(n,`logout`):n;throw e.publishEvent(t.logoutAsync_error,r),r}},H=function(e){return e.AutomaticBeforeTokenExpiration=`AutomaticBeforeTokensExpiration`,e.AutomaticOnlyWhenFetchExecuted=`AutomaticOnlyWhenFetchExecuted`,e}({}),We=(e,n,r=!1,i=`api_request`)=>async(...a)=>{let[o,s,...c]=a,u=s?{...s}:{method:`GET`},d=new Headers;u.headers&&(d=u.headers instanceof Headers?u.headers:new Headers(u.headers));let p=(await lt({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()=>{let{status:e}=await $e(n)(n.configuration,n.configurationName,n.tokens,!1);return e},renewTokensAsync:n.renewTokensAsync.bind(n)}))?.tokens?.accessToken;if(d.has(`Accept`)||d.set(`Accept`,`application/json`),p){if(n.configuration.demonstrating_proof_of_possession&&r){let e=await n.generateDemonstrationOfProofOfPossessionAsync(p,o.toString(),u.method);d.set(`Authorization`,`DPoP ${p}`),d.set(`DPoP`,e)}else d.set(`Authorization`,`Bearer ${p}`);u.credentials||=`same-origin`}let m={...u,headers:d},h;try{h=await e(o,m,...c)}catch(e){let r=_(e,i);throw i===`api_request`&&n.publishEvent(t.apiRequest_error,r),r}if(!h.ok&&h.headers?.has(`DPoP-Nonce`)&&(h.status===400||h.status===401||h.headers.get(`WWW-Authenticate`)?.includes(`use_dpop_nonce`))){let e=new f(l.DPOP_NONCE_REQUIRED,`DPoP nonce required`,{phase:i,retryable:!0,status:h.status,oauthError:`use_dpop_nonce`});i===`api_request`&&n.publishEvent(t.apiRequest_error,e)}return h},Ge=e=>async(n=!1,r=!1)=>{try{if(e.userInfo!=null&&!n)return e.userInfo;let i=!n&&e.configuration.storage?.getItem(`oidc.${e.configurationName}.userInfo`);if(i)return e.userInfo=JSON.parse(i),e.userInfo;let a=e.configuration,o=(await e.initAsync(a.authority,a.authority_configuration)).userInfoEndpoint,s=await(async()=>{let n=await We(fetch,e,r,`userinfo`)(o);if(n.status!==200){let r=n.headers?.has(`DPoP-Nonce`)&&(n.status===400||n.status===401||n.headers.get(`WWW-Authenticate`)?.includes(`use_dpop_nonce`)),i=new f(r?l.DPOP_NONCE_REQUIRED:l.REQUEST_FAILED,`UserInfo request failed`,{phase:`userinfo`,retryable:r||m(n.status),status:n.status,oauthError:r?`use_dpop_nonce`:void 0});return e.publishEvent(t.userInfoAsync_error,i),null}return n.json()})();return e.userInfo=s,s&&e.configuration.storage?.setItem(`oidc.${e.configurationName}.userInfo`,JSON.stringify(s)),s}catch(n){let r=p(n)?n:v(n)?_(n,`userinfo`):n;throw e.publishEvent(t.userInfoAsync_error,r),r}},Ke=()=>fetch,qe=class{constructor(e){this.authorizationEndpoint=e.authorization_endpoint,this.tokenEndpoint=e.token_endpoint,this.revocationEndpoint=e.revocation_endpoint,this.userInfoEndpoint=e.userinfo_endpoint,this.checkSessionIframe=e.check_session_iframe,this.issuer=e.issuer,this.endSessionEndpoint=e.end_session_endpoint,this.pushedAuthorizationRequestEndpoint=e.pushed_authorization_request_endpoint,this.requirePushedAuthorizationRequests=e.require_pushed_authorization_requests??!1}},U={},Je=(e,t=new j)=>(n,r=`default`)=>(U[r]||(U[r]=new W(n,r,e,t)),U[r]),Ye=async e=>{let{parsedTokens:t,callbackPath:n,extras:r,scope:i}=await e.loginCallbackAsync();return e.timeoutId=K(e,t.expiresAt,r,i),{callbackPath:n}},W=class e{constructor(e,t=`default`,n,r=new j){this.isLoggingOut=!1,this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.clearSessionPromise=null,this.logoutPromise=null;let i=e.silent_login_uri;e.silent_redirect_uri&&!e.silent_login_uri&&(i=`${e.silent_redirect_uri.replace(`-callback`,``).replace(`callback`,``)}-login`);let a=e.refresh_time_before_tokens_expiration_in_second??120;a>60&&(a-=Math.floor(Math.random()*40)),this.location=r??new j,this.configuration={...e,silent_login_uri:i,token_automatic_renew_mode:e.token_automatic_renew_mode??H.AutomaticBeforeTokenExpiration,monitor_session:e.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:a,silent_login_timeout:e.silent_login_timeout??12e3,token_renew_mode:e.token_renew_mode??it.access_token_or_id_token_invalid,demonstrating_proof_of_possession:e.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:e.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:e.logout_tokens_to_invalidate??[`access_token`,`refresh_token`],service_worker_activate:e.service_worker_activate??ge,demonstrating_proof_of_possession_configuration:e.demonstrating_proof_of_possession_configuration??ee,preload_user_info:e.preload_user_info??!1,par:e.par??`disabled`,par_request_timeout:e.par_request_timeout??1e4},this.getFetch=n??Ke,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.renewTokensOrThrowAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(e){let t=A(16);return this.events.push({id:t,func:e}),t}removeEventSubscription(e){let t=this.events.filter(t=>t.id!==e);this.events=t}publishEvent(e,t){this.events.forEach(n=>{n.func(e,t)})}static{this.getOrCreate=(e,t)=>(n,r=`default`)=>Je(e,t)(n,r)}static get(e=`default`){return Object.prototype.hasOwnProperty.call(U,e)?U[e]:null}static getOrThrow(t=`default`){let n=e.get(t);if(!n)throw Error(`OIDC library does seem initialized.
2
- Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${t}"></OidcProvider> component.`);return n}static{this.eventNames=t}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){let e=this.location,t=V(e.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,e.getOrigin())}}_silentLoginErrorCallbackFromIFrame(e=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){let t=this.location,n=V(t.getCurrentHref());if(n.error){let e=g(n.error,n.error_description,`Error from OIDC server: ${n.error} - ${n.error_description}`,`refresh`);window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:n.error,error_description:n.error_description,oidcError:y(e)})}`,t.getOrigin())}else window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:e==null?``:e.toString(),oidcError:p(e)?y(e):void 0})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(e){console.error(e),this._silentLoginErrorCallbackFromIFrame(e)}}async initAsync(e,t){if(this.initPromise!==null)return this.initPromise;let n=async()=>{if(t!=null)return new qe({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,pushed_authorization_request_endpoint:t.pushed_authorization_request_endpoint,require_pushed_authorization_requests:t.require_pushed_authorization_requests});let n=await $(this.configuration,this.configurationName)?this.configuration.storage||window.sessionStorage:this.configuration.storage;return await Te(this.getFetch())(e,this.configuration.authority_time_cache_wellknowurl_in_second??3600,n,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=n(),this.initPromise.finally(()=>{this.initPromise=null})}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise===null?(this.tryKeepExistingSessionPromise=_e(this),this.tryKeepExistingSessionPromise.finally(()=>{this.tryKeepExistingSessionPromise=null})):this.tryKeepExistingSessionPromise}async startCheckSessionAsync(e,t,n,r=!1){await w(this,U,this.configuration)(e,t,n,r)}async loginAsync(e=void 0,t=null,n=!1,r=void 0,i=!1){return this.logoutPromise&&await this.logoutPromise,this.loginPromise===null?(this.loginPromise=i?C(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,r):Fe(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location,this.getFetch)(e,t,n,r),this.loginPromise.finally(()=>{this.loginPromise=null})):this.loginPromise}async loginCallbackAsync(t=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;let n=async()=>{let n=await Ie(this)(t),r=n.tokens;return this.tokens=r,await $(this.configuration,this.configurationName)||a(this.configurationName,this.configuration.storage,this.configuration.login_state_storage??this.configuration.storage).setTokens(r),this.publishEvent(e.eventNames.token_acquired,r),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:r,state:n.state,callbackPath:n.callbackPath,scope:n.scope,extras:n.extras}};return this.loginCallbackPromise=n(),this.loginCallbackPromise.finally(()=>{this.loginCallbackPromise=null})}async generateDemonstrationOfProofOfPossessionAsync(e,t,n,r={}){let i=this.configuration,o={ath:await de(e),...r};if(await $(i,this.configurationName))return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${ht(this.configurationName)}`;let s=a(this.configurationName,i.storage,i.login_state_storage??i.storage),c=await s.getDemonstratingProofOfPossessionJwkAsync(),l=s.getDemonstratingProofOfPossessionNonce();return l&&(o.nonce=l),await ae(window)(i.demonstrating_proof_of_possession_configuration)(c,n,t,o)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise===null?(this.loginCallbackWithAutoTokensRenewPromise=Ye(this),this.loginCallbackWithAutoTokensRenewPromise.finally(()=>{this.loginCallbackWithAutoTokensRenewPromise=null})):this.loginCallbackWithAutoTokensRenewPromise}userInfoAsync(e=!1,t=!1){return this.userInfoPromise===null?(this.userInfoPromise=Ge(this)(e,t),this.userInfoPromise.finally(()=>{this.userInfoPromise=null})):this.userInfoPromise}async renewTokensResultAsync(e=null,t=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(!this.timeoutId)return null;x.clearTimeout(this.timeoutId);let n=Ze(this,!0,e,t);return this.renewTokensPromise=n,n.finally(()=>{this.renewTokensPromise===n&&(this.renewTokensPromise=null)})}async renewTokensAsync(e=null,t=null){return(await this.renewTokensResultAsync(e,t))?.tokens}async renewTokensOrThrowAsync(e=null,t=null){let n=await this.renewTokensResultAsync(e,t);if(n?.error)throw n.error;if(!n?.tokens)throw new f(l.TOKEN_REQUEST_FAILED,`Token renewal failed`,{phase:`refresh`,retryable:!1});return n.tokens}async destroyAsync(e){return await Be(this)(e)}async clearSessionAsync(){return this.clearSessionPromise?this.clearSessionPromise:(this.clearSessionPromise=Ve(this,U)(),this.clearSessionPromise.finally(()=>{this.clearSessionPromise=null}))}async logoutSameTabAsync(e,n){this.configuration.monitor_session&&this.configuration.client_id===e&&n&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===n&&(await this.destroyAsync(`LOGGED_OUT`),this.publishEvent(t.logout_from_same_tab,{mmessage:`SessionMonitor`,sub:n}))}async logoutOtherTabAsync(e,n){this.configuration.monitor_session&&this.configuration.client_id===e&&n&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===n&&(await this.destroyAsync(`LOGGED_OUT`),this.publishEvent(t.logout_from_another_tab,{message:`SessionMonitor`,sub:n}))}async logoutAsync(e=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=Ue(this,U,this.getFetch(),console,this.location)(e,t),this.logoutPromise.finally(()=>{this.logoutPromise=null}))}},G=(e,t)=>{let n=t?.oauthError===`use_dpop_nonce`?l.DPOP_NONCE_REQUIRED:l.TOKEN_REQUEST_FAILED;return new f(n,e,{phase:`refresh`,retryable:n===l.DPOP_NONCE_REQUIRED||m(t?.status),status:t?.status,oauthError:t?.oauthError,oauthErrorDescription:t?.oauthErrorDescription})};async function Xe(e,t,n,r=null){let i=await et(e)(t=>{e.tokens=t},0,0,t,n,r),{tokens:o,status:s}=i;return await $(e.configuration,e.configurationName)||a(e.configurationName,e.configuration.storage,e.configuration.login_state_storage??e.configuration.storage).setTokens(e.tokens),e.tokens?{...i,tokens:o}:(await e.destroyAsync(s),{...i,tokens:null})}async function Ze(e,t=!1,n=null,r=null){let i=e.configuration,a=`${i.client_id}_${e.configurationName}_${i.authority}`,o,s=await $(e.configuration,e.configurationName);if(i?.storage===window?.sessionStorage&&!s||!navigator.locks)o=await Xe(e,t,n,r);else{let i=`retry`;for(;i===`retry`;)i=await navigator.locks.request(a,{ifAvailable:!0},async i=>i?await Xe(e,t,n,r):(e.publishEvent(W.eventNames.syncTokensAsync_lock_not_available,{lock:`lock not available`}),`retry`));o=i}return o.tokens?(e.timeoutId&&=K(e,e.tokens.expiresAt,n,r),{...o,tokens:e.tokens}):o}async function Qe(e,t=!1,n=null,r=null){return(await Ze(e,t,n,r)).tokens}var K=(e,t,n=null,r=null)=>{let i=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&x.clearTimeout(e.timeoutId),x.setTimeout(async()=>{let a={timeLeft:J(i,t)};e.publishEvent(W.eventNames.token_timer,a),await Qe(e,!1,n,r)},1e3)},q={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`},$e=e=>async(t,n,r,i=!1)=>{let o={nonce:null};if(!r)return{tokens:null,status:q.NOT_CONNECTED,nonce:o};let s,c=await e.initAsync(t.authority,t.authority_configuration),l=await $(t,n);if(l){let{status:e,tokens:n}=await l.initAsync(c,`syncTokensAsync`,t);if(e===`LOGGED_OUT`)return{tokens:null,status:q.LOGOUT_FROM_ANOTHER_TAB,nonce:o};if(e===`SESSIONS_LOST`)return{tokens:null,status:q.SESSION_LOST,nonce:o};if(!e||!n)return{tokens:null,status:q.REQUIRE_SYNC_TOKENS,nonce:o};if(n.issuedAt!==r.issuedAt)return{tokens:n,status:J(t.refresh_time_before_tokens_expiration_in_second,n.expiresAt)>0?q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,nonce:await l.getNonceAsync()};s=await l.getNonceAsync()}else{let i=a(n,t.storage??sessionStorage,t.login_state_storage??t.storage??sessionStorage),c=await i.initAsync(),{tokens:l}=c,{status:u}=c;if(l&&=ot(l,e.tokens,t.token_renew_mode),!l)return{tokens:null,status:q.LOGOUT_FROM_ANOTHER_TAB,nonce:o};if(u===`SESSIONS_LOST`)return{tokens:null,status:q.SESSION_LOST,nonce:o};if(l.issuedAt!==r.issuedAt){let e=J(t.refresh_time_before_tokens_expiration_in_second,l.expiresAt)>0?q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,n=await i.getNonceAsync();return{tokens:l,status:e,nonce:n}}s=await i.getNonceAsync()}let u=J(t.refresh_time_before_tokens_expiration_in_second,r.expiresAt)>0?`TOKENS_VALID`:`TOKENS_INVALID`;return i?{tokens:r,status:`FORCE_REFRESH`,nonce:s}:{tokens:r,status:u,nonce:s}},et=e=>async(n,r=0,i=0,o=!1,s=null,c=null,u=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:`GIVE_UP`};let d=6,m=o?2:5;for(;!navigator.onLine&&d>0;)await Y({milliseconds:1e3}),d--,e.publishEvent(t.refreshTokensAsync,{message:`wait because navigator is offline try ${d}`});let h=document.hidden,g=h?r:r+1,y=h?i+1:i;if(r>=m||i>=5){n(null);let r=u??G(`refresh token`);return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}s||={};let b=e.configuration,x=(t,n=null,r=null)=>S(e.configurationName,e.configuration,e.publishEvent.bind(e),`refresh`)(t,n,r),C=async()=>{try{let r,i=await $(b,e.configurationName);r=i?i.getLoginParams():a(e.configurationName,b.storage,b.login_state_storage??b.storage).getLoginParams();let o={};if(r&&r.extras)for(let[e,t]of Object.entries(r.extras))t!=null&&(o[e]=t);if(s)for(let[e,t]of Object.entries(s))t!=null&&(o[e]=t);o.prompt=`none`,c&&(o.scope=c);let u=await x(o);if(!u){n(null);let r=G(`refresh token silent not active`);return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token silent not active`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}if(u.error){n(null);let r=u.oidcError??new f(l.OAUTH_ERROR,`refresh token silent`,{phase:`refresh`,retryable:!1,oauthError:u.error});return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token silent`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}return n(u.tokens),e.publishEvent(W.eventNames.token_renewed,{}),{tokens:u.tokens,status:`LOGGED`}}catch(r){let i=p(r)||!v(r)?r:_(r,`refresh`);return console.error(i),e.publishEvent(t.refreshTokensAsync_silent_error,{message:`exceptionSilent`,exception:i.message,error:p(i)?i:void 0}),await et(e)(n,g,y,o,s,c,p(i)?i:u)}};try{let{status:d,tokens:p,nonce:m}=await $e(e)(b,e.configurationName,e.tokens,o);switch(d){case q.SESSION_LOST:n(null);{let n=u??G(`refresh token session lost`);return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token session lost`,error:n}),{tokens:null,status:`SESSION_LOST`,error:n}}case q.NOT_CONNECTED:return n(null),{tokens:null,status:null};case q.TOKENS_VALID:return n(p),{tokens:p,status:`LOGGED_IN`};case q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(p),e.publishEvent(W.eventNames.token_renewed,{reason:`TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID`}),{tokens:p,status:`LOGGED_IN`};case q.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(t.logout_from_another_tab,{status:`session syncTokensAsync`}),{tokens:null,status:`LOGGED_OUT`};case q.REQUIRE_SYNC_TOKENS:return b.token_automatic_renew_mode==H.AutomaticOnlyWhenFetchExecuted&&!o?(e.publishEvent(t.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:`GIVE_UP`}):(e.publishEvent(t.refreshTokensAsync_begin,{tryNumber:r}),await C());default:{if(b.token_automatic_renew_mode==H.AutomaticOnlyWhenFetchExecuted&&q.FORCE_REFRESH!==d)return e.publishEvent(t.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:`GIVE_UP`};if(e.publishEvent(t.refreshTokensAsync_begin,{refreshToken:p.refreshToken,status:d,tryNumber:r,backgroundTry:i}),!p.refreshToken)return await C();let u=b.client_id,h=b.redirect_uri,_=b.authority,v={...b.token_request_extras?b.token_request_extras:{}};for(let[e,t]of Object.entries(s))e.endsWith(`:token_request`)&&(v[e.replace(`:token_request`,``)]=t);return await(async()=>{let r={client_id:u,redirect_uri:h,grant_type:`refresh_token`,refresh_token:p.refreshToken},i=await e.initAsync(_,b.authority_configuration),d=document.hidden?1e4:3e5,x=i.tokenEndpoint,S={};b.demonstrating_proof_of_possession&&(S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(p.accessToken,x,`POST`));let C=await ke(e.getFetch())(x,r,v,p,S,b.token_renew_mode,d);if(!C.success&&C.oauthError===`use_dpop_nonce`&&C.demonstratingProofOfPossessionNonce&&b.demonstrating_proof_of_possession){let t=await $(b,e.configurationName);t?await t.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce):await a(e.configurationName,b.storage,b.login_state_storage??b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce),S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(p.accessToken,x,`POST`),C=await ke(e.getFetch())(x,r,v,p,S,b.token_renew_mode,d)}if(C.success){if(!m||!m.nonce){n(null);let r=new N(M.NONCE_MISSING,`refresh token: nonce missing from storage`,`refresh`);return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token: nonce missing from storage`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}let{isValid:r,reason:o}=ut(C.data,m.nonce,i);if(!r){n(null);let r=new f(o.startsWith(`Nonce does not match`)?l.INVALID_NONCE:l.TOKEN_REQUEST_FAILED,`refresh token return not valid tokens, reason: ${o}`,{phase:`refresh`,retryable:!1});return e.publishEvent(t.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${o}`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}if(n(C.data),C.demonstratingProofOfPossessionNonce){let t=await $(b,e.configurationName);t?await t.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce):await a(e.configurationName,b.storage,b.login_state_storage??b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce)}return e.publishEvent(t.refreshTokensAsync_end,{success:C.success}),e.publishEvent(W.eventNames.token_renewed,{reason:`REFRESH_TOKEN`}),{tokens:C.data,status:`LOGGED_IN`}}{let r=G(`Token request failed`,C);return e.publishEvent(t.refreshTokensAsync_silent_error,{message:`bad request`,tokenResponse:C,error:r}),C.status>=400&&C.status<500?(n(null),e.publishEvent(t.refreshTokensAsync_error,{message:`session lost: ${C.status}`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}):await et(e)(n,g,y,o,s,c,r)}})()}}}catch(r){let i=p(r)||!v(r)?r:_(r,`refresh`);return console.error(i),e.publishEvent(t.refreshTokensAsync_silent_error,{message:`exception`,exception:i.message,error:p(i)?i:void 0}),new Promise((t,r)=>{setTimeout(()=>{et(e)(n,g,y,o,s,c,p(i)?i:u).then(t).catch(r)},1e3)})}},tt=e=>decodeURIComponent(Array.prototype.map.call(atob(e),e=>`%`+(`00`+e.charCodeAt(0).toString(16)).slice(-2)).join(``)),nt=e=>JSON.parse(tt(e.replaceAll(/-/g,`+`).replaceAll(/_/g,`/`))),rt=e=>{try{if(!e)return null;let t=e.split(`.`);return t.length===3?nt(t[1]):null}catch(e){console.warn(e)}return null},it={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 at(e,t,n){return e.issuedAt?typeof e.issuedAt==`string`?parseInt(e.issuedAt,10):e.issuedAt:t&&t.iat?t.iat:n&&n.iat?n.iat:new Date().getTime()/1e3}var ot=(e,t=null,n)=>{if(!e)return null;let r,i=typeof e.expiresIn==`string`?parseInt(e.expiresIn,10):e.expiresIn;r=e.accessTokenPayload===void 0?rt(e.accessToken):e.accessTokenPayload;let a;a=t!=null&&`idToken`in t&&!(`idToken`in e)?t.idToken:e.idToken;let o=e.idTokenPayload?e.idTokenPayload:rt(a),s=o&&o.exp?o.exp:Number.MAX_VALUE,c=r&&r.exp?r.exp:e.issuedAt+i;e.issuedAt=at(e,r,o);let l;l=e.expiresAt?e.expiresAt:n===it.access_token_invalid?c:n===it.id_token_invalid||s<c?s:c;let u={...e,idTokenPayload:o,accessTokenPayload:r,expiresAt:l,idToken:a};if(t!=null&&`refreshToken`in t&&!(`refreshToken`in e)){let e=t.refreshToken;return{...u,refreshToken:e}}return u},st=(e,t,n)=>{if(!e)return null;e.issued_at||=new Date().getTime()/1e3;let r={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&&(r.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(r.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(r.idTokenPayload=e.idTokenPayload),ot(r,t,n)},J=(e,t)=>{let n=t-new Date().getTime()/1e3;return Math.round(n-e)},ct=(e,t=0)=>e?J(t,e.expiresAt)>0:!1,lt=async(e,t=200,n=50)=>{let r=n,i=await e.syncTokensInfoAsync();for(;[q.REQUIRE_SYNC_TOKENS,q.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,q.TOKENS_INVALID].includes(i)&&r>0;){if(e.configuration.token_automatic_renew_mode==H.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}await Y({milliseconds:t}),--r,i=await e.syncTokensInfoAsync()}return{isTokensValid:ct(e.getTokens()),tokens:e.getTokens(),numberWaited:r-n}},ut=(e,t,n)=>{if(e.idTokenPayload){let r=e.idTokenPayload;if(n.issuer!==r.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${n.issuer} !== (idTokenPayload issuer) ${r.iss}`};let i=new Date().getTime()/1e3;if(r.exp&&r.exp<i)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${r.exp} < (currentTimeUnixSecond) ${i}`};let a=604800;if(r.iat&&r.iat+a<i)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${r.iat+a} < (currentTimeUnixSecond) ${i}`};if(r.nonce&&r.nonce!==t)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${r.nonce} !== (nonce) ${t}`}}return{isValid:!0,reason:``}},dt=`7.29.7`,ft=null,pt,Y=({milliseconds:e})=>new Promise(t=>x.setTimeout(t,e)),mt=(e=`/`)=>{try{pt=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:pt.signal}).catch(e=>{console.log(e)}),Y({milliseconds:15e4}).then(()=>mt(e))}catch(e){console.log(e)}},X=()=>{pt&&pt.abort()},ht=e=>{let t=`oidc.tabId.${e}`,n=sessionStorage.getItem(t);if(n)return n;let r=globalThis.crypto.randomUUID();return sessionStorage.setItem(t,r),r},gt=e=>navigator.serviceWorker.controller??e.active??e.waiting??e.installing??null,Z=(e,t)=>n=>{let r=t?.timeoutMs??5e3;return new Promise((t,i)=>{let a=gt(e);if(!a){i(Error(`Service worker target not available (controller/active/waiting/installing missing)`));return}let o=new MessageChannel,s=null,c=()=>{try{s!=null&&(x.clearTimeout(s),s=null),o.port1.onmessage=null,o.port1.close(),o.port2.close()}catch(e){console.error(e)}};s=x.setTimeout(()=>{c(),i(Error(`Service worker did not respond within ${r}ms (type=${n?.type})`))},r),o.port1.onmessage=e=>{c(),e?.data?.error?i(e.data.error):t(e.data)};try{let e=n?.configurationName;a.postMessage({...n,tabId:ht(e??`default`)},[o.port2])}catch(e){c(),i(e)}})},_t=async e=>navigator.serviceWorker.controller?navigator.serviceWorker.controller:new Promise(t=>{let n=!1,r=()=>{n||(n=!0,navigator.serviceWorker.removeEventListener(`controllerchange`,r),t(navigator.serviceWorker.controller??null))};navigator.serviceWorker.addEventListener(`controllerchange`,r),x.setTimeout(()=>{n||(n=!0,navigator.serviceWorker.removeEventListener(`controllerchange`,r),t(navigator.serviceWorker.controller??null))},e)}),vt=!1,Q=!1,yt=new Map,bt=e=>e instanceof DOMException?e.name===`AbortError`:e?.name===`AbortError`,xt=`oidc.sw.controllerchange_reload_count`,St=3,Ct=()=>{try{return parseInt(sessionStorage.getItem(xt)??`0`,10)}catch{return 0}},wt=()=>{let e=Ct()+1;try{sessionStorage.setItem(xt,String(e))}catch{}return e},Tt=()=>{try{sessionStorage.removeItem(xt)}catch{}},$=async(e,t)=>{let n=e.service_worker_relative_url;if(typeof window>`u`||typeof navigator>`u`||!navigator.serviceWorker||!n||e.service_worker_activate()===!1)return null;let r=`${n}?v=${dt}`,i=e.service_worker_register?n:r;yt.has(i)||yt.set(i,e.service_worker_register?e.service_worker_register(n):navigator.serviceWorker.register(r,{updateViaCache:`none`}));let a=null;try{a=await yt.get(i)}catch(e){if(bt(e))return yt.delete(i),console.warn(`oidc-client: service worker registration was aborted (likely tab shutdown or backgrounding); falling back to non–service-worker mode.`,e),null;throw e}let o=`oidc.sw.version_mismatch_reload.${t}`,s=async e=>{X(),console.log(`New SW waiting – SKIP_WAITING`);try{await new Promise((n,r)=>{let i=new MessageChannel,a=null,o=()=>{try{a!=null&&(x.clearTimeout(a),a=null),i.port1.onmessage=null,i.port1.close(),i.port2.close()}catch(e){console.error(e)}};a=x.setTimeout(()=>{o(),r(Error(`SKIP_WAITING did not respond within 8000ms`))},8e3),i.port1.onmessage=e=>{o(),e?.data?.error?r(e.data.error):n()};try{e.postMessage({type:`SKIP_WAITING`,configurationName:t,data:null,tabId:ht(t??`default`)},[i.port2])}catch(e){o(),r(e)}})}catch(e){console.warn(`SKIP_WAITING failed`,e)}},c=async()=>{let e=a.waiting;e?await s(e):console.warn(`sendSkipWaiting called but no waiting service worker found`)},l=e=>{X(),e.addEventListener(`statechange`,async()=>{if(e.state===`installed`&&navigator.serviceWorker.controller){if(Ct()>=St){console.warn(`SW trackInstallingWorker: skipping SKIP_WAITING because the reload budget is exhausted`);return}await s(e)}})};a.addEventListener(`updatefound`,()=>{let e=a.installing;e&&l(e)}),a.installing?l(a.installing):a.waiting&&navigator.serviceWorker.controller&&(Ct()<St?c():console.warn(`SW: a waiting worker exists but reload budget is exhausted – skipping activation`)),a.update().catch(e=>{console.error(e)});try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||(await Z(a,{timeoutMs:8e3})({type:`claim`,configurationName:t,data:null}),await _t(2e3))}catch(e){return console.warn(`Failed init ServiceWorker ${e?.toString?.()??String(e)}`),null}vt||(vt=!0,navigator.serviceWorker.addEventListener(`controllerchange`,()=>{if(Q)return;let e=wt();e>St?console.warn(`SW controllerchange: reload budget exhausted (${e-1} reloads). Skipping reload to avoid infinite loop.`):(Q=!0,console.log(`SW controller changed – reloading page`),X(),window.location.reload())}));let u=async e=>Z(a)({type:`clear`,data:{status:e},configurationName:t}),d=async(e,n,r)=>{let i=await Z(a)({type:`init`,data:{oidcServerConfiguration:e,where:n,oidcConfiguration:{token_renew_mode:r.token_renew_mode,service_worker_convert_all_requests_to_cors:r.service_worker_convert_all_requests_to_cors}},configurationName:t}),s=i.version;if(s!==`7.29.7`){console.warn(`Service worker ${s} version mismatch with js client version ${dt}, unregistering and reloading`);let e=parseInt(sessionStorage.getItem(o)??`0`,10);if(e<3){if(sessionStorage.setItem(o,String(e+1)),a.waiting)return await c(),await Y({milliseconds:500}),Q||(Q=!0,window.location.reload()),new Promise(()=>{});{X();try{await a.update()}catch(e){console.error(e)}let e=await a.unregister();return console.log(`Service worker unregistering ${e}`),await Y({milliseconds:500}),Q||(Q=!0,window.location.reload()),new Promise(()=>{})}}console.error(`Service worker version mismatch persists after ${e} attempt(s). Continuing with mismatched version.`)}else sessionStorage.removeItem(o),Tt();return{tokens:st(i.tokens,null,r.token_renew_mode),status:i.status}},f=(e=`/`)=>{ft??(ft=`not_null`,mt(e))},p=e=>Z(a)({type:`setSessionState`,data:{sessionState:e},configurationName:t}),m=async()=>(await Z(a)({type:`getSessionState`,data:null,configurationName:t})).sessionState,h=e=>(sessionStorage[`oidc.nonce.${t}`]=e.nonce,Z(a)({type:`setNonce`,data:{nonce:e},configurationName:t})),g=async(e=!0)=>{let n=(await Z(a)({type:`getNonce`,data:null,configurationName:t})).nonce;return n||(n=sessionStorage[`oidc.nonce.${t}`],console.warn(`nonce not found in service worker, using sessionStorage`),e&&(await h(n),n=(await g(!1)).nonce)),{nonce:n}},_={},v=e=>{e==null?(delete _[t],delete localStorage[`oidc.login.${t}`]):(_[t]=e,localStorage[`oidc.login.${t}`]=JSON.stringify(e))},y=()=>{if(_[t])return _[t];let e=localStorage[`oidc.login.${t}`];if(typeof e!=`string`||e===``||e===`undefined`||e===`null`)return null;try{_[t]=JSON.parse(e)}catch{return null}return _[t]},b=async e=>{await Z(a)({type:`setDemonstratingProofOfPossessionNonce`,data:{demonstratingProofOfPossessionNonce:e},configurationName:t})},S=async()=>(await Z(a)({type:`getDemonstratingProofOfPossessionNonce`,data:null,configurationName:t})).demonstratingProofOfPossessionNonce,C=async e=>{let n=JSON.stringify(e);await Z(a)({type:`setDemonstratingProofOfPossessionJwk`,data:{demonstratingProofOfPossessionJwkJson:n},configurationName:t})},w=async()=>{let e=await Z(a)({type:`getDemonstratingProofOfPossessionJwk`,data:null,configurationName:t});return e.demonstratingProofOfPossessionJwkJson?JSON.parse(e.demonstratingProofOfPossessionJwkJson):null},T=async(e=!0)=>{let n=(await Z(a)({type:`getState`,data:null,configurationName:t})).state;return n||(n=sessionStorage[`oidc.state.${t}`],console.warn(`state not found in service worker, using sessionStorage`),e&&(await E(n),n=await T(!1))),n},E=async e=>(sessionStorage[`oidc.state.${t}`]=e,Z(a)({type:`setState`,data:{state:e},configurationName:t})),D=async(e=!0)=>{let n=(await Z(a)({type:`getCodeVerifier`,data:null,configurationName:t})).codeVerifier;return n||(n=sessionStorage[`oidc.code_verifier.${t}`],console.warn(`codeVerifier not found in service worker, using sessionStorage`),e&&(await O(n),n=await D(!1))),n},O=async e=>(sessionStorage[`oidc.code_verifier.${t}`]=e,Z(a)({type:`setCodeVerifier`,data:{codeVerifier:e},configurationName:t}));return{clearAsync:u,initAsync:d,startKeepAliveServiceWorker:()=>f(e.service_worker_keep_alive_path),setSessionStateAsync:p,getSessionStateAsync:m,setNonceAsync:h,getNonceAsync:g,setLoginParams:v,getLoginParams:y,getStateAsync:T,setStateAsync:E,getCodeVerifierAsync:D,setCodeVerifierAsync:O,setDemonstratingProofOfPossessionNonce:b,getDemonstratingProofOfPossessionNonce:S,setDemonstratingProofOfPossessionJwkAsync:C,getDemonstratingProofOfPossessionJwkAsync:w,signalAsync:(e,n)=>Z(a,n)({...e,configurationName:e.configurationName??t})}},Et=async(e,t,n,r)=>{let i=await $(e,t);if(!i)throw Error(`signalServiceWorkerAsync: no service worker registered for configuration "${t}"`);return i.signalAsync(n,r)},Dt=class e{constructor(e){this._oidc=e}subscribeEvents(e){return this._oidc.subscribeEvents(e)}removeEventSubscription(e){this._oidc.removeEventSubscription(e)}publishEvent(e,t){this._oidc.publishEvent(e,t)}static{this.getOrCreate=(t,n=new j)=>(r,i=`default`)=>new e(W.getOrCreate(t,n)(r,i))}static get(t=`default`){let n=W.get(t);return n?new e(n):null}static getOrThrow(t=`default`){return new e(W.getOrThrow(t))}static{this.eventNames=W.eventNames}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(e=void 0,t=null,n=!1,r=void 0,i=!1){return this._oidc.loginAsync(e,t,n,r,i)}logoutAsync(e=void 0,t=null){return this._oidc.logoutAsync(e,t)}clearSessionAsync(){return this._oidc.clearSessionAsync()}get isLoggingOut(){return this._oidc.isLoggingOut===!0}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(e=null,t=null){return this._oidc.renewTokensAsync(e,t)}renewTokensOrThrowAsync(e=null,t=null){return this._oidc.renewTokensOrThrowAsync(e,t)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(e,t,n,r={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(e,t,n,r)}async getValidTokenAsync(e=200,t=50){let n=this._oidc;return lt({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()=>{let{status:e}=await $e(n)(n.configuration,n.configurationName,n.tokens,!1);return e},renewTokensAsync:n.renewTokensAsync.bind(n)},e,t)}fetchWithTokens(e,t=!1){return We(e,this._oidc,t)}async userInfoAsync(e=!1,t=!1){return this._oidc.userInfoAsync(e,t)}userInfo(){return this._oidc.userInfo}async signalServiceWorker(e,t){return Et(this._oidc.configuration,this._oidc.configurationName,e,t)}},Ot=`1.0.0`,kt={SKIP_WAITING:`SKIP_WAITING`,CLAIM:`claim`,CLEAR:`clear`,INIT:`init`,SET_STATE:`setState`,GET_STATE:`getState`,SET_CODE_VERIFIER:`setCodeVerifier`,GET_CODE_VERIFIER:`getCodeVerifier`,SET_SESSION_STATE:`setSessionState`,GET_SESSION_STATE:`getSessionState`,SET_NONCE:`setNonce`,GET_NONCE:`getNonce`,SET_DPOP_NONCE:`setDemonstratingProofOfPossessionNonce`,GET_DPOP_NONCE:`getDemonstratingProofOfPossessionNonce`,SET_DPOP_JWK:`setDemonstratingProofOfPossessionJwk`,GET_DPOP_JWK:`getDemonstratingProofOfPossessionJwk`},At={ACCESS_TOKEN:`ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER`,REFRESH_TOKEN:`REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER`,NONCE_TOKEN:`NONCE_SECURED_BY_OIDC_SERVICE_WORKER`,CODE_VERIFIER:`CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER`},jt=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER`;e.DPOP_TOKEN_PLACEHOLDER_PREFIX=jt,e.OidcClient=Dt,e.OidcError=f,e.OidcErrorCode=l,e.OidcLocation=j,e.OidcStateError=N,e.OidcStateErrorCode=M,e.PROTOCOL_VERSION=Ot,e.PushedAuthorizationRequestError=F,e.PushedAuthorizationRequestErrorCode=P,e.STORAGE_KEY_PREFIX={TAB_ID:`oidc.tabId.`,STATE:`oidc.state.`,NONCE:`oidc.nonce.`,CODE_VERIFIER:`oidc.code_verifier.`,LOGIN_PARAMS:`oidc.login.`,SW_VERSION_MISMATCH_RELOAD:`oidc.sw.version_mismatch_reload.`},e.SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY=`oidc.sw.controllerchange_reload_count`,e.ServiceWorkerMessageType=kt,e.TOKEN_PLACEHOLDERS=At,e.TokenAutomaticRenewMode=H,e.TokenRenewMode=it,e.buildDpopSecuredPlaceholder=(e,t=`default`)=>`${jt}_${e}#tabId=${t}`,e.buildSecuredTokenPlaceholder=(e,t,n=`default`)=>`${e}_${t}#tabId=${n}`,e.buildStorageKey=(e,t)=>`${e}${t}`,e.getFetchDefault=Ke,e.getParseQueryStringFromLocation=V,e.getPath=Ne,e.isOidcError=p,e.isOidcStateError=be,e.isPushedAuthorizationRequestError=xe,e.isServiceWorkerMessageType=e=>typeof e==`string`&&Object.values(kt).includes(e),e.signalServiceWorkerAsync=Et});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`oidc-client`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t={INVALID_RESOURCE:`INVALID_RESOURCE`,INVALID_TARGET:`INVALID_TARGET`,RESOURCE_TOKEN_UNAVAILABLE:`RESOURCE_TOKEN_UNAVAILABLE`,RESOURCE_CONTEXT_MISMATCH:`RESOURCE_CONTEXT_MISMATCH`,RESOURCE_WORKER_UNSUPPORTED:`RESOURCE_WORKER_UNSUPPORTED`,LOGIN_REQUIRED:`LOGIN_REQUIRED`,CONSENT_REQUIRED:`CONSENT_REQUIRED`,INTERACTION_REQUIRED:`INTERACTION_REQUIRED`,OAUTH_ERROR:`OAUTH_ERROR`,TOKEN_REQUEST_FAILED:`TOKEN_REQUEST_FAILED`,SILENT_LOGIN_TIMEOUT:`SILENT_LOGIN_TIMEOUT`,INVALID_STATE:`INVALID_STATE`,INVALID_NONCE:`INVALID_NONCE`,DPOP_NONCE_REQUIRED:`DPOP_NONCE_REQUIRED`,NETWORK_ERROR:`NETWORK_ERROR`,STATE_MISSING:`STATE_MISSING`,STATE_MISMATCH:`STATE_MISMATCH`,NONCE_MISSING:`NONCE_MISSING`,ENDPOINT_UNAVAILABLE:`ENDPOINT_UNAVAILABLE`,REQUEST_FAILED:`REQUEST_FAILED`,INVALID_RESPONSE:`INVALID_RESPONSE`},n=new Set(Object.values(t)),r=new Set([`login`,`callback`,`refresh`,`logout`,`userinfo`,`api_request`]),i=class extends Error{constructor(e,t,n){super(t),this.name=`OidcError`,this.code=e,this.phase=n.phase,this.oauthError=n.oauthError,this.oauthErrorDescription=n.oauthErrorDescription,this.retryable=n.retryable,this.status=n.status,this.cause=n.cause,Object.setPrototypeOf(this,new.target.prototype)}},a=e=>e instanceof i,o=e=>e===408||e===429||e!==void 0&&e>=500,s=e=>{switch(e){case`invalid_target`:return t.INVALID_TARGET;case`login_required`:return t.LOGIN_REQUIRED;case`consent_required`:return t.CONSENT_REQUIRED;case`interaction_required`:return t.INTERACTION_REQUIRED;case`use_dpop_nonce`:return t.DPOP_NONCE_REQUIRED;default:return t.OAUTH_ERROR}},c=(e,n,r,a,c)=>{let l=s(e);return new i(l,r,{phase:a,retryable:l!==t.LOGIN_REQUIRED&&l!==t.CONSENT_REQUIRED&&l!==t.INTERACTION_REQUIRED&&(l===t.DPOP_NONCE_REQUIRED||e===`server_error`||e===`temporarily_unavailable`||o(c)),oauthError:e,oauthErrorDescription:n,status:c})},l=(e,n,r=`Network request failed`)=>{let a=e instanceof Error&&typeof e.message==`string`&&e.message?e.message:r;return new i(t.NETWORK_ERROR,a,{phase:n,retryable:!0,cause:e})},u=e=>e instanceof Error?e.name===`AbortError`||e.name===`NetworkError`||e.message===`Network request failed`||e.message===`Failed to fetch`||e.message===`fetch failed`:!1,d=e=>({name:e.name,message:e.message,code:e.code,phase:e.phase,retryable:e.retryable,oauthError:e.oauthError,oauthErrorDescription:e.oauthErrorDescription,status:e.status}),f=e=>{if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.message!=`string`||typeof t.code!=`string`||!n.has(t.code)||typeof t.phase!=`string`||!r.has(t.phase)||typeof t.retryable!=`boolean`)return null;let a=new i(t.code,t.message,{phase:t.phase,retryable:t.retryable,oauthError:typeof t.oauthError==`string`?t.oauthError:void 0,oauthErrorDescription:typeof t.oauthErrorDescription==`string`?t.oauthErrorDescription:void 0,status:typeof t.status==`number`?t.status:void 0});return typeof t.name==`string`&&t.name&&(a.name=t.name),a},p={resource_token_acquired:`resource_token_acquired`,resource_token_cleared:`resource_token_cleared`,resource_token_error:`resource_token_error`,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`,loginCallbackAsync_navigated:`loginCallbackAsync_navigated`,loginCallbackAsync_navigation_error:`loginCallbackAsync_navigation_error`,logoutAsync_error:`logoutAsync_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`,userInfoAsync_error:`userInfoAsync_error`,apiRequest_error:`apiRequest_error`,syncTokensAsync_begin:`syncTokensAsync_begin`,syncTokensAsync_lock_not_available:`syncTokensAsync_lock_not_available`,syncTokensAsync_end:`syncTokensAsync_end`,syncTokensAsync_error:`syncTokensAsync_error`,tokensInvalidAndWaitingActionsToRefresh:`tokensInvalidAndWaitingActionsToRefresh`,loadingTimeout_error:`loadingTimeout_error`},m=(e,t,n)=>{n==null?delete e[t]:e[t]=JSON.stringify(n)},h=(e,t,n)=>{n==null?delete e[t]:e[t]=n},g=e=>{if(typeof e!=`string`||e===`undefined`||e===`null`||e===``)return null;try{return JSON.parse(e)}catch{return null}},_=(e,t=sessionStorage,n)=>{let r=n??t,i=i=>(m(t,`oidc.${e}`,{tokens:null,status:i}),delete t[`oidc.${e}.userInfo`],n&&n!==t&&(delete r[`oidc.login.${e}`],delete r[`oidc.state.${e}`],delete r[`oidc.code_verifier.${e}`],delete r[`oidc.nonce.${e}`]),Promise.resolve()),a=async()=>{let n=g(t[`oidc.${e}`]);return n?Promise.resolve({tokens:n.tokens,status:n.status}):(m(t,`oidc.${e}`,{tokens:null,status:null}),{tokens:null,status:null})},o=n=>{m(t,`oidc.${e}`,{tokens:n})},s=async n=>{h(t,`oidc.session_state.${e}`,n)},c=async()=>t[`oidc.session_state.${e}`],l=t=>{h(r,`oidc.nonce.${e}`,t?.nonce)},u=n=>{m(t,`oidc.jwk.${e}`,n)},d=()=>g(t[`oidc.jwk.${e}`]),f=async()=>({nonce:r[`oidc.nonce.${e}`]}),p=async n=>{h(t,`oidc.dpop_nonce.${e}`,n)},_=()=>t[`oidc.dpop_nonce.${e}`],v=async n=>{h(t,`oidc.dpop_api_nonce.${e}`,n)},y=()=>t[`oidc.dpop_api_nonce.${e}`],b=()=>{let n=g(t[`oidc.${e}`]);return n?JSON.stringify({tokens:n.tokens}):null},x={};return{clearAsync:i,initAsync:a,setTokens:o,getTokens:b,setSessionStateAsync:s,getSessionStateAsync:c,setNonceAsync:l,getNonceAsync:f,setLoginParams:t=>{t==null?(delete x[e],delete r[`oidc.login.${e}`]):(x[e]=t,m(r,`oidc.login.${e}`,t))},getLoginParams:()=>{if(x[e])return x[e];let t=g(r[`oidc.login.${e}`]);return t===null?(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null):(x[e]=t,t)},getStateAsync:async()=>r[`oidc.state.${e}`],setStateAsync:async t=>{h(r,`oidc.state.${e}`,t)},getCodeVerifierAsync:async()=>r[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async t=>{h(r,`oidc.code_verifier.${e}`,t)},setDemonstratingProofOfPossessionNonce:p,getDemonstratingProofOfPossessionNonce:_,setDemonstratingProofOfPossessionApiNonce:v,getDemonstratingProofOfPossessionApiNonce:y,setDemonstratingProofOfPossessionJwkAsync:u,getDemonstratingProofOfPossessionJwkAsync:d}},v=2e3,y=console,b=class{constructor(e,t,n,r=v,i=!0){this._callback=e,this._client_id=t,this._url=n,this._interval=r||v,this._stopOnError=i;let a=n.indexOf(`/`,n.indexOf(`//`)+2);this._frame_origin=n.substring(0,a),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=n}load(){return new Promise(e=>{this._frame.onload=()=>{e()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener(`message`,this._boundMessageEvent,!1)})}_message(e){e.origin===this._frame_origin&&e.source===this._frame.contentWindow&&(e.data===`error`?(y.error(`CheckSessionIFrame: error message from check session op iframe`),this._stopOnError&&this.stop()):e.data===`changed`?(y.debug(e),y.debug(`CheckSessionIFrame: changed message from check session op iframe`),this.stop(),this._callback()):y.debug(`CheckSessionIFrame: `+e.data+` message from check session op iframe`))}start(e){y.debug(`CheckSessionIFrame.start :`+e),this.stop();let t=()=>{this._frame.contentWindow.postMessage(this._client_id+` `+e,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&=(y.debug(`CheckSessionIFrame.stop`),window.clearInterval(this._timer),null)}},x=(function(){let e=typeof window>`u`?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}})(),S=(e,n,r,a=`login`)=>(o=null,s=null,l=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{r(p.silentLoginAsync_begin,{});let u=``;if(s&&(o??={},o.state=s),l!=null&&(o??={},o.scope=l),o!=null)for(let[e,t]of Object.entries(o))t!=null&&(u===``?u=`?${encodeURIComponent(e)}=${encodeURIComponent(t)}`:u+=`&${encodeURIComponent(e)}=${encodeURIComponent(t)}`);let d=n.silent_login_uri+u,m=d.indexOf(`/`,d.indexOf(`//`)+2),h=d.substring(0,m),g=document.createElement(`iframe`);return g.width=`0px`,g.height=`0px`,g.id=`${e}_oidc_iframe`,g.setAttribute(`src`,d),g.style.display=`none`,document.body.appendChild(g),new Promise((o,s)=>{let l=!1,u=()=>{window.removeEventListener(`message`,d),g.remove(),l=!0},d=t=>{if(t.origin===h&&t.source===g.contentWindow){let n=`${e}_oidc_tokens:`,i=`${e}_oidc_error:`,d=`${e}_oidc_exception:`,m=t.data;if(m&&typeof m==`string`&&!l){if(m.startsWith(n)){let e=JSON.parse(t.data.replace(n,``));r(p.silentLoginAsync_end,{}),o(e),u()}else if(m.startsWith(i)){let e=JSON.parse(t.data.replace(i,``)),n=f(e.oidcError)??c(e.error,e.error_description,`Error from OIDC server: ${e.error} - ${e.error_description}`,a);r(p.silentLoginAsync_error,n),o({error:`oidc_`+e.error,tokens:null,sessionState:null,oidcError:n}),u()}else if(m.startsWith(d)){let e=JSON.parse(t.data.replace(d,``)),n=f(e.oidcError)??Error(e.error);r(p.silentLoginAsync_error,n),s(n),u()}}}};try{window.addEventListener(`message`,d);let e=n.silent_login_timeout;setTimeout(()=>{if(!l){u();let e=new i(t.SILENT_LOGIN_TIMEOUT,`timeout`,{phase:a,retryable:!0});r(p.silentLoginAsync_error,e),s(e)}},e)}catch(e){u(),r(p.silentLoginAsync_error,e),s(e)}})}catch(e){throw r(p.silentLoginAsync_error,e),e}},C=(e,n,r,a,o)=>(e=null,s=void 0)=>{e={...e};let c=(e,t,i)=>S(n,r,a.bind(o))(e,t,i);return(async()=>{let n;e&&`state`in e&&(n=e.state,delete e.state);let l=r.extras?{...r.extras,...e}:e,u=await c({...l,prompt:`none`},n,s);if(u){if(u.oidcError)throw u.oidcError;if(!u.tokens)throw new i(t.TOKEN_REQUEST_FAILED,`Silent login returned no tokens.`,{phase:`login`,retryable:!1});return o.timeoutId&&x.clearTimeout(o.timeoutId),o.tokens=u.tokens,a(p.token_acquired,{}),o.timeoutId=J(o,o.tokens.expiresAt,e,s),{}}})().catch(e=>e)},w=(e,t,n)=>(r,i,a,o=!1)=>{let s=(t,r=void 0,i=void 0)=>S(e.configurationName,n,e.publishEvent.bind(e))(t,r,i);return new Promise((c,l)=>{n.silent_login_uri&&n.silent_redirect_uri&&n.monitor_session&&r&&a&&!o?(e.checkSessionIFrame=new b(()=>{e.checkSessionIFrame.stop();let r=e.tokens;if(r===null)return;let i=r.idToken,a=r.idTokenPayload;return s({prompt:`none`,id_token_hint:i,scope:n.scope||`openid`}).then(t=>{if(t.error)throw Error(t.error);let n=t.tokens.idTokenPayload;if(a.sub===n.sub){let r=t.sessionState;e.checkSessionIFrame.start(t.sessionState),a.sid===n.sid?console.debug(`SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:`,r):console.debug(`SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:`,r)}else console.debug(`SessionMonitor._callback: Different subject signed into OP:`,n.sub)}).catch(async e=>{console.warn(`SessionMonitor._callback: Silent login failed, logging out other tabs:`,e);for(let[,e]of Object.entries(t))await e.logoutOtherTabAsync(n.client_id,a.sub)})},i,r),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(a),c(e.checkSessionIFrame)}).catch(e=>{l(e)})):c(null)})};function T(e){return new TextEncoder().encode(e)}function E(e){return btoa(e).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+/g,``)}function D(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode(parseInt(t,16))})}var O=e=>{let t=``;return e.forEach(function(e){t+=String.fromCharCode(e)}),E(t)};function k(e){return E(D(e))}var A={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`},j={sign:e=>async(t,n,r,i,a=`dpop+jwt`)=>{switch(t=Object.assign({},t),n.typ=a,n.alg=i.jwtHeaderAlgorithm,n.alg){case`ES256`:n.jwk={kty:t.kty,crv:t.crv,x:t.x,y:t.y};break;case`RS256`:n.jwk={kty:t.kty,n:t.n,e:t.e,kid:n.kid};break;default:throw Error(`Unknown or not implemented JWS algorithm`)}let o={protected:k(JSON.stringify(n)),payload:k(JSON.stringify(r))},s=i.importKeyAlgorithm,c=await e.crypto.subtle.importKey(`jwk`,t,s,!0,[`sign`]),l=T(`${o.protected}.${o.payload}`),u=i.signAlgorithm,d=await e.crypto.subtle.sign(u,c,l);return o.signature=O(new Uint8Array(d)),`${o.protected}.${o.payload}.${o.signature}`}},M={generate:e=>async t=>{let n=t,r=await e.crypto.subtle.generateKey(n,!0,[`sign`,`verify`]);return await e.crypto.subtle.exportKey(`jwk`,r.privateKey)},neuter:e=>{let t=Object.assign({},e);return delete t.d,t.key_ops=[`verify`],t}},ee={thumbprint:e=>async(t,n)=>{let r;switch(t.kty){case`EC`:r=`{"crv":"CRV","kty":"EC","x":"X","y":"Y"}`.replace(`CRV`,t.crv).replace(`X`,t.x).replace(`Y`,t.y);break;case`RSA`:r=`{"e":"E","kty":"RSA","n":"N"}`.replace(`E`,t.e).replace(`N`,t.n);break;default:throw Error(`Unknown or not implemented JWK type`)}let i=await e.crypto.subtle.digest(n,T(r));return O(new Uint8Array(i))}},te=e=>async t=>await M.generate(e)(t),ne=e=>t=>async(n,r=`POST`,i,a={})=>{let o=new URL(i,e.location?.href);o.search=``,o.hash=``;let s={jti:btoa(e.crypto.randomUUID()),htm:r,htu:o.href,iat:Math.round(Date.now()/1e3),...a},c=await ee.thumbprint(e)(n,t.digestAlgorithm);return await j.sign(e)(n,{kid:c},s,t)},re=()=>typeof globalThis<`u`?globalThis.crypto:void 0,ie=()=>{let e=re();return{hasCrypto:!!e,hasSubtleCrypto:!!e?.subtle}},ae=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,oe=e=>{let t=[];for(let n=0;n<e.byteLength;n+=1){let r=e[n]%62;t.push(ae[r])}return t.join(``)},se=e=>{let t=new Uint8Array(e),n=re();if(!n?.getRandomValues)throw Error(`Web Crypto API is unavailable; secure random values cannot be generated.`);return n.getRandomValues(t),oe(t)};function ce(e){let t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}function le(e){return new Promise((t,n)=>{crypto.subtle.digest(`SHA-256`,ce(e)).then(e=>t(O(new Uint8Array(e))),e=>n(e))})}var ue=e=>{if(e.length<43||e.length>128)return Promise.reject(Error(`Invalid code length.`));let{hasSubtleCrypto:t}=ie();return t?le(e):Promise.reject(Error(`window.crypto.subtle is unavailable.`))},de=e=>!!(e.os===`iOS`&&e.osVersion.startsWith(`12`)||e.os===`Mac OS X`&&e.osVersion.startsWith(`10_15_6`)),fe=e=>{let t=e.appVersion,n=e.userAgent,r=`-`,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(let e in i){let t=i[e];if(t.r.test(n)){r=t.s;break}}let a=`-`;switch(/Windows/.test(r)&&(a=/Windows (.*)/.exec(r)[1],r=`Windows`),r){case`Mac OS`:case`Mac OS X`:case`Android`:a=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(n)[1];break;case`iOS`:{let e=/OS (\d+)_(\d+)_?(\d+)?/.exec(t);e!=null&&e.length>2&&(a=e[1]+`.`+e[2]+`.`+(parseInt(e[3])|0));break}}return{os:r,osVersion:a}};function pe(){let e=navigator.userAgent,t,n=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(n[1]))return t=/\brv[ :]+(\d+)/g.exec(e)||[],{name:`ie`,version:t[1]||``};if(n[1]===`Chrome`&&(t=e.match(/\bOPR|Edge\/(\d+)/),t!=null)){let n=t[1];if(!n){let r=e.split(t[0]+`/`);r.length>1&&(n=r[1])}return{name:`opera`,version:n}}return n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,`-?`],(t=e.match(/version\/(\d+)/i))!=null&&n.splice(1,1,t[1]),{name:n[0].toLowerCase(),version:n[1]}}var me=()=>{let{name:e,version:t}=pe();return e===`chrome`&&parseInt(t)<=70||e===`opera`&&(!t||parseInt(t.split(`.`)[0])<80)||e===`ie`?!1:!de(fe(navigator))},he=async e=>{let t;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{let n=e.configuration,r=await e.initAsync(n.authority,n.authority_configuration);if(t=await $(n,e.configurationName),t){let{tokens:i}=await t.initAsync(r,`tryKeepExistingSessionAsync`,n);if(i){t.startKeepAliveServiceWorker(),e.tokens=i;let a=t.getLoginParams(e.configurationName);e.timeoutId=J(e,e.tokens.expiresAt,a.extras,a.scope);let o=await t.getSessionStateAsync();return await e.startCheckSessionAsync(r.checkSessionIframe,n.client_id,o),n.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{n.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:`service worker is not supported by this browser`});let t=_(e.configurationName,n.storage??sessionStorage,n.login_state_storage??n.storage??sessionStorage),{tokens:i}=await t.initAsync();if(i){e.tokens=Mt(i,null,n.token_renew_mode);let a=t.getLoginParams();e.timeoutId=J(e,e.tokens.expiresAt,a.extras,a.scope);let o=await t.getSessionStateAsync();return await e.startCheckSessionAsync(r.checkSessionIframe,n.client_id,o),n.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:t?`service worker sessions not retrieved`:`session storage sessions not retrieved`}),!1}catch(n){return console.error(n),t&&await t.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,`tokens inside ServiceWorker are invalid`),!1}},ge=class{open(e){window.location.href=e}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){let e=window.location;return e.pathname+(e.search||``)+(e.hash||``)}getOrigin(){return window.origin}},N={STATE_MISSING:`STATE_MISSING`,STATE_MISMATCH:`STATE_MISMATCH`,NONCE_MISSING:`NONCE_MISSING`},_e=new Set(Object.values(N)),ve=e=>typeof e==`string`&&_e.has(e),P=class e extends i{constructor(t,n,r=`callback`){super(t,n,{phase:r,retryable:!1}),this.name=`OidcStateError`,Object.setPrototypeOf(this,e.prototype)}},ye=e=>e instanceof P||a(e)&&ve(e.code),F={ENDPOINT_UNAVAILABLE:`ENDPOINT_UNAVAILABLE`,REQUEST_FAILED:`REQUEST_FAILED`,INVALID_RESPONSE:`INVALID_RESPONSE`},I=class e extends i{constructor(t,n,r={}){super(t,n,{phase:`login`,retryable:r.cause!==void 0||o(r.status),status:r.status,oauthError:r.oauthError,oauthErrorDescription:r.oauthErrorDescription,cause:r.cause}),this.name=`PushedAuthorizationRequestError`,Object.setPrototypeOf(this,e.prototype)}},be=e=>e instanceof I,xe={},Se=(e,t=window.sessionStorage,n)=>{if(!xe[e]&&t){let n=t.getItem(e);n&&(xe[e]=JSON.parse(n))}let r=xe[e],i=1e3*n;return r&&r.timestamp+i>Date.now()?r.result:null},Ce=(e,t,n=window.sessionStorage)=>{let r={result:t,timestamp:Date.now()};xe[e]=r,n&&n.setItem(e,JSON.stringify(r))},we=3600,Te=e=>async(t,n=we,r=window.sessionStorage,i=1e4)=>{let a=`${t}/.well-known/openid-configuration`,o=`oidc.server:${t}`,s=Se(o,r,n);if(s)return new yt(s);let c=await L(e)(a,{},i);if(c.status!==200)return null;let l=await c.json();return Ce(o,l,r),new yt(l)},L=e=>async(t,n={},r=1e4,i=0)=>{let a;try{let i=new AbortController,o=setTimeout(()=>i.abort(),r);try{a=await e(t,{...n,signal:i.signal})}finally{clearTimeout(o)}}catch(a){if(a.name===`AbortError`||a.message===`Network request failed`){if(i<=1)return await L(e)(t,n,r,i+1);throw a}throw console.error(a.message),a}return a},R={refresh_token:`refresh_token`,access_token:`access_token`},Ee=e=>{let t=[];for(let n in e){let r=e[n],i=Array.isArray(r)?r:[String(r)];for(let e of i)t.push(`${encodeURIComponent(n)}=${encodeURIComponent(e)}`)}return t.join(`&`)},De=e=>async(t,n,r=R.refresh_token,i,a={},o=1e4)=>{let s={token:n,token_type_hint:r,client_id:i};for(let[e,t]of Object.entries(a))s[e]===void 0&&(s[e]=t);let c=Ee(s),l=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`},body:c},o);if(l.status!==200){let e=await Oe(l);return{success:!1,status:l.status,oauthError:typeof e?.error==`string`?e.error:void 0,oauthErrorDescription:typeof e?.error_description==`string`?e.error_description:void 0}}return{success:!0,status:l.status}},Oe=async e=>{try{return await e.json()}catch{return null}},ke=e=>async(t,n,r=1e4)=>{if(n.request_uri!==void 0)throw new I(F.REQUEST_FAILED,`The request_uri parameter must not be included in a pushed authorization request.`);let i=Ee(n),a;try{a=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`},body:i},r)}catch(e){throw new I(F.REQUEST_FAILED,`The pushed authorization request could not be sent.`,{cause:e})}let o=await Oe(a);if(a.status!==201){let e=typeof o?.error==`string`?o.error:void 0,t=typeof o?.error_description==`string`?o.error_description:void 0,n=[e,t].filter(Boolean).join(`: `);throw new I(F.REQUEST_FAILED,`The pushed authorization request failed with HTTP status ${a.status}${n?` (${n})`:``}.`,{status:a.status,oauthError:e,oauthErrorDescription:t})}if(typeof o?.request_uri!=`string`||o.request_uri.length===0||!Number.isInteger(o?.expires_in)||o.expires_in<=0)throw new I(F.INVALID_RESPONSE,`The pushed authorization response must contain a non-empty request_uri and a positive integer expires_in.`,{status:a.status});return{request_uri:o.request_uri,expires_in:o.expires_in}},Ae=e=>async(t,n,r,i,a={},o,s=1e4)=>{for(let[e,t]of Object.entries(r))n[e]===void 0&&(n[e]=t);let c=Ee(n),l=await L(e)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`,...a},body:c},s);if(l.status!==200){let e=await Oe(l);return{success:!1,status:l.status,data:e,oauthError:typeof e?.error==`string`?e.error:void 0,oauthErrorDescription:typeof e?.error_description==`string`?e.error_description:void 0,demonstratingProofOfPossessionNonce:l.headers?.has(z)?l.headers.get(z):null}}let u=await l.json(),d=null;return l.headers.has(z)&&(d=l.headers.get(z)),{success:!0,status:l.status,data:Nt(u,i,o),demonstratingProofOfPossessionNonce:d}},je=(e,t)=>async(n,r,i)=>{r=r?{...r}:{};let a=se(128),o=await ue(a);if(await e.setCodeVerifierAsync(a),await e.setStateAsync(r.state),r.code_challenge=o,r.code_challenge_method=`S256`,i){let e=await ke(i.fetch)(i.endpoint,r,i.timeoutMs);t.open(`${n}?client_id=${encodeURIComponent(String(r.client_id))}&request_uri=${encodeURIComponent(e.request_uri)}`);return}let s=``;if(r)for(let[e,t]of Object.entries(r))for(let n of Array.isArray(t)?t:[String(t)])s+=s===``?`?`:`&`,s+=`${e}=${encodeURIComponent(n)}`;t.open(`${n}${s}`)},z=`DPoP-Nonce`,Me=e=>async(t,n,r,i,a=1e4,o=!1)=>{n=n?{...n}:{},n.code_verifier=await e.getCodeVerifierAsync();let s=Ee(n),c=await L(fetch)(t,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded;charset=UTF-8`,...r},body:s},a);if(c.status!==200){let t=await Oe(c),n=typeof t?.error==`string`?t.error:void 0;return o&&n===`use_dpop_nonce`||await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),{success:!1,status:c.status,data:t,oauthError:n,oauthErrorDescription:typeof t?.error_description==`string`?t.error_description:void 0,demonstratingProofOfPossessionNonce:c.headers?.has(z)?c.headers.get(z):null}}await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]);let l=null;c.headers.has(z)&&(l=c.headers.get(z));let u=await c.json();return{success:!0,data:{state:n.state,tokens:Nt(u,null,i),demonstratingProofOfPossessionNonce:l}}},Ne=`x-oidc-resource`,Pe=(e,t)=>`${e}#resource=${encodeURIComponent(t)}`,Fe=e=>{let t=e.indexOf(`#resource=`);return t<0?void 0:decodeURIComponent(e.slice(t+10))},Ie=e=>{if(typeof e!=`string`||!/^[a-z][a-z\d+.-]*:/i.test(e)||e.includes(`#`)||/\s/.test(e))throw Error(`A resource must be an absolute URI without whitespace or a fragment.`);new URL(e)},Le=e=>{let t=new URL(e);if(t.protocol!==`https:`&&t.protocol!==`http:`||t.username||t.password||t.hash||/%2f|%5c/i.test(t.pathname))throw Error(`API destinations must be HTTP(S) URLs without credentials, fragments, or encoded separators.`);return t},Re=e=>{let t=Le(e);if(t.search)throw Error(`An API URL prefix must not contain a query.`);return t},ze=(e,t)=>{let n=Le(t).origin;return e?.some(e=>e.allowedUrlPrefixes.some(e=>Re(e).origin===n))??!1},Be=(e,t)=>{let n=Le(t);return e.allowedUrlPrefixes.some(e=>{let t=Re(e),r=t.pathname.replace(/\/+$/,``);return n.origin===t.origin&&(r===``||n.pathname===r||n.pathname.startsWith(`${r}/`))})},B=(e,t)=>{Ie(t);let n=e?.filter(e=>e.resource===t)??[];if(n.length!==1||n[0].allowedUrlPrefixes.length===0)throw Error(`The resource must be registered exactly once with permitted API URL prefixes.`);for(let e of n[0].allowedUrlPrefixes)Be(n[0],e);return n[0]},Ve=`1.1.0`,He={SKIP_WAITING:`SKIP_WAITING`,CLAIM:`claim`,CLEAR:`clear`,INIT:`init`,SET_STATE:`setState`,GET_STATE:`getState`,SET_CODE_VERIFIER:`setCodeVerifier`,GET_CODE_VERIFIER:`getCodeVerifier`,SET_SESSION_STATE:`setSessionState`,GET_SESSION_STATE:`getSessionState`,SET_NONCE:`setNonce`,GET_NONCE:`getNonce`,SET_DPOP_NONCE:`setDemonstratingProofOfPossessionNonce`,GET_DPOP_NONCE:`getDemonstratingProofOfPossessionNonce`,SET_DPOP_JWK:`setDemonstratingProofOfPossessionJwk`,GET_DPOP_JWK:`getDemonstratingProofOfPossessionJwk`},Ue={ACCESS_TOKEN:`ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER`,REFRESH_TOKEN:`REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER`,NONCE_TOKEN:`NONCE_SECURED_BY_OIDC_SERVICE_WORKER`,CODE_VERIFIER:`CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER`},We=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER`,Ge={TAB_ID:`oidc.tabId.`,STATE:`oidc.state.`,NONCE:`oidc.nonce.`,CODE_VERIFIER:`oidc.code_verifier.`,LOGIN_PARAMS:`oidc.login.`,SW_VERSION_MISMATCH_RELOAD:`oidc.sw.version_mismatch_reload.`},Ke=`oidc.sw.controllerchange_reload_count`,qe=(e,t)=>`${e}${t}`,Je=(e,t,n=`default`)=>`${e}_${t}#tabId=${n}`,Ye=(e,t=`default`)=>`${We}_${e}#tabId=${t}`,Xe=e=>typeof e==`string`&&Object.values(He).includes(e),Ze=e=>{let t=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!t)throw Error(`Invalid URL`);let n=t[6],r=t[7];if(r){let e=r.split(`?`);e.length===2&&(r=e[0],n=e[1])}return n.startsWith(`?`)&&(n=n.slice(1)),{href:e,protocol:t[1],host:t[2],hostname:t[3],port:t[4],path:t[5],search:n,hash:r}},Qe=e=>{let t=Ze(e),{path:n}=t;n.endsWith(`/`)&&(n=n.slice(0,-1));let{hash:r}=t;return(r===`#`||r===`#_=_`)&&(r=``),r&&(n+=r),n},V=e=>{let{search:t}=Ze(e);return $e(t)},$e=e=>{let t={};for(let n of e.split(`&`)){let[e,r]=n.split(`=`);t[decodeURIComponent(e)]=decodeURIComponent(r)}return t},et=`_oidc_resource`,tt=`oidc.resource_transaction.`,H=(e,t)=>t===void 0?e:Pe(e,t),U=(e,n,r)=>{let a=r??n.resource;if(a===void 0)return e;let o=typeof a==`string`?[a]:a;if(o.length===0)throw new i(t.INVALID_RESOURCE,`At least one resource is required.`,{phase:`login`,retryable:!1});for(let e of o)Ie(e),n.resources&&B(n.resources,e);let s=e.resource;if(s!==void 0&&JSON.stringify(typeof s==`string`?[s]:s)!==JSON.stringify(o))throw new i(t.INVALID_RESOURCE,`Resource extras conflict with the selected resource.`,{phase:`login`,retryable:!1});return{...e,resource:a}},nt=(e,t,n)=>{sessionStorage.setItem(`${tt}${e}.${t}`,n)},rt=(e,t)=>{let{state:n}=V(t);return n?sessionStorage.getItem(`${tt}${e}.${n}`)??void 0:void 0},it=(e,t)=>{let{state:n}=V(t);n&&sessionStorage.removeItem(`${tt}${e}.${n}`)},at=(e,t)=>{let n=`${tt}${e}.`;for(let e of Object.keys(sessionStorage))e.startsWith(n)&&(t===void 0||sessionStorage.getItem(e)===t)&&sessionStorage.removeItem(e)},ot=(e,t,n,r,i,a=()=>window.fetch)=>(o=void 0,s=null,c=!1,d=void 0)=>{let f=s;s={...s};let m=s[et];delete s[et];let h=H(e,m);return(async()=>{let g=o||i.getPath();if(`state`in s||(s.state=se(16)),m!==void 0&&nt(e,s.state,m),n(p.loginAsync_begin,{}),s)for(let e of Object.keys(s))e.endsWith(`:token_request`)&&delete s[e];try{let e=c?t.silent_redirect_uri:t.redirect_uri;d||=t.scope;let n=U(t.extras?{...t.extras,...s}:s,t,m);typeof n.scope==`string`&&(d=n.scope),n.nonce||=se(12);let o={nonce:n.nonce},l=await $(t,h),u=await r(t.authority,t.authority_configuration),p;if(l)l.setLoginParams({callbackPath:g,extras:f,scope:d,resource:m}),await l.initAsync(u,`loginAsync`,{...t,scope:d}),await l.setNonceAsync(o),l.startKeepAliveServiceWorker(),p=l;else{let e=_(h,t.storage??sessionStorage,t.login_state_storage??t.storage??sessionStorage);e.setLoginParams({callbackPath:g,extras:f,scope:d,resource:m}),await e.setNonceAsync(o),p=e}let v={client_id:t.client_id,redirect_uri:e,scope:d,response_type:`code`,...n},y=t.par??`disabled`,b=u.pushedAuthorizationRequestEndpoint,x=u.requirePushedAuthorizationRequests;if(!b&&(y===`required`||y===`auto`&&x))throw new I(F.ENDPOINT_UNAVAILABLE,`Pushed Authorization Requests are required, but the authorization server metadata does not provide a pushed_authorization_request_endpoint.`);let S=y!==`disabled`&&b?{endpoint:b,fetch:a(),timeoutMs:t.par_request_timeout}:void 0;await je(p,i)(u.authorizationEndpoint,v,S)}catch(e){let t=u(e)?l(e,`login`):e;throw n(p.loginAsync_error,t),t}})()},st=e=>async(n=!1,r)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});let a=e.configuration,s=H(e.configurationName,r),l=a.client_id,u=n?a.silent_redirect_uri:a.redirect_uri,d=a.authority,f=a.token_request_timeout,m=await e.initAsync(d,a.authority_configuration),h=V(e.location.getCurrentHref()),g=h.session_state,v=await $(a,s),y,b,x,S;if(v)await v.initAsync(m,`loginCallbackAsync`,a),await v.setSessionStateAsync(g),b=await v.getNonceAsync(),x=v.getLoginParams(),S=await v.getStateAsync(),v.startKeepAliveServiceWorker(),y=v;else{let e=_(s,a.storage??sessionStorage,a.login_state_storage??a.storage??sessionStorage);await e.setSessionStateAsync(g),b=await e.getNonceAsync(),x=e.getLoginParams(),S=await e.getStateAsync(),y=e}if(h.error||h.error_description)throw c(h.error,h.error_description,`Error from OIDC server: ${h.error} - ${h.error_description}`,n?`refresh`:`callback`);if(h.iss&&h.iss!==m.issuer)throw console.error(),Error(`Issuer not valid (expected: ${m.issuer}, received: ${h.iss})`);if(h.state){if(!S)throw new P(N.STATE_MISSING,`OIDC state is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).`,n?`refresh`:`callback`);if(h.state!==S)throw new P(N.STATE_MISMATCH,`OIDC state does not match the stored one (expected: ${S}, received: ${h.state}).`,n?`refresh`:`callback`)}if(!b||!b.nonce)throw new P(N.NONCE_MISSING,`OIDC nonce is missing from storage. The login state may have been cleared between the authorization redirect and the callback (e.g., private browsing, storage cleared, or browser eviction).`,n?`refresh`:`callback`);let C=U({code:h.code,grant_type:`authorization_code`,client_id:a.client_id,redirect_uri:u},a,r),w={};if(a.token_request_extras)for(let[e,t]of Object.entries(a.token_request_extras))w[e]=t;if(x?.extras)for(let[e,t]of Object.entries(x.extras))e.endsWith(`:token_request`)&&(w[e.replace(`:token_request`,``)]=t);let T=m.tokenEndpoint,E={},D;if(a.demonstrating_proof_of_possession){if(v)E.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${s}`;else{if(D=r===void 0?await te(window)(a.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm):await _(e.configurationName,a.storage).getDemonstratingProofOfPossessionJwkAsync(),!D)throw new i(t.RESOURCE_TOKEN_UNAVAILABLE,`The original OIDC DPoP key is unavailable.`,{phase:`callback`,retryable:!1});await _(s,a.storage,a.login_state_storage??a.storage).setDemonstratingProofOfPossessionJwkAsync(D),E.DPoP=await ne(window)(a.demonstrating_proof_of_possession_configuration)(D,`POST`,T)}}let O=U({...C,...w},a,r),k=await Me(y)(T,O,E,e.configuration.token_renew_mode,f,a.demonstrating_proof_of_possession);if(!k.success&&k.oauthError===`use_dpop_nonce`&&k.demonstratingProofOfPossessionNonce&&a.demonstrating_proof_of_possession?(await y.setDemonstratingProofOfPossessionNonce(k.demonstratingProofOfPossessionNonce),v||(E.DPoP=await ne(window)(a.demonstrating_proof_of_possession_configuration)(D,`POST`,T,{nonce:k.demonstratingProofOfPossessionNonce})),k=await Me(y)(T,O,E,e.configuration.token_renew_mode,f)):!k.success&&a.demonstrating_proof_of_possession&&await Promise.all([y.setCodeVerifierAsync(null),y.setStateAsync(null)]),!k.success){let e=k.oauthError===`use_dpop_nonce`?t.DPOP_NONCE_REQUIRED:t.TOKEN_REQUEST_FAILED;throw new i(e,`Token request failed`,{phase:n?`refresh`:`callback`,retryable:e===t.DPOP_NONCE_REQUIRED||o(k.status),status:k.status,oauthError:k.oauthError,oauthErrorDescription:k.oauthErrorDescription})}let A,j=k.data.tokens;a.resources?.length&&(j.scope??=x?.scope??a.scope);let M=k.data.demonstratingProofOfPossessionNonce;if(k.data.state!==w.state)throw new i(t.INVALID_STATE,`state is not valid`,{phase:n?`refresh`:`callback`,retryable:!1});if(r!==void 0&&j.idTokenPayload?.nonce!==b.nonce)throw new i(t.INVALID_NONCE,`Resource authorization requires the transaction nonce in a fresh ID token.`,{phase:n?`refresh`:`callback`,retryable:!1});let{isValid:ee,reason:re}=Lt(j,b.nonce,m);if(!ee){let e=`Tokens are not OpenID valid, reason: ${re}`;throw re.startsWith(`Nonce does not match`)?new i(t.INVALID_NONCE,e,{phase:n?`refresh`:`callback`,retryable:!1}):Error(e)}if(v){if(j.refreshToken&&!j.refreshToken.includes(`SECURED_BY_OIDC_SERVICE_WORKER`))throw Error(`Refresh token should be hidden by service worker`);if(M&&j?.accessToken.includes(`SECURED_BY_OIDC_SERVICE_WORKER`))throw Error(`Demonstration of proof of possession require Access token not hidden by service worker`)}if(v)await v.initAsync(m,`syncTokensAsync`,a),A=v.getLoginParams(),M&&await v.setDemonstratingProofOfPossessionNonce(M);else{let e=_(s,a.storage,a.login_state_storage??a.storage);A=e.getLoginParams(),M&&await e.setDemonstratingProofOfPossessionNonce(M)}return r===void 0&&await e.startCheckSessionAsync(m.checkSessionIframe,l,g,n),e.publishEvent(p.loginCallbackAsync_end,{}),{resource:r,tokens:j,state:`request.state`,callbackPath:A.callbackPath,scope:h.scope,extras:A.extras}}catch(t){let r=!a(t)&&u(t)?l(t,n?`refresh`:`callback`):t;throw console.error(r),e.publishEvent(p.loginCallbackAsync_error,r),r}},ct={access_token:`access_token`,refresh_token:`refresh_token`},lt=(e,t)=>{let n={};if(e){for(let[r,i]of Object.entries(e))if(r.endsWith(t)){let e=r.replace(t,``);n[e]=i}return n}return n},ut=e=>{let t={};if(e){for(let[n,r]of Object.entries(e))n.includes(`:`)||(t[n]=r);return t}return t},dt=e=>async t=>{e.resourceTokens&&await e.resourceTokens.clearAllAsync(),x.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();let n=await $(e.configuration,e.configurationName);n?await n.clearAsync(t):await _(e.configurationName,e.configuration.storage,e.configuration.login_state_storage??e.configuration.storage).clearAsync(t),e.tokens=null,e.userInfo=null},ft=(e,t)=>async()=>{let n=e.tokens?.idTokenPayload?.sub??null;await e.destroyAsync(`LOGGED_OUT`);for(let[,r]of Object.entries(t))r===e?e.publishEvent(p.logout_from_same_tab,{}):await e.logoutSameTabAsync(e.configuration.client_id,n)},pt=(e,t,n,r)=>{`id_token_hint`in t||(t.id_token_hint=n),!(`post_logout_redirect_uri`in t)&&r!==null&&(t.post_logout_redirect_uri=r);let i=``;for(let[e,n]of Object.entries(t))n!=null&&(i+=i===``?`?`:`&`,i+=`${e}=${encodeURIComponent(n)}`);return`${e}${i}`},mt=(e,n,r,s,c)=>async(d=void 0,f=null)=>{let m=e.configuration,h;try{h=await e.initAsync(m.authority,m.authority_configuration)}catch(t){let n=u(t)?l(t,`logout`):t;throw e.publishEvent(p.logoutAsync_error,n),n}d&&typeof d!=`string`&&(d=void 0,s.warn(`callbackPathOrUrl path is not a string`));let g=d??c.getPath(),_=!1;d&&(_=d.includes(`https://`)||d.includes(`http://`));let v=d===null?null:_?d:c.getOrigin()+g,y=e.tokens?e.tokens.idToken:``;e.isLoggingOut=!0;try{try{m.resources?.length&&e.resourceTokens&&await e.resourceTokens.withRefreshLockAsync(async()=>{});let n=h.revocationEndpoint;if(n){let a=[],s=e.tokens?e.tokens.accessToken:null;if(s&&m.logout_tokens_to_invalidate.includes(ct.access_token)){let e=lt(f,`:revoke_access_token`),t=De(r)(n,s,R.access_token,m.client_id,e);a.push(t)}let c=e.tokens?e.tokens.refreshToken:null;if(c&&m.logout_tokens_to_invalidate.includes(ct.refresh_token)){let e=lt(f,`:revoke_refresh_token`),t=De(r)(n,c,R.refresh_token,m.client_id,e);a.push(t)}if(e.resourceTokens){let t=await e.resourceTokens.getTokensToRevokeAsync(),i=new Set([s,c].filter(Boolean));for(let e of t)for(let[t,o]of[[R.access_token,e.accessToken],[R.refresh_token,e.refreshToken]])o&&!i.has(o)&&m.logout_tokens_to_invalidate.includes(t)&&(i.add(o),a.push(De(r)(n,o,t,m.client_id,lt(f,t===R.access_token?`:revoke_access_token`:`:revoke_refresh_token`))))}if(a.length>0){let n=await Promise.all(a);for(let r of n)r.success||e.publishEvent(p.logoutAsync_error,new i(t.REQUEST_FAILED,`Token revocation request failed`,{phase:`logout`,retryable:o(r.status),status:r.status,oauthError:r.oauthError,oauthErrorDescription:r.oauthErrorDescription}))}}}catch(t){let n=!a(t)&&u(t)?l(t,`logout`):t;e.publishEvent(p.logoutAsync_error,n),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(n)}let d=lt(f,`:oidc`);if(d&&d.no_reload===`true`){await ft(e,n)(),e.isLoggingOut=!1;return}let g=ut(f);if(h.endSessionEndpoint){let e=pt(h.endSessionEndpoint,g,y,v);c.open(e)}else c.reload();await ft(e,n)()}catch(t){e.isLoggingOut=!1;let n=!a(t)&&u(t)?l(t,`logout`):t;throw e.publishEvent(p.logoutAsync_error,n),n}},W=e=>new i(t.RESOURCE_TOKEN_UNAVAILABLE,e,{phase:`refresh`,retryable:!1}),ht=class{constructor(e){this.oidc=e,this.pending=new Map,this.cached=new Map,this.generations=new Map,this.generation=0,this.refreshQueue=Promise.resolve(),this.renewalTimers=new Map}async contextAsync(e){let{oidc:t}=this,n=H(t.configurationName,e),r=await t.initAsync(t.configuration.authority,t.configuration.authority_configuration),i=await $(t.configuration,n),a=_(n,t.configuration.storage,t.configuration.login_state_storage??t.configuration.storage),o=i?await i.initAsync(r,`resource-token`,t.configuration):await a.initAsync(),s=[];if(`resourceContexts`in o&&o.resourceContexts!==void 0){if(!Array.isArray(o.resourceContexts)||o.resourceContexts.some(e=>typeof e!=`string`))throw W(`The worker returned invalid resource context metadata.`);s.push(...o.resourceContexts)}return{storage:i??a,tokens:o.tokens,server:r,isWorker:i!==null,resourceContexts:s}}validate(e,n,r,a=this.oidc.tokens?.idTokenPayload?.sub){let{oidc:o}=this,s=B(o.configuration.resources,e),c=n.resourceContext;if(!c||c.resource!==e||c.issuer!==r||c.clientId!==o.configuration.client_id||c.configurationName!==o.configurationName||c.subject!==a)throw new i(t.RESOURCE_CONTEXT_MISMATCH,`The token does not belong to this resource and OIDC session.`,{phase:`refresh`,retryable:!1});let l=n.accessTokenPayload;if(l?.iss!==void 0&&l.iss!==r||l&&s.audiences&&!s.audiences.some(e=>(typeof l.aud==`string`?[l.aud]:Array.isArray(l.aud)?l.aud:[]).includes(e)))throw new i(t.RESOURCE_CONTEXT_MISMATCH,`Resource token issuer or configured audience does not match.`,{phase:`refresh`,retryable:!1});if(typeof n.accessToken!=`string`||!n.accessToken||!Number.isFinite(n.expiresAt)||!Number.isFinite(n.issuedAt)||n.refreshToken!=null&&(typeof n.refreshToken!=`string`||!n.refreshToken))throw W(`The provider did not return a usable resource token response.`);if(s.scope&&!s.scope.split(/\s+/).filter(Boolean).every(e=>(n.scope??``).split(/\s+/).includes(e)))throw W(`The provider did not grant the required resource scopes.`)}publicToken(e,t){return{resource:e,issuer:t.resourceContext.issuer,clientId:this.oidc.configuration.client_id,configurationName:this.oidc.configurationName,accessToken:t.accessToken,expiresAt:t.expiresAt,scope:t.scope,tokenType:t.tokenType}}updateSharedRefreshToken(e,t){typeof e.refreshToken==`string`&&e.refreshToken&&this.oidc.tokens&&(this.oidc.tokens={...this.oidc.tokens,refreshToken:e.refreshToken},t||_(this.oidc.configurationName,this.oidc.configuration.storage).setTokens(this.oidc.tokens))}scheduleRenewal(e,t){let n=this.renewalTimers.get(e);if(n&&x.clearTimeout(n),this.oidc.configuration.token_automatic_renew_mode===`AutomaticOnlyWhenFetchExecuted`)return;let r=Math.max(1e3,Math.min(2147483647,(t.expiresAt-Date.now()/1e3-this.renewalMargin(t))*1e3)),i=x.setTimeout(async()=>{this.renewalTimers.delete(e);try{await this.getAccessTokenAsync(e,{forceRenew:!0})}catch(e){console.error(`Resource renewal failed:`,a(e)?e.code:`unexpected error`)}},r);this.renewalTimers.set(e,i)}renewalMargin(e){return Math.min(this.oidc.configuration.refresh_time_before_tokens_expiration_in_second,Math.max(0,(e.expiresAt-e.issuedAt)/2))}async withRefreshLockAsync(e){let t=async()=>{if(navigator.locks){let t=this.oidc.configuration;return navigator.locks.request(`${t.client_id}_${this.oidc.configurationName}_${t.authority}`,e)}return e()},n=this.refreshQueue.then(t,t);return this.refreshQueue=n.then(()=>void 0,()=>void 0),n}async acceptAuthorizationAsync(e,n){let r=this.generation,a=this.generations.get(e)??0,o=await this.contextAsync(e),s=await this.contextAsync();if(r!==this.generation||a!==(this.generations.get(e)??0))throw W(`The resource authorization was cleared.`);let c=n.idTokenPayload?.sub;if(typeof c!=`string`||(this.oidc.tokens?.idTokenPayload?.sub??s.tokens?.idTokenPayload?.sub)!==c)throw new i(t.RESOURCE_CONTEXT_MISMATCH,`Resource authorization must preserve the authenticated subject.`,{phase:`callback`,retryable:!1});if(n.refreshToken&&n.refreshToken===s.tokens?.refreshToken)throw W(`The provider reused a refresh token across separate authorization transactions; use a multi-resource authorization grant instead.`);let l={...n,scope:n.scope??B(this.oidc.configuration.resources,e).scope??this.oidc.configuration.scope,resourceContext:{resource:e,issuer:o.server.issuer,clientId:this.oidc.configuration.client_id,configurationName:this.oidc.configurationName,subject:c,grantResource:e}};this.validate(e,l,o.server.issuer,c),o.isWorker||_(H(this.oidc.configurationName,e),this.oidc.configuration.storage).setTokens(l),this.cached.set(e,l)}getAccessTokenAsync(e,n={}){let r=this.pending.get(e);if(r)return r;let o=this.generation,s=this.generations.get(e)??0,d=this.oidc.tokens?.idTokenPayload?.sub,f=this.oidc.tokens?.idTokenPayload?.nonce,m=()=>this.generation===o&&(this.generations.get(e)??0)===s&&!this.oidc.isLoggingOut&&this.oidc.tokens?.idTokenPayload?.sub===d&&this.oidc.tokens?.idTokenPayload?.nonce===f,h=this.withRefreshLockAsync(async()=>{let{oidc:r}=this,a=B(r.configuration.resources,e);if(!Number.isFinite(r.configuration.refresh_time_before_tokens_expiration_in_second)||r.configuration.refresh_time_before_tokens_expiration_in_second<0)throw W(`Configure a finite, non-negative renewal margin.`);if(!r.tokens||typeof r.tokens.idTokenPayload?.sub!=`string`||!m())throw W(`Sign in before requesting a resource token.`);if(r.configuration.token_request_extras?.resource!==void 0&&r.configuration.token_request_extras.resource!==e)throw new i(t.INVALID_RESOURCE,`Token extras conflict with the selected resource.`,{phase:`refresh`,retryable:!1});let l=await this.contextAsync(e),u=await this.contextAsync();if(!m())throw W(`The resource transaction was cleared.`);let h=u.tokens?.idTokenPayload?.nonce;if(!u.tokens||u.tokens.idTokenPayload?.sub!==d||!u.isWorker&&h!==r.tokens.idTokenPayload?.nonce)throw W(`The original OIDC session changed or is unavailable; restore it before requesting resource tokens.`);let g=l.tokens;if(g&&(this.validate(e,g,l.server.issuer),!n.forceRenew&&Ft(g,this.renewalMargin(g)))){let t=this.cached.get(e);return this.cached.set(e,g),this.scheduleRenewal(e,g),(t?.accessToken!==g.accessToken||t?.expiresAt!==g.expiresAt||t?.scope!==g.scope||t?.tokenType!==g.tokenType)&&r.publishEvent(p.resource_token_acquired,{resource:e}),this.publicToken(e,g)}let v=typeof r.configuration.resource==`string`?[r.configuration.resource]:r.configuration.resource??[],y=(u.tokens.scope??r.configuration.scope).split(/\s+/),b=!a.scope||a.scope.split(/\s+/).filter(Boolean).every(e=>y.includes(e)),x=g?.resourceContext?g.resourceContext.grantResource:v.includes(e)&&b?null:e,C=x===null?await this.contextAsync():l,w=x===null&&!b?void 0:C.tokens?.refreshToken,T=r.configuration.demonstrating_proof_of_possession||C.tokens?.tokenType?.toLowerCase()===`dpop`;if(!m())throw W(`The resource transaction was cleared.`);if(w){let n=await C.storage.getNonceAsync(),u=l.isWorker?{[Ne]:encodeURIComponent(e)}:{};T&&(u.DPoP=await this.generateProofAsync(e,{accessToken:C.tokens.accessToken,url:l.server.tokenEndpoint,method:`POST`,grantResource:x}));let p={client_id:r.configuration.client_id,grant_type:`refresh_token`,refresh_token:w,resource:e,...a.scope?{scope:a.scope}:{}},v=()=>Ae(r.getFetch())(l.server.tokenEndpoint,p,r.configuration.token_request_extras??{},g,u,X.access_token_invalid,r.configuration.token_request_timeout),y=await v();if(!y.success&&y.oauthError===`use_dpop_nonce`&&y.demonstratingProofOfPossessionNonce&&T&&(await C.storage.setDemonstratingProofOfPossessionNonce(y.demonstratingProofOfPossessionNonce),u.DPoP=await this.generateProofAsync(e,{accessToken:C.tokens.accessToken,url:l.server.tokenEndpoint,method:`POST`,grantResource:x}),y=await v()),y.success){let c=await this.contextAsync();if(!c.tokens||c.tokens.idTokenPayload?.sub!==d||!c.isWorker&&c.tokens.idTokenPayload?.nonce!==h)throw W(`The original OIDC session changed during resource renewal.`);g=y.data;let u=this.generation===o&&r.tokens?.idTokenPayload?.sub===d&&r.tokens?.idTokenPayload?.nonce===f;if(u&&x===null&&this.updateSharedRefreshToken(g,l.isWorker),g.idTokenPayload?.sub!==void 0&&g.idTokenPayload.sub!==d)throw new i(t.RESOURCE_CONTEXT_MISMATCH,`Resource renewal changed the authenticated subject.`,{phase:`refresh`,retryable:!1});let p=Lt(g,n?.nonce,l.server);if(!p.isValid)throw W(p.reason);if(g={...g,scope:g.scope??a.scope??C.tokens.scope??r.configuration.scope,resourceContext:{resource:e,issuer:l.server.issuer,clientId:r.configuration.client_id,configurationName:r.configurationName,subject:d,grantResource:x}},this.validate(e,g,l.server.issuer,d),!m())throw u&&r.isLoggingOut&&s===(this.generations.get(e)??0)&&!l.isWorker&&_(H(r.configurationName,e),r.configuration.storage).setTokens(g),W(`The resource transaction was cleared.`);y.demonstratingProofOfPossessionNonce&&await C.storage.setDemonstratingProofOfPossessionNonce(y.demonstratingProofOfPossessionNonce),l.isWorker||_(H(r.configurationName,e),r.configuration.storage).setTokens(g),x===null&&this.updateSharedRefreshToken(g,l.isWorker)}else if(y.oauthError!==`invalid_grant`)throw c(y.oauthError,y.oauthErrorDescription,`Resource token request failed.`,`refresh`,y.status);else g=null}else g=null;if(!g){if(!m())throw W(`The resource transaction was cleared.`);let t=a.scope?[...new Set([`openid`,...a.scope.split(` `)])].join(` `):r.configuration.scope,n=await S(r.configurationName,r.configuration,r.publishEvent.bind(r),`refresh`)({...r.configuration.extras,prompt:`none`,resource:e,[et]:e},null,t);if(!n)throw W(`Configure silent_redirect_uri and silent_login_uri for resource authorization.`);if(n.error)throw n.oidcError??c(n.error,void 0,`Resource silent authorization failed.`,`refresh`);if(!m()||n.resource!==e)throw W(`The resource authorization transaction is no longer current.`);await this.acceptAuthorizationAsync(e,n.tokens),l=await this.contextAsync(e),g=l.tokens??this.cached.get(e)}if(!m())throw W(`The resource transaction was cleared.`);if(this.validate(e,g,l.server.issuer),!Ft(g))throw W(`The resource access token is expired.`);return this.cached.set(e,g),this.scheduleRenewal(e,g),r.publishEvent(p.resource_token_acquired,{resource:e}),this.publicToken(e,g)}).catch(n=>{let r=a(n)?n:u(n)?l(n,`refresh`):new i(t.RESOURCE_TOKEN_UNAVAILABLE,n instanceof Error?n.message:`Resource token acquisition failed.`,{phase:`refresh`,retryable:!1,cause:n});throw this.oidc.publishEvent(p.resource_token_error,{resource:e,error:r}),r}).finally(()=>{this.pending.get(e)===h&&this.pending.delete(e)});return this.pending.set(e,h),h}async generateProofAsync(e,t){let n=this.cached.get(e)?.resourceContext,r=t.grantResource===void 0?n?n.grantResource:e:t.grantResource,i=await this.contextAsync(r??void 0);if(i.isWorker)return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${H(this.oidc.configurationName,e)}`;let a=await i.storage.getDemonstratingProofOfPossessionJwkAsync();if(!a)throw W(`The resource DPoP grant key is unavailable.`);let o=t.url===i.server.tokenEndpoint?await i.storage.getDemonstratingProofOfPossessionNonce():_(H(this.oidc.configurationName,e),this.oidc.configuration.storage).getDemonstratingProofOfPossessionApiNonce();return ne(window)(this.oidc.configuration.demonstrating_proof_of_possession_configuration)(a,t.method,t.url,{ath:await le(t.accessToken),...o?{nonce:o}:{}})}peek(e){if(this.oidc.isLoggingOut)return null;let t=this.cached.get(e);return t&&t.resourceContext?.subject===this.oidc.tokens?.idTokenPayload?.sub&&Ft(t)?this.publicToken(e,t):null}createApiNonceRecorder(e){let t=this.generation,n=this.generations.get(e)??0;return async r=>{t!==this.generation||n!==(this.generations.get(e)??0)||!this.peek(e)?console.warn(`Ignoring a resource API nonce response after its session was cleared.`):this.oidc.configuration.service_worker_relative_url||await _(H(this.oidc.configurationName,e),this.oidc.configuration.storage).setDemonstratingProofOfPossessionApiNonce(r)}}async getTokensToRevokeAsync(){if(!this.oidc.configuration.resources?.length)return[];let e=await this.contextAsync(),t=e.isWorker?e.resourceContexts.map(Fe).filter(e=>e!==void 0):this.oidc.configuration.resources.map(e=>e.resource),n=[];for(let e of t){let t=await this.contextAsync(e);t.tokens&&(this.validate(e,t.tokens,t.server.issuer),n.push(t.tokens))}return n}async clearAsync(e){B(this.oidc.configuration.resources,e),this.generations.set(e,(this.generations.get(e)??0)+1),at(this.oidc.configurationName,e),this.pending.delete(e),this.cached.delete(e);let t=this.renewalTimers.get(e);t&&x.clearTimeout(t),this.renewalTimers.delete(e);let n=await this.contextAsync(e);await n.storage.clearAsync(`LOGGED_OUT`),n.storage.setLoginParams(null),n.isWorker||(await _(H(this.oidc.configurationName,e),this.oidc.configuration.storage).setDemonstratingProofOfPossessionApiNonce(null),await Promise.all([n.storage.setStateAsync(null),n.storage.setCodeVerifierAsync(null),n.storage.setNonceAsync(null),n.storage.setDemonstratingProofOfPossessionJwkAsync(null),n.storage.setDemonstratingProofOfPossessionNonce(null)])),this.oidc.publishEvent(p.resource_token_cleared,{resource:e})}async clearAllAsync(){if(this.oidc.configuration.resources?.length){this.generation++,at(this.oidc.configurationName),this.pending.clear(),this.cached.clear();for(let e of this.renewalTimers.values())x.clearTimeout(e);if(this.renewalTimers.clear(),!this.oidc.configuration.service_worker_relative_url)for(let e of this.oidc.configuration.resources??[]){let t=_(H(this.oidc.configurationName,e.resource),this.oidc.configuration.storage,this.oidc.configuration.login_state_storage??this.oidc.configuration.storage);await t.clearAsync(`LOGGED_OUT`),t.setLoginParams(null),await Promise.all([t.setStateAsync(null),t.setCodeVerifierAsync(null),t.setNonceAsync(null),t.setDemonstratingProofOfPossessionJwkAsync(null),t.setDemonstratingProofOfPossessionNonce(null),t.setDemonstratingProofOfPossessionApiNonce(null)])}}}},G=function(e){return e.AutomaticBeforeTokenExpiration=`AutomaticBeforeTokensExpiration`,e.AutomaticOnlyWhenFetchExecuted=`AutomaticOnlyWhenFetchExecuted`,e}({}),gt=(e,n,r=!1,a=`api_request`)=>async(...o)=>{let[s,c,...u]=o,d=typeof a==`string`?a:`api_request`,f=typeof a==`string`?void 0:a.resource,m;if(f===void 0&&d===`api_request`&&n.configuration.resources?.length)try{let e=new URL(s instanceof Request?s.url:s.toString(),window.location.href).toString();if(ze(n.configuration.resources,e))throw Error(`Select a resource explicitly when fetching a resource-managed API.`)}catch(e){let r=new i(t.INVALID_RESOURCE,e instanceof Error?e.message:`Invalid resource destination.`,{phase:d,retryable:!1,cause:e});throw n.publishEvent(p.apiRequest_error,r),r}if(typeof a!=`string`&&Object.prototype.hasOwnProperty.call(a,`resource`))try{if(typeof f!=`string`)throw Error(`An explicit resource identifier is required.`);if(m=new URL(s instanceof Request?s.url:s.toString(),window.location.href).toString(),!Be(B(n.configuration.resources,f),m))throw Error(`The destination does not belong to the selected resource.`);if(c?.redirect===`follow`)throw Error(`Resource fetch cannot automatically follow redirects.`)}catch(e){let r=new i(t.INVALID_RESOURCE,e instanceof Error?e.message:`Invalid resource destination.`,{phase:d,retryable:!1,cause:e});throw n.publishEvent(p.apiRequest_error,r),r}let h=f===void 0?c?{...c}:{method:`GET`}:{...s instanceof Request?{method:s.method,headers:s.headers,credentials:s.credentials}:{method:`GET`},...c,redirect:c?.redirect??`error`},g=new Headers;h.headers&&(g=f===void 0&&h.headers instanceof Headers?h.headers:new Headers(h.headers));let _={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()=>{let{status:e}=await Et(n)(n.configuration,n.configurationName,n.tokens,!1);return e},renewTokensAsync:n.renewTokensAsync.bind(n)},v=f===void 0?void 0:await n.resourceTokens.getAccessTokenAsync(f),y=f===void 0?await It(_):void 0,b=v?.accessToken??y?.tokens?.accessToken;if(g.has(`Accept`)||g.set(`Accept`,`application/json`),b){if(n.configuration.demonstrating_proof_of_possession&&r||v?.tokenType?.toLowerCase()===`dpop`){let e=f===void 0?await n.generateDemonstrationOfProofOfPossessionAsync(b,s.toString(),h.method):await n.resourceTokens.generateProofAsync(f,{accessToken:b,url:m,method:h.method??`GET`});g.set(`Authorization`,`DPoP ${b}`),g.set(`DPoP`,e)}else g.set(`Authorization`,`Bearer ${b}`);h.credentials||=`same-origin`}let x={...h,headers:g},S=v&&g.has(`DPoP`)?n.resourceTokens.createApiNonceRecorder(f):void 0;if(v&&n.resourceTokens.peek(f)?.accessToken!==v.accessToken){let e=new i(t.RESOURCE_TOKEN_UNAVAILABLE,`The selected resource token was cleared or changed before dispatch.`,{phase:d,retryable:!1});throw n.publishEvent(p.apiRequest_error,e),e}let C;try{C=await e(s,x,...u)}catch(e){let t=l(e,d);throw d===`api_request`&&n.publishEvent(p.apiRequest_error,t),t}let w=C.headers?.get(`DPoP-Nonce`);if(S&&w&&await S(w),!C.ok&&C.headers?.has(`DPoP-Nonce`)&&(C.status===400||C.status===401||C.headers.get(`WWW-Authenticate`)?.includes(`use_dpop_nonce`))){let e=new i(t.DPOP_NONCE_REQUIRED,`DPoP nonce required`,{phase:d,retryable:!0,status:C.status,oauthError:`use_dpop_nonce`});d===`api_request`&&n.publishEvent(p.apiRequest_error,e)}return C},_t=e=>async(n=!1,r=!1)=>{try{if(e.userInfo!=null&&!n)return e.userInfo;let a=!n&&e.configuration.storage?.getItem(`oidc.${e.configurationName}.userInfo`);if(a)return e.userInfo=JSON.parse(a),e.userInfo;let s=e.configuration,c=(await e.initAsync(s.authority,s.authority_configuration)).userInfoEndpoint,l=await(async()=>{let n=await gt(fetch,e,r,`userinfo`)(c);if(n.status!==200){let r=n.headers?.has(`DPoP-Nonce`)&&(n.status===400||n.status===401||n.headers.get(`WWW-Authenticate`)?.includes(`use_dpop_nonce`)),a=new i(r?t.DPOP_NONCE_REQUIRED:t.REQUEST_FAILED,`UserInfo request failed`,{phase:`userinfo`,retryable:r||o(n.status),status:n.status,oauthError:r?`use_dpop_nonce`:void 0});return e.publishEvent(p.userInfoAsync_error,a),null}return n.json()})();return e.userInfo=l,l&&e.configuration.storage?.setItem(`oidc.${e.configurationName}.userInfo`,JSON.stringify(l)),l}catch(t){let n=a(t)?t:u(t)?l(t,`userinfo`):t;throw e.publishEvent(p.userInfoAsync_error,n),n}},vt=()=>fetch,yt=class{constructor(e){this.authorizationEndpoint=e.authorization_endpoint,this.tokenEndpoint=e.token_endpoint,this.revocationEndpoint=e.revocation_endpoint,this.userInfoEndpoint=e.userinfo_endpoint,this.checkSessionIframe=e.check_session_iframe,this.issuer=e.issuer,this.endSessionEndpoint=e.end_session_endpoint,this.pushedAuthorizationRequestEndpoint=e.pushed_authorization_request_endpoint,this.requirePushedAuthorizationRequests=e.require_pushed_authorization_requests??!1}},K={},bt=(e,t=new ge)=>(n,r=`default`)=>(K[r]||(K[r]=new q(n,r,e,t)),K[r]),xt=async e=>{let{parsedTokens:t,callbackPath:n,extras:r,scope:i}=await e.loginCallbackAsync();return e.timeoutId=J(e,t.expiresAt,r,i),{callbackPath:n}},q=class e{constructor(e,t=`default`,n,r=new ge){this.isLoggingOut=!1,this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.clearSessionPromise=null,this.logoutPromise=null;let i=e.silent_login_uri;e.silent_redirect_uri&&!e.silent_login_uri&&(i=`${e.silent_redirect_uri.replace(`-callback`,``).replace(`callback`,``)}-login`);let a=e.refresh_time_before_tokens_expiration_in_second??120;a>60&&(a-=Math.floor(Math.random()*40)),this.location=r??new ge,this.configuration={...e,silent_login_uri:i,token_automatic_renew_mode:e.token_automatic_renew_mode??G.AutomaticBeforeTokenExpiration,monitor_session:e.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:a,silent_login_timeout:e.silent_login_timeout??12e3,token_renew_mode:e.token_renew_mode??X.access_token_or_id_token_invalid,demonstrating_proof_of_possession:e.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:e.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:e.logout_tokens_to_invalidate??[`access_token`,`refresh_token`],service_worker_activate:e.service_worker_activate??me,demonstrating_proof_of_possession_configuration:e.demonstrating_proof_of_possession_configuration??A,preload_user_info:e.preload_user_info??!1,par:e.par??`disabled`,par_request_timeout:e.par_request_timeout??1e4},this.getFetch=n??vt,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.resourceTokens=new ht(this),this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.renewTokensOrThrowAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(e){let t=se(16);return this.events.push({id:t,func:e}),t}removeEventSubscription(e){let t=this.events.filter(t=>t.id!==e);this.events=t}publishEvent(e,t){this.events.forEach(n=>{n.func(e,t)})}static{this.getOrCreate=(e,t)=>(n,r=`default`)=>bt(e,t)(n,r)}static get(e=`default`){return Object.prototype.hasOwnProperty.call(K,e)?K[e]:null}static getOrThrow(t=`default`){let n=e.get(t);if(!n)throw Error(`OIDC library does seem initialized.
2
+ Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${t}"></OidcProvider> component.`);return n}static{this.eventNames=p}_silentLoginCallbackFromIFrame(e=this.tokens,t){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){let n=this.location,r=V(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:e,resource:t,sessionState:r.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(e=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){let t=this.location,n=V(t.getCurrentHref());if(n.error){let e=c(n.error,n.error_description,`Error from OIDC server: ${n.error} - ${n.error_description}`,`refresh`);window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:n.error,error_description:n.error_description,oidcError:d(e)})}`,t.getOrigin())}else window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:e==null?``:e.toString(),oidcError:a(e)?d(e):void 0})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{let e=this.configuration.resources?.length?rt(this.configurationName,this.location.getCurrentHref()):void 0,t=await this.loginCallbackAsync(!0);this._silentLoginCallbackFromIFrame(t.parsedTokens,e)}catch(e){console.error(e),this._silentLoginErrorCallbackFromIFrame(e)}}async initAsync(e,t){if(this.initPromise!==null)return this.initPromise;let n=async()=>{if(t!=null)return new yt({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,pushed_authorization_request_endpoint:t.pushed_authorization_request_endpoint,require_pushed_authorization_requests:t.require_pushed_authorization_requests});let n=await $(this.configuration,this.configurationName)?this.configuration.storage||window.sessionStorage:this.configuration.storage;return await Te(this.getFetch())(e,this.configuration.authority_time_cache_wellknowurl_in_second??3600,n,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=n(),this.initPromise.finally(()=>{this.initPromise=null})}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise===null?(this.tryKeepExistingSessionPromise=he(this),this.tryKeepExistingSessionPromise.finally(()=>{this.tryKeepExistingSessionPromise=null})):this.tryKeepExistingSessionPromise}async startCheckSessionAsync(e,t,n,r=!1){await w(this,K,this.configuration)(e,t,n,r)}async loginAsync(e=void 0,t=null,n=!1,r=void 0,i=!1){return this.logoutPromise&&await this.logoutPromise,this.loginPromise===null?(this.loginPromise=(async()=>(t?._oidc_resource===void 0&&this.configuration.resources?.length&&await this.resourceTokens.clearAllAsync(),i?C(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,r):ot(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location,this.getFetch)(e,t,n,r)))(),this.loginPromise.catch(e=>{throw n&&this._silentLoginErrorCallbackFromIFrame(e),e}).finally(()=>{this.loginPromise=null})):this.loginPromise}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;let r=async()=>{let r=this.configuration.resources?.length?rt(this.configurationName,this.location.getCurrentHref()):void 0,a=await st(this)(n,r),o=a.tokens;if(r!==void 0){if(rt(this.configurationName,this.location.getCurrentHref())!==r)throw new i(t.RESOURCE_TOKEN_UNAVAILABLE,`The resource authorization was cleared.`,{phase:`callback`,retryable:!1});return await this.resourceTokens.acceptAuthorizationAsync(r,o),it(this.configurationName,this.location.getCurrentHref()),{parsedTokens:o,state:a.state,callbackPath:a.callbackPath,scope:a.scope,extras:a.extras}}return await this.resourceTokens.clearAllAsync(),this.tokens=o,await $(this.configuration,H(this.configurationName,r))||_(this.configurationName,this.configuration.storage,this.configuration.login_state_storage??this.configuration.storage).setTokens(o),this.publishEvent(e.eventNames.token_acquired,o),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:o,state:a.state,callbackPath:a.callbackPath,scope:a.scope,extras:a.extras}};return this.loginCallbackPromise=r(),this.loginCallbackPromise.finally(()=>{this.loginCallbackPromise=null})}async generateDemonstrationOfProofOfPossessionAsync(e,t,n,r={}){let i=this.configuration,a={ath:await le(e),...r};if(await $(i,this.configurationName))return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}#tabId=${Wt(this.configurationName)}`;let o=_(this.configurationName,i.storage,i.login_state_storage??i.storage),s=await o.getDemonstratingProofOfPossessionJwkAsync(),c=o.getDemonstratingProofOfPossessionNonce();return c&&(a.nonce=c),await ne(window)(i.demonstrating_proof_of_possession_configuration)(s,n,t,a)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise===null?(this.loginCallbackWithAutoTokensRenewPromise=xt(this),this.loginCallbackWithAutoTokensRenewPromise.finally(()=>{this.loginCallbackWithAutoTokensRenewPromise=null})):this.loginCallbackWithAutoTokensRenewPromise}userInfoAsync(e=!1,t=!1){return this.userInfoPromise===null?(this.userInfoPromise=_t(this)(e,t),this.userInfoPromise.finally(()=>{this.userInfoPromise=null})):this.userInfoPromise}async renewTokensResultAsync(e=null,t=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(!this.timeoutId)return null;x.clearTimeout(this.timeoutId);let n=wt(this,!0,e,t);return this.renewTokensPromise=n,n.finally(()=>{this.renewTokensPromise===n&&(this.renewTokensPromise=null)})}async renewTokensAsync(e=null,t=null){return(await this.renewTokensResultAsync(e,t))?.tokens}async renewTokensOrThrowAsync(e=null,n=null){let r=await this.renewTokensResultAsync(e,n);if(r?.error)throw r.error;if(!r?.tokens)throw new i(t.TOKEN_REQUEST_FAILED,`Token renewal failed`,{phase:`refresh`,retryable:!1});return r.tokens}async destroyAsync(e){return await dt(this)(e)}async clearSessionAsync(){return this.clearSessionPromise?this.clearSessionPromise:(this.clearSessionPromise=ft(this,K)(),this.clearSessionPromise.finally(()=>{this.clearSessionPromise=null}))}async logoutSameTabAsync(e,t){this.configuration.monitor_session&&this.configuration.client_id===e&&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(e,t){this.configuration.monitor_session&&this.configuration.client_id===e&&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(e=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=mt(this,K,this.getFetch(),console,this.location)(e,t),this.logoutPromise.finally(()=>{this.logoutPromise=null}))}},St=(e,n)=>{let r=n?.oauthError===`use_dpop_nonce`?t.DPOP_NONCE_REQUIRED:t.TOKEN_REQUEST_FAILED;return new i(r,e,{phase:`refresh`,retryable:r===t.DPOP_NONCE_REQUIRED||o(n?.status),status:n?.status,oauthError:n?.oauthError,oauthErrorDescription:n?.oauthErrorDescription})};async function Ct(e,t,n,r=null){let i=t=>{e.tokens=t};e.publishEvent(q.eventNames.syncTokensAsync_begin,{});let o;try{o=await Dt(e)(i,0,0,t,n,r)}catch(t){throw e.publishEvent(q.eventNames.syncTokensAsync_error,{message:`sync tokens error`,error:a(t)?t:void 0,exception:t}),t}let{tokens:s,status:c}=o;return e.publishEvent(q.eventNames.syncTokensAsync_end,{status:c}),await $(e.configuration,e.configurationName)||_(e.configurationName,e.configuration.storage,e.configuration.login_state_storage??e.configuration.storage).setTokens(e.tokens),e.tokens?{...o,tokens:s}:(await e.destroyAsync(c),{...o,tokens:null})}async function wt(e,t=!1,n=null,r=null){let i=e.configuration,a=`${i.client_id}_${e.configurationName}_${i.authority}`,o,s=await $(e.configuration,e.configurationName);if(i.resources?.length&&e.resourceTokens)o=await e.resourceTokens.withRefreshLockAsync(()=>Ct(e,t,n,r));else if(i?.storage===window?.sessionStorage&&!s||!navigator.locks)o=await Ct(e,t,n,r);else{let i=`retry`;for(;i===`retry`;)i=await navigator.locks.request(a,{ifAvailable:!0},async i=>i?await Ct(e,t,n,r):(e.publishEvent(q.eventNames.syncTokensAsync_lock_not_available,{lock:`lock not available`}),`retry`));o=i}return o.tokens?(e.timeoutId&&=J(e,e.tokens.expiresAt,n,r),{...o,tokens:e.tokens}):o}async function Tt(e,t=!1,n=null,r=null){return(await wt(e,t,n,r)).tokens}var J=(e,t,n=null,r=null)=>{let i=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&x.clearTimeout(e.timeoutId),x.setTimeout(async()=>{let a={timeLeft:Pt(i,t)};e.publishEvent(q.eventNames.token_timer,a),await Tt(e,!1,n,r)},1e3)},Y={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`},Et=e=>async(t,n,r,i=!1)=>{let a={nonce:null};if(!r)return{tokens:null,status:Y.NOT_CONNECTED,nonce:a};let o,s=await e.initAsync(t.authority,t.authority_configuration),c=await $(t,n);if(c){let{status:e,tokens:n}=await c.initAsync(s,`syncTokensAsync`,t);if(e===`LOGGED_OUT`)return{tokens:null,status:Y.LOGOUT_FROM_ANOTHER_TAB,nonce:a};if(e===`SESSIONS_LOST`)return{tokens:null,status:Y.SESSION_LOST,nonce:a};if(!e||!n)return{tokens:null,status:Y.REQUIRE_SYNC_TOKENS,nonce:a};if(n.issuedAt!==r.issuedAt)return{tokens:n,status:Pt(t.refresh_time_before_tokens_expiration_in_second,n.expiresAt)>0?Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,nonce:await c.getNonceAsync()};o=await c.getNonceAsync()}else{let i=_(n,t.storage??sessionStorage,t.login_state_storage??t.storage??sessionStorage),s=await i.initAsync(),{tokens:c}=s,{status:l}=s;if(c&&=Mt(c,e.tokens,t.token_renew_mode),!c)return{tokens:null,status:Y.LOGOUT_FROM_ANOTHER_TAB,nonce:a};if(l===`SESSIONS_LOST`)return{tokens:null,status:Y.SESSION_LOST,nonce:a};if(c.issuedAt!==r.issuedAt){let e=Pt(t.refresh_time_before_tokens_expiration_in_second,c.expiresAt)>0?Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,n=await i.getNonceAsync();return{tokens:c,status:e,nonce:n}}o=await i.getNonceAsync()}let l=Pt(t.refresh_time_before_tokens_expiration_in_second,r.expiresAt)>0?`TOKENS_VALID`:`TOKENS_INVALID`;return i?{tokens:r,status:`FORCE_REFRESH`,nonce:o}:{tokens:r,status:l,nonce:o}},Dt=e=>async(n,r=0,o=0,s=!1,c=null,d=null,f=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:`GIVE_UP`};let m=6,h=s?2:5;for(;!navigator.onLine&&m>0;)await Vt({milliseconds:1e3}),m--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${m}`});let g=document.hidden,v=g?r:r+1,y=g?o+1:o;if(r>=h||o>=5){n(null);let t=f??St(`refresh token`);return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token`,error:t}),{tokens:null,status:`SESSION_LOST`,error:t}}c||={};let b=e.configuration,x=(t,n=null,r=null)=>S(e.configurationName,e.configuration,e.publishEvent.bind(e),`refresh`)(t,n,r),C=async()=>{try{let r,a=await $(b,e.configurationName);r=a?a.getLoginParams():_(e.configurationName,b.storage,b.login_state_storage??b.storage).getLoginParams();let o={};if(r&&r.extras)for(let[e,t]of Object.entries(r.extras))t!=null&&(o[e]=t);if(c)for(let[e,t]of Object.entries(c))t!=null&&(o[e]=t);o.prompt=`none`,d&&(o.scope=d);let s=await x(o);if(!s){n(null);let t=St(`refresh token silent not active`);return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token silent not active`,error:t}),{tokens:null,status:`SESSION_LOST`,error:t}}if(s.error){n(null);let r=s.oidcError??new i(t.OAUTH_ERROR,`refresh token silent`,{phase:`refresh`,retryable:!1,oauthError:s.error});return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token silent`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}return n(s.tokens),e.publishEvent(q.eventNames.token_renewed,{}),{tokens:s.tokens,status:`LOGGED`}}catch(t){let r=a(t)||!u(t)?t:l(t,`refresh`);return console.error(r),e.publishEvent(p.refreshTokensAsync_silent_error,{message:`exceptionSilent`,exception:r.message,error:a(r)?r:void 0}),await Dt(e)(n,v,y,s,c,d,a(r)?r:f)}};try{let{status:a,tokens:l,nonce:u}=await Et(e)(b,e.configurationName,e.tokens,s);switch(a){case Y.SESSION_LOST:n(null);{let t=f??St(`refresh token session lost`);return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token session lost`,error:t}),{tokens:null,status:`SESSION_LOST`,error:t}}case Y.NOT_CONNECTED:return n(null),{tokens:null,status:null};case Y.TOKENS_VALID:return n(l),{tokens:l,status:`LOGGED_IN`};case Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(l),e.publishEvent(q.eventNames.token_renewed,{reason:`TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID`}),{tokens:l,status:`LOGGED_IN`};case Y.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(p.logout_from_another_tab,{status:`session syncTokensAsync`}),{tokens:null,status:`LOGGED_OUT`};case Y.REQUIRE_SYNC_TOKENS:return b.token_automatic_renew_mode==G.AutomaticOnlyWhenFetchExecuted&&!s?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:`GIVE_UP`}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:r}),await C());default:{if(b.token_automatic_renew_mode==G.AutomaticOnlyWhenFetchExecuted&&Y.FORCE_REFRESH!==a)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:`GIVE_UP`};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:l.refreshToken,status:a,tryNumber:r,backgroundTry:o}),!l.refreshToken)return await C();let f=b.client_id,m=b.redirect_uri,h=b.authority,g={...b.token_request_extras?b.token_request_extras:{}};for(let[e,t]of Object.entries(c))e.endsWith(`:token_request`)&&(g[e.replace(`:token_request`,``)]=t);return await(async()=>{let r=U({client_id:f,redirect_uri:m,grant_type:`refresh_token`,refresh_token:l.refreshToken},b),a=await e.initAsync(h,b.authority_configuration),o=document.hidden?1e4:3e5,x=a.tokenEndpoint,S={};b.demonstrating_proof_of_possession&&(S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(l.accessToken,x,`POST`));let C=await Ae(e.getFetch())(x,r,U(g,b),l,S,b.token_renew_mode,o);if(!C.success&&C.oauthError===`use_dpop_nonce`&&C.demonstratingProofOfPossessionNonce&&b.demonstrating_proof_of_possession){let t=await $(b,e.configurationName);t?await t.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce):await _(e.configurationName,b.storage,b.login_state_storage??b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce),S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(l.accessToken,x,`POST`),C=await Ae(e.getFetch())(x,r,g,l,S,b.token_renew_mode,o)}if(C.success){if(!u||!u.nonce){n(null);let t=new P(N.NONCE_MISSING,`refresh token: nonce missing from storage`,`refresh`);return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token: nonce missing from storage`,error:t}),{tokens:null,status:`SESSION_LOST`,error:t}}let{isValid:r,reason:o}=Lt(C.data,u.nonce,a);if(!r){n(null);let r=new i(o.startsWith(`Nonce does not match`)?t.INVALID_NONCE:t.TOKEN_REQUEST_FAILED,`refresh token return not valid tokens, reason: ${o}`,{phase:`refresh`,retryable:!1});return e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${o}`,error:r}),{tokens:null,status:`SESSION_LOST`,error:r}}if(n(C.data),C.demonstratingProofOfPossessionNonce){let t=await $(b,e.configurationName);t?await t.setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce):await _(e.configurationName,b.storage,b.login_state_storage??b.storage).setDemonstratingProofOfPossessionNonce(C.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:C.success}),e.publishEvent(q.eventNames.token_renewed,{reason:`REFRESH_TOKEN`}),{tokens:C.data,status:`LOGGED_IN`}}{let t=St(`Token request failed`,C);return e.publishEvent(p.refreshTokensAsync_silent_error,{message:`bad request`,tokenResponse:C,error:t}),C.status>=400&&C.status<500?(n(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${C.status}`,error:t}),{tokens:null,status:`SESSION_LOST`,error:t}):await Dt(e)(n,v,y,s,c,d,t)}})()}}}catch(t){let r=a(t)||!u(t)?t:l(t,`refresh`);return console.error(r),e.publishEvent(p.refreshTokensAsync_silent_error,{message:`exception`,exception:r.message,error:a(r)?r:void 0}),new Promise((t,i)=>{setTimeout(()=>{Dt(e)(n,v,y,s,c,d,a(r)?r:f).then(t).catch(i)},1e3)})}},Ot=e=>decodeURIComponent(Array.prototype.map.call(atob(e),e=>`%`+(`00`+e.charCodeAt(0).toString(16)).slice(-2)).join(``)),kt=e=>JSON.parse(Ot(e.replaceAll(/-/g,`+`).replaceAll(/_/g,`/`))),At=e=>{try{if(!e)return null;let t=e.split(`.`);return t.length===3?kt(t[1]):null}catch(e){console.warn(e)}return null},X={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 jt(e,t,n){return e.issuedAt?typeof e.issuedAt==`string`?parseInt(e.issuedAt,10):e.issuedAt:t&&t.iat?t.iat:n&&n.iat?n.iat:new Date().getTime()/1e3}var Mt=(e,t=null,n)=>{if(!e)return null;let r,i=typeof e.expiresIn==`string`?parseInt(e.expiresIn,10):e.expiresIn;r=e.accessTokenPayload===void 0?At(e.accessToken):e.accessTokenPayload;let a;a=t!=null&&`idToken`in t&&!(`idToken`in e)?t.idToken:e.idToken;let o=e.idTokenPayload?e.idTokenPayload:At(a),s=o&&o.exp?o.exp:Number.MAX_VALUE,c=r&&r.exp?r.exp:e.issuedAt+i;e.issuedAt=jt(e,r,o);let l;l=e.expiresAt?e.expiresAt:n===X.access_token_invalid?c:n===X.id_token_invalid||s<c?s:c;let u={...e,idTokenPayload:o,accessTokenPayload:r,expiresAt:l,idToken:a};if(t!=null&&`refreshToken`in t&&!(`refreshToken`in e)){let e=t.refreshToken;return{...u,refreshToken:e}}return u},Nt=(e,t,n)=>{if(!e)return null;e.issued_at||=new Date().getTime()/1e3;let r={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope??t?.scope,tokenType:e.token_type,issuedAt:e.issued_at};return e.resourceContext!==void 0&&Object.assign(r,{resourceContext:e.resourceContext}),`refresh_token`in e&&(r.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(r.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(r.idTokenPayload=e.idTokenPayload),Mt(r,t,n)},Pt=(e,t)=>{let n=t-new Date().getTime()/1e3;return Math.round(n-e)},Ft=(e,t=0)=>e?Pt(t,e.expiresAt)>0:!1,It=async(e,t=200,n=50)=>{let r=n,i=await e.syncTokensInfoAsync();for(;[Y.REQUIRE_SYNC_TOKENS,Y.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID,Y.TOKENS_INVALID].includes(i)&&r>0;){if(e.configuration.token_automatic_renew_mode==G.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}await Vt({milliseconds:t}),--r,i=await e.syncTokensInfoAsync()}return{isTokensValid:Ft(e.getTokens()),tokens:e.getTokens(),numberWaited:r-n}},Lt=(e,t,n)=>{if(e.idTokenPayload){let r=e.idTokenPayload;if(n.issuer!==r.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${n.issuer} !== (idTokenPayload issuer) ${r.iss}`};let i=new Date().getTime()/1e3;if(r.exp&&r.exp<i)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${r.exp} < (currentTimeUnixSecond) ${i}`};let a=604800;if(r.iat&&r.iat+a<i)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${r.iat+a} < (currentTimeUnixSecond) ${i}`};if(r.nonce&&r.nonce!==t)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${r.nonce} !== (nonce) ${t}`}}return{isValid:!0,reason:``}},Rt=`7.30.0`,zt=null,Bt,Vt=({milliseconds:e})=>new Promise(t=>x.setTimeout(t,e)),Ht=(e=`/`)=>{try{Bt=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Bt.signal}).catch(e=>{console.log(e)}),Vt({milliseconds:15e4}).then(()=>Ht(e))}catch(e){console.log(e)}},Ut=()=>{Bt&&Bt.abort()},Wt=e=>{Fe(e)!==void 0&&(e=e.split(`#resource=`)[0]);let t=`oidc.tabId.${e}`,n=sessionStorage.getItem(t);if(n)return n;let r=globalThis.crypto.randomUUID();return sessionStorage.setItem(t,r),r},Gt=e=>navigator.serviceWorker.controller??e.active??e.waiting??e.installing??null,Z=(e,t)=>n=>{let r=t?.timeoutMs??5e3;return new Promise((t,i)=>{let a=Gt(e);if(!a){i(Error(`Service worker target not available (controller/active/waiting/installing missing)`));return}let o=new MessageChannel,s=null,c=()=>{try{s!=null&&(x.clearTimeout(s),s=null),o.port1.onmessage=null,o.port1.close(),o.port2.close()}catch(e){console.error(e)}};s=x.setTimeout(()=>{c(),i(Error(`Service worker did not respond within ${r}ms (type=${n?.type})`))},r),o.port1.onmessage=e=>{c(),e?.data?.error?i(e.data.error):t(e.data)};try{let e=n?.configurationName;a.postMessage({...n,tabId:Wt(e??`default`)},[o.port2])}catch(e){c(),i(e)}})},Kt=async e=>navigator.serviceWorker.controller?navigator.serviceWorker.controller:new Promise(t=>{let n=!1,r=()=>{n||(n=!0,navigator.serviceWorker.removeEventListener(`controllerchange`,r),t(navigator.serviceWorker.controller??null))};navigator.serviceWorker.addEventListener(`controllerchange`,r),x.setTimeout(()=>{n||(n=!0,navigator.serviceWorker.removeEventListener(`controllerchange`,r),t(navigator.serviceWorker.controller??null))},e)}),qt=!1,Q=!1,Jt=new Map,Yt=e=>e instanceof DOMException?e.name===`AbortError`:e?.name===`AbortError`,Xt=`oidc.sw.controllerchange_reload_count`,Zt=3,Qt=()=>{try{return parseInt(sessionStorage.getItem(Xt)??`0`,10)}catch{return 0}},$t=()=>{let e=Qt()+1;try{sessionStorage.setItem(Xt,String(e))}catch{}return e},en=()=>{try{sessionStorage.removeItem(Xt)}catch{}},$=async(e,n)=>{let r=e.service_worker_relative_url,a=Fe(n),o=n.split(`#resource=`)[0],s=()=>{if(a!==void 0&&r)throw new i(t.RESOURCE_WORKER_UNSUPPORTED,`Resource token isolation requires an available, compatible Service Worker.`,{phase:`refresh`,retryable:!1});return null};if(typeof window>`u`||typeof navigator>`u`||!navigator.serviceWorker||!r||e.service_worker_activate()===!1)return s();let c=`${r}${r.includes(`?`)?`&`:`?`}v=${Rt}`,l=e.service_worker_register?r:c;Jt.has(l)||Jt.set(l,e.service_worker_register?e.service_worker_register(r):navigator.serviceWorker.register(c,{updateViaCache:`none`}));let u=null;try{u=await Jt.get(l)}catch(e){if(Yt(e))return Jt.delete(l),console.warn(`oidc-client: service worker registration was aborted (likely tab shutdown or backgrounding); falling back to non–service-worker mode.`,e),s();throw e}let d=`oidc.sw.version_mismatch_reload.${n}`,f=async e=>{Ut(),console.log(`New SW waiting – SKIP_WAITING`);try{await new Promise((t,r)=>{let i=new MessageChannel,a=null,o=()=>{try{a!=null&&(x.clearTimeout(a),a=null),i.port1.onmessage=null,i.port1.close(),i.port2.close()}catch(e){console.error(e)}};a=x.setTimeout(()=>{o(),r(Error(`SKIP_WAITING did not respond within 8000ms`))},8e3),i.port1.onmessage=e=>{o(),e?.data?.error?r(e.data.error):t()};try{e.postMessage({type:`SKIP_WAITING`,configurationName:n,data:null,tabId:Wt(n??`default`)},[i.port2])}catch(e){o(),r(e)}})}catch(e){console.warn(`SKIP_WAITING failed`,e)}},p=async()=>{let e=u.waiting;e?await f(e):console.warn(`sendSkipWaiting called but no waiting service worker found`)},m=e=>{Ut(),e.addEventListener(`statechange`,async()=>{if(e.state===`installed`&&navigator.serviceWorker.controller){if(Qt()>=Zt){console.warn(`SW trackInstallingWorker: skipping SKIP_WAITING because the reload budget is exhausted`);return}await f(e)}})};u.addEventListener(`updatefound`,()=>{let e=u.installing;e&&m(e)}),u.installing?m(u.installing):u.waiting&&navigator.serviceWorker.controller&&(Qt()<Zt?p():console.warn(`SW: a waiting worker exists but reload budget is exhausted – skipping activation`)),u.update().catch(e=>{console.error(e)});try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||(await Z(u,{timeoutMs:8e3})({type:`claim`,configurationName:n,data:null}),await Kt(2e3))}catch(e){return console.warn(`Failed init ServiceWorker ${e?.toString?.()??String(e)}`),s()}qt||(qt=!0,navigator.serviceWorker.addEventListener(`controllerchange`,()=>{if(Q)return;let e=$t();e>Zt?console.warn(`SW controllerchange: reload budget exhausted (${e-1} reloads). Skipping reload to avoid infinite loop.`):(Q=!0,console.log(`SW controller changed – reloading page`),Ut(),window.location.reload())}));let h=async e=>Z(u)({type:`clear`,data:{status:e},configurationName:n}),g=async(e,r,s)=>{let c={token_renew_mode:s.token_renew_mode,client_id:s.client_id,scope:s.scope,resource:s.resource,resources:s.resources,service_worker_convert_all_requests_to_cors:s.service_worker_convert_all_requests_to_cors};if(a!==void 0&&(await Z(u)({type:`init`,configurationName:o,data:{oidcServerConfiguration:e,where:`resource-capability`,oidcConfiguration:c}})).resourceTokenManagement!==!0)throw new i(t.RESOURCE_WORKER_UNSUPPORTED,`Update OidcServiceWorker.js before using resource tokens.`,{phase:`refresh`,retryable:!1});let l=await Z(u)({type:`init`,data:{oidcServerConfiguration:e,where:r,oidcConfiguration:c},configurationName:n}),f=l.version;if(f!==`7.30.0`){console.warn(`Service worker ${f} version mismatch with js client version ${Rt}, unregistering and reloading`);let e=parseInt(sessionStorage.getItem(d)??`0`,10);if(e<3){if(sessionStorage.setItem(d,String(e+1)),u.waiting)return await p(),await Vt({milliseconds:500}),Q||(Q=!0,window.location.reload()),new Promise(()=>{});{Ut();try{await u.update()}catch(e){console.error(e)}let e=await u.unregister();return console.log(`Service worker unregistering ${e}`),await Vt({milliseconds:500}),Q||(Q=!0,window.location.reload()),new Promise(()=>{})}}console.error(`Service worker version mismatch persists after ${e} attempt(s). Continuing with mismatched version.`)}else sessionStorage.removeItem(d),en();return{tokens:Nt(l.tokens,null,s.token_renew_mode),status:l.status,resourceContexts:l.resourceContexts}},_=(e=`/`)=>{zt??(zt=`not_null`,Ht(e))},v=e=>Z(u)({type:`setSessionState`,data:{sessionState:e},configurationName:n}),y=async()=>(await Z(u)({type:`getSessionState`,data:null,configurationName:n})).sessionState,b=e=>(a===void 0&&(sessionStorage[`oidc.nonce.${n}`]=e.nonce),Z(u)({type:`setNonce`,data:{nonce:e},configurationName:n})),S=async(e=!0)=>{let t=(await Z(u)({type:`getNonce`,data:null,configurationName:n})).nonce;return a===void 0&&(t||(t=sessionStorage[`oidc.nonce.${n}`],console.warn(`nonce not found in service worker, using sessionStorage`),e&&(await b(t),t=(await S(!1)).nonce))),{nonce:t}},C={},w=e=>{e==null?(delete C[n],delete localStorage[`oidc.login.${n}`]):(C[n]=e,localStorage[`oidc.login.${n}`]=JSON.stringify(e))},T=()=>{if(C[n])return C[n];let e=localStorage[`oidc.login.${n}`];if(typeof e!=`string`||e===``||e===`undefined`||e===`null`)return null;try{C[n]=JSON.parse(e)}catch{return null}return C[n]},E=async e=>{await Z(u)({type:`setDemonstratingProofOfPossessionNonce`,data:{demonstratingProofOfPossessionNonce:e},configurationName:n})},D=async()=>(await Z(u)({type:`getDemonstratingProofOfPossessionNonce`,data:null,configurationName:n})).demonstratingProofOfPossessionNonce,O=async e=>{let t=JSON.stringify(e);await Z(u)({type:`setDemonstratingProofOfPossessionJwk`,data:{demonstratingProofOfPossessionJwkJson:t},configurationName:n})},k=async()=>{let e=await Z(u)({type:`getDemonstratingProofOfPossessionJwk`,data:null,configurationName:n});return e.demonstratingProofOfPossessionJwkJson?JSON.parse(e.demonstratingProofOfPossessionJwkJson):null},A=async(e=!0)=>{let t=(await Z(u)({type:`getState`,data:null,configurationName:n})).state;return a===void 0&&(t||(t=sessionStorage[`oidc.state.${n}`],console.warn(`state not found in service worker, using sessionStorage`),e&&(await j(t),t=await A(!1)))),t},j=async e=>(a===void 0&&(sessionStorage[`oidc.state.${n}`]=e),Z(u)({type:`setState`,data:{state:e},configurationName:n})),M=async(e=!0)=>{let t=(await Z(u)({type:`getCodeVerifier`,data:null,configurationName:n})).codeVerifier;return a===void 0&&(t||(t=sessionStorage[`oidc.code_verifier.${n}`],console.warn(`codeVerifier not found in service worker, using sessionStorage`),e&&(await ee(t),t=await M(!1)))),t},ee=async e=>(a===void 0&&(sessionStorage[`oidc.code_verifier.${n}`]=e),Z(u)({type:`setCodeVerifier`,data:{codeVerifier:e},configurationName:n}));return{clearAsync:h,initAsync:g,startKeepAliveServiceWorker:()=>_(e.service_worker_keep_alive_path),setSessionStateAsync:v,getSessionStateAsync:y,setNonceAsync:b,getNonceAsync:S,setLoginParams:w,getLoginParams:T,getStateAsync:A,setStateAsync:j,getCodeVerifierAsync:M,setCodeVerifierAsync:ee,setDemonstratingProofOfPossessionNonce:E,getDemonstratingProofOfPossessionNonce:D,setDemonstratingProofOfPossessionJwkAsync:O,getDemonstratingProofOfPossessionJwkAsync:k,signalAsync:(e,t)=>Z(u,t)({...e,configurationName:e.configurationName??n})}},tn=async(e,t,n,r)=>{let i=await $(e,t);if(!i)throw Error(`signalServiceWorkerAsync: no service worker registered for configuration "${t}"`);return i.signalAsync(n,r)},nn=class e{constructor(e){this._oidc=e}subscribeEvents(e){return this._oidc.subscribeEvents(e)}removeEventSubscription(e){this._oidc.removeEventSubscription(e)}publishEvent(e,t){this._oidc.publishEvent(e,t)}static{this.getOrCreate=(t,n=new ge)=>(r,i=`default`)=>new e(q.getOrCreate(t,n)(r,i))}static get(t=`default`){let n=q.get(t);return n?new e(n):null}static getOrThrow(t=`default`){return new e(q.getOrThrow(t))}static{this.eventNames=q.eventNames}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(e=void 0,t=null,n=!1,r=void 0,i=!1){return this._oidc.loginAsync(e,t,n,r,i)}logoutAsync(e=void 0,t=null){return this._oidc.logoutAsync(e,t)}clearSessionAsync(){return this._oidc.clearSessionAsync()}get isLoggingOut(){return this._oidc.isLoggingOut===!0}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(e=null,t=null){return this._oidc.renewTokensAsync(e,t)}renewTokensOrThrowAsync(e=null,t=null){return this._oidc.renewTokensOrThrowAsync(e,t)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(e,t,n,r={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(e,t,n,r)}async getValidTokenAsync(e=200,t=50){let n=this._oidc;return It({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()=>{let{status:e}=await Et(n)(n.configuration,n.configurationName,n.tokens,!1);return e},renewTokensAsync:n.renewTokensAsync.bind(n)},e,t)}getAccessTokenForResourceAsync(e,t){return this._oidc.resourceTokens.getAccessTokenAsync(e,t)}getAccessTokenForResource(e){return this._oidc.resourceTokens.peek(e)}clearResourceTokensAsync(e){return this._oidc.resourceTokens.clearAsync(e)}fetchForResource(e,t=window.fetch,n={}){return this.fetchWithTokens(t,n.demonstratingProofOfPossession??!1,{resource:e})}fetchWithTokens(e,t=!1,n={}){return gt(e,this._oidc,n.demonstratingProofOfPossession??t,n)}async userInfoAsync(e=!1,t=!1){return this._oidc.userInfoAsync(e,t)}userInfo(){return this._oidc.userInfo}async signalServiceWorker(e,t){return tn(this._oidc.configuration,this._oidc.configurationName,e,t)}};e.DPOP_TOKEN_PLACEHOLDER_PREFIX=We,e.OidcClient=nn,e.OidcError=i,e.OidcErrorCode=t,e.OidcLocation=ge,e.OidcStateError=P,e.OidcStateErrorCode=N,e.PROTOCOL_VERSION=Ve,e.PushedAuthorizationRequestError=I,e.PushedAuthorizationRequestErrorCode=F,e.STORAGE_KEY_PREFIX=Ge,e.SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY=Ke,e.ServiceWorkerMessageType=He,e.TOKEN_PLACEHOLDERS=Ue,e.TokenAutomaticRenewMode=G,e.TokenRenewMode=X,e.buildDpopSecuredPlaceholder=Ye,e.buildSecuredTokenPlaceholder=Je,e.buildStorageKey=qe,e.getFetchDefault=vt,e.getParseQueryStringFromLocation=V,e.getPath=Qe,e.isOidcError=a,e.isOidcStateError=ye,e.isPushedAuthorizationRequestError=be,e.isServiceWorkerMessageType=Xe,e.signalServiceWorkerAsync=tn});
@@ -20,6 +20,8 @@ export declare const initSession: (configurationName: any, storage?: Storage, lo
20
20
  setCodeVerifierAsync: (codeVerifier: any) => Promise<void>;
21
21
  setDemonstratingProofOfPossessionNonce: (dpopNonce: string) => Promise<void>;
22
22
  getDemonstratingProofOfPossessionNonce: () => string;
23
+ setDemonstratingProofOfPossessionApiNonce: (nonce: string) => Promise<void>;
24
+ getDemonstratingProofOfPossessionApiNonce: () => string | undefined;
23
25
  setDemonstratingProofOfPossessionJwkAsync: (jwk: JsonWebKey) => void;
24
26
  getDemonstratingProofOfPossessionJwkAsync: () => JsonWebKey;
25
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"initSession.d.ts","sourceRoot":"","sources":["../src/initSession.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,WAAW,GACtB,sBAAiB,EACjB,iBAAwB,EACxB,oBAAoB,OAAO;;;;;;;;;;;;;;;;;2BAwGS,MAAM;;;wDA/CuB,MAAM;kDAIpB,MAAM;qDAjBD,UAAU;;CA4FnE,CAAC"}
1
+ {"version":3,"file":"initSession.d.ts","sourceRoot":"","sources":["../src/initSession.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,WAAW,GACtB,sBAAiB,EACjB,iBAAwB,EACxB,oBAAoB,OAAO;;;;;;;;;;;;;;;;;2BA+GS,MAAM;;;wDAtDuB,MAAM;kDAIpB,MAAM;uDAIO,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;qDAIhC,MAAM,GAAG,SAAS;qDAzBhB,UAAU;;CAqGnE,CAAC"}
@@ -17,31 +17,7 @@ export declare const sleepAsync: ({ milliseconds }: {
17
17
  export declare const defaultServiceWorkerUpdateRequireCallback: (location: ILOidcLocation) => (registration: any, stopKeepAlive: () => void) => Promise<void>;
18
18
  export declare const getTabId: (configurationName: string) => string;
19
19
  export declare const registrationCache: Map<string, Promise<ServiceWorkerRegistration>>;
20
- export declare const initWorkerAsync: (configuration: OidcConfiguration, configurationName: string) => Promise<{
21
- clearAsync: (status: any) => Promise<any>;
22
- initAsync: (oidcServerConfiguration: any, where: any, oidcConfiguration: OidcConfiguration) => Promise<{
23
- tokens: import('./parseTokens.js').Tokens;
24
- status: any;
25
- }>;
26
- startKeepAliveServiceWorker: () => void;
27
- setSessionStateAsync: (sessionState: string) => Promise<any>;
28
- getSessionStateAsync: () => Promise<any>;
29
- setNonceAsync: (nonce: any) => Promise<any>;
30
- getNonceAsync: (fallback?: boolean) => Promise<{
31
- nonce: any;
32
- }>;
33
- setLoginParams: (data: any) => void;
34
- getLoginParams: () => any;
35
- getStateAsync: (fallback?: boolean) => Promise<any>;
36
- setStateAsync: (state: string) => Promise<any>;
37
- getCodeVerifierAsync: (fallback?: boolean) => Promise<any>;
38
- setCodeVerifierAsync: (codeVerifier: string) => Promise<any>;
39
- setDemonstratingProofOfPossessionNonce: (demonstratingProofOfPossessionNonce: string) => Promise<void>;
40
- getDemonstratingProofOfPossessionNonce: () => Promise<any>;
41
- setDemonstratingProofOfPossessionJwkAsync: (demonstratingProofOfPossessionJwk: JsonWebKey) => Promise<void>;
42
- getDemonstratingProofOfPossessionJwkAsync: () => Promise<any>;
43
- signalAsync: (message: ServiceWorkerSignalMessage, options?: ServiceWorkerSignalOptions) => Promise<any>;
44
- }>;
20
+ export declare const initWorkerAsync: (configuration: OidcConfiguration, configurationName: string) => Promise<any>;
45
21
  /**
46
22
  * Sends a typed message to the OIDC service worker for the given
47
23
  * configuration. Wraps `MessageChannel` setup, request/response correlation
@@ -1 +1 @@
1
- {"version":3,"file":"initWorker.d.ts","sourceRoot":"","sources":["../src/initWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,eAAO,MAAM,UAAU,GAAI,kBAAkB;IAAE,YAAY,EAAE,GAAG,CAAA;CAAE,qBAEjE,CAAC;AA4BF,eAAO,MAAM,yCAAyC,GACnD,UAAU,cAAc,MAAY,cAAc,GAAG,EAAE,eAAe,MAAM,IAAI,kBAOhF,CAAC;AAEJ,eAAO,MAAM,QAAQ,GAAI,mBAAmB,MAAM,WAQjD,CAAC;AAuGF,eAAO,MAAM,iBAAiB,iDAAwD,CAAC;AA+CvF,eAAO,MAAM,eAAe,GAC1B,eAAe,iBAAiB,EAChC,mBAAmB,MAAM;;6EA2NJ,iBAAiB;;;;;yCAkFM,MAAM;;;+BA2BX,OAAO;;;;;+BAkGP,OAAO;2BAoBV,MAAM;sCASI,OAAO;yCAoBH,MAAM;kFA1FjB,MAAM;;mFAmBR,UAAU;;2BAiFpC,0BAA0B,YACzB,0BAA0B,KACnC,OAAO,CAAC,GAAG,CAAC;EA8BhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,iBAAiB,EAChC,mBAAmB,MAAM,EACzB,SAAS,0BAA0B,EACnC,UAAU,0BAA0B,KACnC,OAAO,CAAC,GAAG,CAQb,CAAC"}
1
+ {"version":3,"file":"initWorker.d.ts","sourceRoot":"","sources":["../src/initWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAElD,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,eAAO,MAAM,UAAU,GAAI,kBAAkB;IAAE,YAAY,EAAE,GAAG,CAAA;CAAE,qBAEjE,CAAC;AA4BF,eAAO,MAAM,yCAAyC,GACnD,UAAU,cAAc,MAAY,cAAc,GAAG,EAAE,eAAe,MAAM,IAAI,kBAOhF,CAAC;AAEJ,eAAO,MAAM,QAAQ,GAAI,mBAAmB,MAAM,WAWjD,CAAC;AAuGF,eAAO,MAAM,iBAAiB,iDAAwD,CAAC;AA+CvF,eAAO,MAAM,eAAe,GAC1B,eAAe,iBAAiB,EAChC,mBAAmB,MAAM,iBAojB1B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,iBAAiB,EAChC,mBAAmB,MAAM,EACzB,SAAS,0BAA0B,EACnC,UAAU,0BAA0B,KACnC,OAAO,CAAC,GAAG,CAQb,CAAC"}
package/dist/jwt.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,2CAA2C,EAAE,MAAM,SAAS,CAAC;AAgCtE,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,WAOjD,CAAC;AAUF,eAAO,MAAM,kDAAkD,EAAE,2CAc9D,CAAC;AAuEJ,eAAO,MAAM,GAAG;cAnEV,GAAG,MAEL,QAAG,EACH,YAAO,EACP,WAAM,EACN,6CAA6C,2CAA2C,EACxF,sBAA0B;CA6DH,CAAC;AAqD5B,eAAO,MAAM,GAAG;oBAtBO,GAAG,MAAY,QAAG,EAAE,iBAAiB,mBAAmB;CAsB9C,CAAC;AAElC,eAAO,MAAM,gBAAgB,GAC1B,GAAG,GAAG,MAAY,sBAAsB,qBAAqB,GAAG,cAAc,iBAO9E,CAAC;AAEJ,eAAO,MAAM,8CAA8C,GACxD,GAAG,GAAG,MACN,6CAA6C,2CAA2C,MAClF,QAAG,EAAE,cAAe,EAAE,KAAK,MAAM,EAAE,iBAAiB,oBAuB1D,CAAC"}
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,2CAA2C,EAAE,MAAM,SAAS,CAAC;AAgCtE,eAAO,MAAM,gBAAgB,GAAI,OAAO,UAAU,WAOjD,CAAC;AAUF,eAAO,MAAM,kDAAkD,EAAE,2CAc9D,CAAC;AAuEJ,eAAO,MAAM,GAAG;cAnEV,GAAG,MAEL,QAAG,EACH,YAAO,EACP,WAAM,EACN,6CAA6C,2CAA2C,EACxF,sBAA0B;CA6DH,CAAC;AAqD5B,eAAO,MAAM,GAAG;oBAtBO,GAAG,MAAY,QAAG,EAAE,iBAAiB,mBAAmB;CAsB9C,CAAC;AAElC,eAAO,MAAM,gBAAgB,GAC1B,GAAG,GAAG,MAAY,sBAAsB,qBAAqB,GAAG,cAAc,iBAO9E,CAAC;AAEJ,eAAO,MAAM,8CAA8C,GACxD,GAAG,GAAG,MACN,6CAA6C,2CAA2C,MAClF,QAAG,EAAE,cAAe,EAAE,KAAK,MAAM,EAAE,iBAAiB,oBA0B1D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=legacyCompatibility.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacyCompatibility.spec.d.ts","sourceRoot":"","sources":["../src/legacyCompatibility.spec.ts"],"names":[],"mappings":""}
package/dist/login.d.ts CHANGED
@@ -3,7 +3,8 @@ import { default as Oidc } from './oidc';
3
3
  import { Fetch, OidcConfiguration, StringMap } from './types.js';
4
4
  export type InitAsyncFunction = (authority: string, authorityConfiguration: any) => Promise<any>;
5
5
  export declare const defaultLoginAsync: (configurationName: string, configuration: OidcConfiguration, publishEvent: (string: any, any: any) => void, initAsync: InitAsyncFunction, oidcLocation: ILOidcLocation, getFetch?: () => Fetch) => (callbackPath?: string, extras?: StringMap, isSilentSignin?: boolean, scope?: string) => Promise<unknown>;
6
- export declare const loginCallbackAsync: (oidc: Oidc) => (isSilentSignin?: boolean) => Promise<{
6
+ export declare const loginCallbackAsync: (oidc: Oidc) => (isSilentSignin?: boolean, resource?: string) => Promise<{
7
+ resource: string;
7
8
  tokens: any;
8
9
  state: string;
9
10
  callbackPath: any;
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAkB1B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,GAE1B,mBAAmB,MAAM,EACzB,eAAe,iBAAiB,EAChC,cAAc,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,EACnC,WAAW,iBAAiB,EAC5B,cAAc,cAAc,EAC5B,WAAU,MAAM,KAA0B,MAG1C,eAAc,MAAkB,EAChC,SAAQ,SAAgB,EACxB,wBAAsB,EACtB,QAAO,MAAkB,KACxB,OAAO,CAAC,OAAO,CAoGjB,CAAC;AAEJ,eAAO,MAAM,kBAAkB,GAC5B,MAAM,IAAI,MACJ,wBAAsB;;;;;;EAgR5B,CAAC"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAwB1B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,GAE1B,mBAAmB,MAAM,EACzB,eAAe,iBAAiB,EAChC,cAAc,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,EACnC,WAAW,iBAAiB,EAC5B,cAAc,cAAc,EAC5B,WAAU,MAAM,KAA0B,MAG1C,eAAc,MAAkB,EAChC,SAAQ,SAAgB,EACxB,wBAAsB,EACtB,QAAO,MAAkB,KACxB,OAAO,CAAC,OAAO,CAsHjB,CAAC;AAEJ,eAAO,MAAM,kBAAkB,GAC5B,MAAM,IAAI,MACJ,wBAAsB,EAAE,WAAW,MAAM;;;;;;;EAsT/C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../src/logout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAW5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AA6BF,eAAO,MAAM,YAAY,GAAG,SAAI,MAAU,WAAM,kBAmB/C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAI,EAAE,iBAAY,wBAWnD,CAAC;AA4BF,eAAO,MAAM,WAAW,GACrB,SAAI,EAAE,iBAAY,EAAE,UAAK,EAAE,YAAO,EAAE,aAAa,cAAc,MACzD,oBAAmB,MAAM,GAAG,IAAI,GAAG,SAAqB,EAAE,SAAQ,SAAgB,kBA4JxF,CAAC"}
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../src/logout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAW5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AA6BF,eAAO,MAAM,YAAY,GAAG,SAAI,MAAU,WAAM,kBAoB/C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAI,EAAE,iBAAY,wBAWnD,CAAC;AA4BF,eAAO,MAAM,WAAW,GACrB,SAAI,EAAE,iBAAY,EAAE,UAAK,EAAE,YAAO,EAAE,aAAa,cAAc,MACzD,oBAAmB,MAAM,GAAG,IAAI,GAAG,SAAqB,EAAE,SAAQ,SAAgB,kBA+LxF,CAAC"}