@axa-fr/oidc-client 7.22.7 → 7.22.8-alpha.1449

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -158,10 +158,10 @@ const X = (e, n = null, t) => {
158
158
  issuedAt: e.issued_at
159
159
  };
160
160
  return "refresh_token" in e && (s.refreshToken = e.refresh_token), e.accessTokenPayload !== void 0 && (s.accessTokenPayload = e.accessTokenPayload), e.idTokenPayload !== void 0 && (s.idTokenPayload = e.idTokenPayload), X(s, n, t);
161
- }, U = (e, n) => {
161
+ }, K = (e, n) => {
162
162
  const t = (/* @__PURE__ */ new Date()).getTime() / 1e3, s = n - t;
163
163
  return Math.round(s - e);
164
- }, ce = (e) => e ? U(0, e.expiresAt) > 0 : !1, ge = async (e, n = 200, t = 50) => {
164
+ }, ce = (e) => e ? K(0, e.expiresAt) > 0 : !1, ge = async (e, n = 200, t = 50) => {
165
165
  let s = t;
166
166
  if (!e.tokens)
167
167
  return null;
@@ -227,14 +227,13 @@ const X = (e, n = null, t) => {
227
227
  y(d, w);
228
228
  };
229
229
  };
230
- }).toString();
230
+ }).toString(), l = typeof process > "u";
231
231
  try {
232
232
  const _ = new Blob(["(", u, ")()"], { type: "application/javascript" });
233
233
  f = URL.createObjectURL(_);
234
234
  } catch {
235
- return null;
235
+ return l && console.warn("BlobUrl not available"), null;
236
236
  }
237
- const l = typeof process > "u";
238
237
  try {
239
238
  if (SharedWorker)
240
239
  return c = new SharedWorker(f), c.port;
@@ -251,7 +250,7 @@ const X = (e, n = null, t) => {
251
250
  }();
252
251
  if (!e) {
253
252
  const c = typeof window > "u" ? global : window;
254
- return {
253
+ return console.log("Worker not available, using setTimeout" + (c === global ? " in NodeJS" : "") + "."), {
255
254
  setTimeout: setTimeout.bind(c),
256
255
  clearTimeout: clearTimeout.bind(c),
257
256
  setInterval: setInterval.bind(c),
@@ -293,7 +292,7 @@ const X = (e, n = null, t) => {
293
292
  setInterval: i,
294
293
  clearInterval: a
295
294
  };
296
- }(), le = "7.22.7";
295
+ }(), le = "7.22.8-alpha.1449";
297
296
  let ue = null, j;
298
297
  const z = ({ milliseconds: e }) => new Promise((n) => J.setTimeout(n, e)), me = (e = "/") => {
299
298
  try {
@@ -422,7 +421,7 @@ const re = (e) => {
422
421
  function _e(e) {
423
422
  return we($e(e));
424
423
  }
425
- const Ke = {
424
+ const Ue = {
426
425
  importKeyAlgorithm: {
427
426
  name: "ECDSA",
428
427
  namedCurve: "P-256",
@@ -435,7 +434,7 @@ const Ke = {
435
434
  },
436
435
  digestAlgorithm: { name: "SHA-256" },
437
436
  jwtHeaderAlgorithm: "ES256"
438
- }, Ue = (e) => async (n, t, s, o, r = "dpop+jwt") => {
437
+ }, Ke = (e) => async (n, t, s, o, r = "dpop+jwt") => {
439
438
  switch (n = Object.assign({}, n), t.typ = r, t.alg = o.jwtHeaderAlgorithm, t.alg) {
440
439
  case "ES256":
441
440
  t.jwk = { kty: n.kty, crv: n.crv, x: n.x, y: n.y };
@@ -456,7 +455,7 @@ const Ke = {
456
455
  }, a = o.importKeyAlgorithm, c = !0, f = ["sign"], u = await e.crypto.subtle.importKey("jwk", n, a, c, f), l = pe(`${i.protected}.${i.payload}`), _ = o.signAlgorithm, h = await e.crypto.subtle.sign(_, u, l);
457
456
  return i.signature = re(new Uint8Array(h)), `${i.protected}.${i.payload}.${i.signature}`;
458
457
  };
459
- var Fe = { sign: Ue };
458
+ var Fe = { sign: Ke };
460
459
  const Ve = (e) => async (n) => {
461
460
  const t = n, s = !0, o = ["sign", "verify"], r = await e.crypto.subtle.generateKey(t, s, o);
462
461
  return await e.crypto.subtle.exportKey("jwk", r.privateKey);
@@ -675,9 +674,9 @@ async function Te(e, n = !1, t = null) {
675
674
  }
676
675
  const M = (e, n, t = null) => {
677
676
  const s = e.configuration.refresh_time_before_tokens_expiration_in_second;
678
- return J.setTimeout(async () => {
679
- const r = { timeLeft: U(s, n) };
680
- e.publishEvent(C.eventNames.token_timer, r), await Te(e, !1, t);
677
+ return console.log("autoRenewTokens", s, n), J.setTimeout(async () => {
678
+ const r = { timeLeft: K(s, n) };
679
+ console.log("autoRenewTokens", r), e.publishEvent(C.eventNames.token_timer, r), await Te(e, !1, t);
681
680
  }, 1e3);
682
681
  }, N = {
683
682
  FORCE_REFRESH: "FORCE_REFRESH",
@@ -702,7 +701,7 @@ const M = (e, n, t = null) => {
702
701
  if (!l || !_)
703
702
  return { tokens: null, status: "REQUIRE_SYNC_TOKENS", nonce: r };
704
703
  if (_.issuedAt !== s.issuedAt) {
705
- const y = U(n.refresh_time_before_tokens_expiration_in_second, _.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", m = await c.getNonceAsync();
704
+ const y = K(n.refresh_time_before_tokens_expiration_in_second, _.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", m = await c.getNonceAsync();
706
705
  return { tokens: _, status: y, nonce: m };
707
706
  }
708
707
  i = await c.getNonceAsync();
@@ -713,14 +712,14 @@ const M = (e, n, t = null) => {
713
712
  if (h === "SESSIONS_LOST")
714
713
  return { tokens: null, status: "SESSIONS_LOST", nonce: r };
715
714
  if (_.issuedAt !== s.issuedAt) {
716
- const m = U(n.refresh_time_before_tokens_expiration_in_second, _.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", d = await l.getNonceAsync();
715
+ const m = K(n.refresh_time_before_tokens_expiration_in_second, _.expiresAt) > 0 ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID", d = await l.getNonceAsync();
717
716
  return { tokens: _, status: m, nonce: d };
718
717
  }
719
718
  } else
720
719
  return { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB", nonce: r };
721
720
  i = await l.getNonceAsync();
722
721
  }
723
- const u = U(n.refresh_time_before_tokens_expiration_in_second, s.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
722
+ const u = K(n.refresh_time_before_tokens_expiration_in_second, s.expiresAt) > 0 ? "TOKENS_VALID" : "TOKENS_INVALID";
724
723
  return o ? { tokens: s, status: "FORCE_REFRESH", nonce: i } : { tokens: s, status: u, nonce: i };
725
724
  }, H = (e) => async (n = 0, t = !1, s = null, o) => {
726
725
  if (!navigator.onLine && document.hidden)
@@ -999,11 +998,11 @@ const M = (e, n, t = null) => {
999
998
  redirect_uri: o
1000
999
  }, v = {};
1001
1000
  if (t.token_request_extras)
1002
- for (const [E, K] of Object.entries(t.token_request_extras))
1003
- v[E] = K;
1001
+ for (const [E, U] of Object.entries(t.token_request_extras))
1002
+ v[E] = U;
1004
1003
  if (y && y.extras)
1005
- for (const [E, K] of Object.entries(y.extras))
1006
- E.endsWith(":token_request") && (v[E.replace(":token_request", "")] = K);
1004
+ for (const [E, U] of Object.entries(y.extras))
1005
+ E.endsWith(":token_request") && (v[E.replace(":token_request", "")] = U);
1007
1006
  const A = a.tokenEndpoint, b = {};
1008
1007
  if (t.demonstrating_proof_of_possession)
1009
1008
  if (l)
@@ -1327,7 +1326,7 @@ const x = {}, wn = (e, n = new Y()) => (t, s = "default") => (x[s] || (x[s] = ne
1327
1326
  logout_tokens_to_invalidate: n.logout_tokens_to_invalidate ?? ["access_token", "refresh_token"],
1328
1327
  service_worker_update_require_callback: a,
1329
1328
  service_worker_activate: n.service_worker_activate ?? kn,
1330
- demonstrating_proof_of_possession_configuration: n.demonstrating_proof_of_possession_configuration ?? Ke,
1329
+ demonstrating_proof_of_possession_configuration: n.demonstrating_proof_of_possession_configuration ?? Ue,
1331
1330
  preload_user_info: n.preload_user_info ?? !1
1332
1331
  }, this.getFetch = s ?? pn, this.configurationName = t, this.tokens = null, this.userInfo = null, this.events = [], this.timeoutId = null, this.loginCallbackWithAutoTokensRenewAsync.bind(this), this.initAsync.bind(this), this.loginCallbackAsync.bind(this), this.subscribeEvents.bind(this), this.removeEventSubscription.bind(this), this.publishEvent.bind(this), this.destroyAsync.bind(this), this.logoutAsync.bind(this), this.renewTokensAsync.bind(this), this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
1333
1332
  }
@@ -1,2 +1,2 @@
1
- (function(C,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(C=typeof globalThis<"u"?globalThis:C||self,G(C["oidc-client"]={}))})(this,function(C){"use strict";const D=console;class Ce{constructor(n,t,s,o=2e3,r=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||2e3,this._stopOnError=r;const i=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substr(0,i),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=s}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(D.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(D.debug(n),D.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):D.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){D.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(D.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},P=(e,n=sessionStorage)=>{const t=k=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:k}),Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const k=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:k.tokens,status:k.status})},o=k=>{n[`oidc.${e}`]=JSON.stringify({tokens:k})},r=async k=>{n[`oidc.session_state.${e}`]=k},i=async()=>n[`oidc.session_state.${e}`],a=k=>{n[`oidc.nonce.${e}`]=k.nonce},c=k=>{n[`oidc.jwk.${e}`]=JSON.stringify(k)},_=()=>JSON.parse(n[`oidc.jwk.${e}`]),u=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async k=>{n[`oidc.dpop_nonce.${e}`]=k},f=()=>n[`oidc.dpop_nonce.${e}`],h=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let y={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:h,setSessionStateAsync:r,getSessionStateAsync:i,setNonceAsync:a,getNonceAsync:u,setLoginParams:k=>{y[e]=k,n[`oidc.login.${e}`]=JSON.stringify(k)},getLoginParams:()=>{const k=n[`oidc.login.${e}`];return k?(y[e]||(y[e]=JSON.parse(k)),y[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async k=>{n[`oidc.state.${e}`]=k},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async k=>{n[`oidc.code_verifier.${e}`]=k},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:f,setDemonstratingProofOfPossessionJwkAsync:c,getDemonstratingProofOfPossessionJwkAsync:_}};var R=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(R||{});const Ne=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),xe=e=>JSON.parse(Ne(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),ue=e=>{try{return e&&We(e,".")===2?xe(e.split(".")[1]):null}catch(n){console.warn(n)}return null},We=(e,n)=>e.split(n).length-1,Y={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const X=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=ue(e.accessToken);let r;n!=null&&"idToken"in n&&!("idToken"in e)?r=n.idToken:r=e.idToken;const i=e.idTokenPayload?e.idTokenPayload:ue(r),a=i&&i.exp?i.exp:Number.MAX_VALUE,c=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Le(e,s,i);let _;e.expiresAt?_=e.expiresAt:t===Y.access_token_invalid?_=c:t===Y.id_token_invalid?_=a:_=a<c?a:c;const u={...e,idTokenPayload:i,accessTokenPayload:s,expiresAt:_,idToken:r};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...u,refreshToken:l}}return u},ne=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),X(s,n,t)},F=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},fe=e=>e?F(0,e.expiresAt)>0:!1,_e=async(e,n=200,t=50)=>{let s=t;if(!e.tokens)return null;for(;!fe(e.tokens)&&s>0;){if(e.configuration.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await Q({milliseconds:n});s=s-1}return{isTokensValid:fe(e.tokens),tokens:e.tokens,numberWaited:s-t}},de=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const r=60*60*24*7;if(s.iat&&s.iat+r<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+r} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},V=function(){const e=function(){let c,_;const u=(function(){const f={},h={setTimeout:function(m,d,w){f[d]=setTimeout(function(){m.postMessage(d),f[d]=null},w)},setInterval:function(m,d,w){f[d]=setInterval(function(){m.postMessage(d)},w)},clearTimeout:function(m,d){clearTimeout(f[d]),f[d]=null},clearInterval:function(m,d){clearInterval(f[d]),f[d]=null}};function y(m,d){const w=d.data[0],v=d.data[1],A=d.data[2];h[w]&&h[w](m,v,A)}this.onmessage=function(m){y(self,m)},this.onconnect=function(m){const d=m.ports[0];d.onmessage=function(w){y(d,w)}}}).toString();try{const f=new Blob(["(",u,")()"],{type:"application/javascript"});_=URL.createObjectURL(f)}catch{return null}const l=typeof process>"u";try{if(SharedWorker)return c=new SharedWorker(_),c.port}catch{l&&console.warn("SharedWorker not available")}try{if(Worker)return c=new Worker(_),c}catch{l&&console.warn("Worker not available")}return null}();if(!e){const c=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(c),clearTimeout:clearTimeout.bind(c),setInterval:setInterval.bind(c),clearInterval:clearInterval.bind(c)}}const n=function(){let c=0;return function(){return c++,c}}(),t={},s={};e.onmessage=function(c){const _=c.data,u=t[_];if(u){u(),t[_]=null;return}const l=s[_];l&&l()};function o(c,_){const u=n();return e.postMessage(["setTimeout",u,_]),t[u]=c,u}function r(c){e.postMessage(["clearTimeout",c]),t[c]=null}function i(c,_){const u=n();return e.postMessage(["setInterval",u,_]),s[u]=c,u}function a(c){e.postMessage(["clearInterval",c]),s[c]=null}return{setTimeout:o,clearTimeout:r,setInterval:i,clearInterval:a}}(),he="7.22.7";let ye=null,z;const Q=({milliseconds:e})=>new Promise(n=>V.setTimeout(n,e)),ge=(e="/")=>{try{z=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:z.signal}).catch(s=>{console.log(s)}),Q({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},De=()=>{z&&z.abort()},Re=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),$e=e=>async(n,t)=>{t(),await n.update();const s=await n.unregister();console.log(`Service worker unregistering ${s}`),await Q({milliseconds:2e3}),e.reload()},O=e=>n=>new Promise(function(t,s){const o=new MessageChannel;o.port1.onmessage=function(r){r.data&&r.data.error?s(r.data.error):t(r.data)},e.active.postMessage(n,[o.port2])}),I=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;let s=null;e.register?s=await e.service_worker_register(t):s=await navigator.serviceWorker.register(t);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await O(s)({type:"claim"})}catch{return null}const o=async g=>O(s)({type:"clear",data:{status:g},configurationName:n}),r=async(g,S,T)=>{const L=await O(s)({type:"init",data:{oidcServerConfiguration:g,where:S,oidcConfiguration:{token_renew_mode:T.token_renew_mode,service_worker_convert_all_requests_to_cors:T.service_worker_convert_all_requests_to_cors}},configurationName:n}),U=L.version;return U!==he&&(console.warn(`Service worker ${U} version mismatch with js client version ${he}, unregistering and reloading`),await T.service_worker_update_require_callback(s,De)),{tokens:ne(L.tokens,null,T.token_renew_mode),status:L.status}},i=(g="/")=>{ye==null&&(ye="not_null",ge(g))},a=g=>O(s)({type:"setSessionState",data:{sessionState:g},configurationName:n}),c=async()=>(await O(s)({type:"getSessionState",data:null,configurationName:n})).sessionState,_=g=>(sessionStorage[`oidc.nonce.${n}`]=g.nonce,O(s)({type:"setNonce",data:{nonce:g},configurationName:n})),u=async()=>{let S=(await O(s)({type:"getNonce",data:null,configurationName:n})).nonce;return S||(S=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:S}};let l={};return{clearAsync:o,initAsync:r,startKeepAliveServiceWorker:()=>i(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:a,getSessionStateAsync:c,setNonceAsync:_,getNonceAsync:u,setLoginParams:g=>{l[n]=g,localStorage[`oidc.login.${n}`]=JSON.stringify(g)},getLoginParams:()=>{const g=localStorage[`oidc.login.${n}`];return l[n]||(l[n]=JSON.parse(g)),l[n]},getStateAsync:async()=>{let S=(await O(s)({type:"getState",data:null,configurationName:n})).state;return S||(S=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),S},setStateAsync:async g=>(sessionStorage[`oidc.state.${n}`]=g,O(s)({type:"setState",data:{state:g},configurationName:n})),getCodeVerifierAsync:async()=>{let S=(await O(s)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return S||(S=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),S},setCodeVerifierAsync:async g=>(sessionStorage[`oidc.code_verifier.${n}`]=g,O(s)({type:"setCodeVerifier",data:{codeVerifier:g},configurationName:n})),setDemonstratingProofOfPossessionNonce:async g=>{await O(s)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:g},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await O(s)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async g=>{const S=JSON.stringify(g);await O(s)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:S},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const g=await O(s)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return g.demonstratingProofOfPossessionJwkJson?JSON.parse(g.demonstratingProofOfPossessionJwkJson):null}}},$={},Ke=(e,n=window.sessionStorage,t)=>{if(!$[e]&&n){const o=n.getItem(e);o&&($[e]=JSON.parse(o))}const s=1e3*t;return $[e]&&$[e].timestamp+s>Date.now()?$[e].result:null},Ue=(e,n,t=window.sessionStorage)=>{const s=Date.now();$[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function ke(e){return new TextEncoder().encode(e)}function me(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Fe(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const te=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),me(n)};function pe(e){return me(Fe(e))}const Ve={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var Me={sign:e=>async(n,t,s,o,r="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=r,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:pe(JSON.stringify(t)),payload:pe(JSON.stringify(s))},a=o.importKeyAlgorithm,c=!0,_=["sign"],u=await e.crypto.subtle.importKey("jwk",n,a,c,_),l=ke(`${i.protected}.${i.payload}`),f=o.signAlgorithm,h=await e.crypto.subtle.sign(f,u,l);return i.signature=te(new Uint8Array(h)),`${i.protected}.${i.payload}.${i.signature}`}};const Je={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],r=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",r.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var Be={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,ke(s));return te(new Uint8Array(o))}};const je=e=>async n=>await Je.generate(e)(n),we=e=>n=>async(t,s="POST",o,r={})=>{const i={jti:btoa(He()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...r},a=await Be.thumbprint(e)(t,n.digestAlgorithm);return await Me.sign(e)(t,{kid:a},i,n)},He=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},Ae=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%se.length;n.push(se[s])}return n.join("")},oe=e=>{const n=new Uint8Array(e),{hasCrypto:t}=Ae();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*se.length|0;return qe(n)};function Ge(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Se(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",Ge(e)).then(s=>n(te(new Uint8Array(s))),s=>t(s))})}const Ye=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Ae();return n?Se(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},Xe=60*60,ze=e=>async(n,t=Xe,s=window.sessionStorage,o=1e4)=>{const r=`${n}/.well-known/openid-configuration`,i=`oidc.server:${n}`,a=Ke(i,s,t);if(a)return new ce(a);const c=await M(e)(r,{},o);if(c.status!==200)return null;const _=await c.json();return Ue(i,_,s),new ce(_)},M=e=>async(n,t={},s=1e4,o=0)=>{let r;try{const i=new AbortController;setTimeout(()=>i.abort(),s),r=await e(n,{...t,signal:i.signal})}catch(i){if(i.name==="AbortError"||i.message==="Network request failed"){if(o<=1)return await M(e)(n,t,s,o+1);throw i}else throw console.error(i.message),i}return r},re={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,t,s=re.refresh_token,o,r={},i=1e4)=>{const a={token:t,token_type_hint:s,client_id:o};for(const[l,f]of Object.entries(r))a[l]===void 0&&(a[l]=f);const c=[];for(const l in a){const f=encodeURIComponent(l),h=encodeURIComponent(a[l]);c.push(`${f}=${h}`)}const _=c.join("&");return(await M(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:_},i)).status!==200?{success:!1}:{success:!0}},Qe=e=>async(n,t,s,o,r={},i,a=1e4)=>{for(const[h,y]of Object.entries(s))t[h]===void 0&&(t[h]=y);const c=[];for(const h in t){const y=encodeURIComponent(h),m=encodeURIComponent(t[h]);c.push(`${y}=${m}`)}const _=c.join("&"),u=await M(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...r},body:_},a);if(u.status!==200)return{success:!1,status:u.status,demonstratingProofOfPossessionNonce:null};const l=await u.json();let f=null;return u.headers.has(Z)&&(f=u.headers.get(Z)),{success:!0,status:u.status,data:ne(l,o,i),demonstratingProofOfPossessionNonce:f}},Ze=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=oe(128),r=await Ye(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=r,s.code_challenge_method="S256";let i="";if(s)for(const[a,c]of Object.entries(s))i===""?i+="?":i+="&",i+=`${a}=${encodeURIComponent(c)}`;n.open(`${t}${i}`)},Z="DPoP-Nonce",en=e=>async(n,t,s,o,r=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const i=[];for(const l in t){const f=encodeURIComponent(l),h=encodeURIComponent(t[l]);i.push(`${f}=${h}`)}const a=i.join("&"),c=await M(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:a},r);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),c.status!==200)return{success:!1,status:c.status};let _=null;c.headers.has(Z)&&(_=c.headers.get(Z));const u=await c.json();return{success:!0,data:{state:t.state,tokens:ne(u,null,o),demonstratingProofOfPossessionNonce:_}}};async function Te(e,n,t){const s=a=>{e.tokens=a},{tokens:o,status:r}=await ee(e)(0,n,t,s);return await I(e.configuration,e.configurationName)||await P(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(r),null)}const nn=async(e,n)=>{const t=await I(n,e.configurationName);if(t){const s=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await t.initAsync(s,"tryKeepExistingSessionAsync",n);return o}else{const s=P(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await s.initAsync();return o=X(o,e.tokens,n.token_renew_mode),o}};async function be(e,n=!1,t=null){const s=e.configuration,o=`${s.client_id}_${e.configurationName}_${s.authority}`;let r;const i=await I(e.configuration,e.configurationName);return(s==null?void 0:s.storage)===(window==null?void 0:window.sessionStorage)&&!i?r=await Te(e,n,t):r=await navigator.locks.request(o,{ifAvailable:!0},async a=>a?await Te(e,n,t):(e.publishEvent(N.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await nn(e,s))),r?(e.timeoutId&&(e.timeoutId=J(e,e.tokens.expiresAt,t)),e.tokens):null}const J=(e,n,t=null)=>{const s=e.configuration.refresh_time_before_tokens_expiration_in_second;return V.setTimeout(async()=>{const r={timeLeft:F(s,n)};e.publishEvent(N.eventNames.token_timer,r),await be(e,!1,t)},1e3)},x={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",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},tn=e=>async(n,t,s,o=!1)=>{const r={nonce:null};if(!s)return{tokens:null,status:"NOT_CONNECTED",nonce:r};let i=r;const a=await e.initAsync(n.authority,n.authority_configuration),c=await I(n,t);if(c){const{status:l,tokens:f}=await c.initAsync(a,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};if(l==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(!l||!f)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:r};if(f.issuedAt!==s.issuedAt){const y=F(n.refresh_time_before_tokens_expiration_in_second,f.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",m=await c.getNonceAsync();return{tokens:f,status:y,nonce:m}}i=await c.getNonceAsync()}else{const l=P(t,n.storage??sessionStorage);let{tokens:f,status:h}=await l.initAsync();if(f&&(f=X(f,e.tokens,n.token_renew_mode)),f){if(h==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(f.issuedAt!==s.issuedAt){const m=F(n.refresh_time_before_tokens_expiration_in_second,f.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",d=await l.getNonceAsync();return{tokens:f,status:m,nonce:d}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};i=await l.getNonceAsync()}const u=F(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:i}:{tokens:s,status:u,nonce:i}},ee=e=>async(n=0,t=!1,s=null,o)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let r=6;for(;!navigator.onLine&&r>0;)await Q({milliseconds:1e3}),r--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const i=n+1;s||(s={});const a=e.configuration,c=(u,l=null,f=null)=>ie(e.configurationName,e.configuration,e.publishEvent.bind(e))(u,l,f),_=async()=>{try{let u;const l=await I(a,e.configurationName);l?u=l.getLoginParams():u=P(e.configurationName,a.storage).getLoginParams();const f=await c({...u.extras,...s,prompt:"none"});return f?f.error?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(o(f.tokens),e.publishEvent(N.eventNames.token_renewed,{}),{tokens:f.tokens,status:"LOGGED"}):(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(u){return console.error(u),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:u.message}),await ee(e)(i,t,s,o)}};try{const{status:u,tokens:l,nonce:f}=await tn(e)(a,e.configurationName,e.tokens,t);switch(u){case x.SESSION_LOST:return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case x.NOT_CONNECTED:return o(null),{tokens:null,status:null};case x.TOKENS_VALID:return o(l),{tokens:l,status:"LOGGED_IN"};case x.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return o(l),e.publishEvent(N.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:l,status:"LOGGED_IN"};case x.LOGOUT_FROM_ANOTHER_TAB:return o(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case x.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted&&x.FORCE_REFRESH!==u?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:n}),await _());default:{if(a.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted&&x.FORCE_REFRESH!==u)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:l.refreshToken,status:u,tryNumber:n}),!l.refreshToken)return await _();const h=a.client_id,y=a.redirect_uri,m=a.authority,w={...a.token_request_extras?a.token_request_extras:{}};for(const[A,b]of Object.entries(s))A.endsWith(":token_request")&&(w[A.replace(":token_request","")]=b);return await(async()=>{const A={client_id:h,redirect_uri:y,grant_type:"refresh_token",refresh_token:l.refreshToken},b=await e.initAsync(m,a.authority_configuration),k=document.hidden?1e4:3e4*10,g=b.tokenEndpoint,S={};a.demonstrating_proof_of_possession&&(S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(l.accessToken,g,"POST"));const T=await Qe(e.getFetch())(g,A,w,l,S,a.token_renew_mode,k);if(T.success){const{isValid:L,reason:U}=de(T.data,f.nonce,b);if(!L)return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${U}`}),{tokens:null,status:"SESSION_LOST"};if(o(T.data),T.demonstratingProofOfPossessionNonce){const E=await I(a,e.configurationName);E?await E.setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce):await P(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:T.success}),e.publishEvent(N.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:T.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:T}),T.status>=400&&T.status<500?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${T.status}`}),{tokens:null,status:"SESSION_LOST"}):await ee(e)(i,t,s,o)})()}}}catch(u){return console.error(u),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:u.message}),ee(e)(i,t,s,o)}},ie=(e,n,t)=>(s=null,o=null,r=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let i="";if(o&&(s==null&&(s={}),s.state=o),r&&(s==null&&(s={}),s.scope=r),s!=null)for(const[l,f]of Object.entries(s))i===""?i=`?${encodeURIComponent(l)}=${encodeURIComponent(f)}`:i+=`&${encodeURIComponent(l)}=${encodeURIComponent(f)}`;const a=n.silent_login_uri+i,c=a.indexOf("/",a.indexOf("//")+2),_=a.substring(0,c),u=document.createElement("iframe");return u.width="0px",u.height="0px",u.id=`${e}_oidc_iframe`,u.setAttribute("src",a),document.body.appendChild(u),new Promise((l,f)=>{let h=!1;const y=()=>{window.removeEventListener("message",m),u.remove(),h=!0},m=d=>{if(d.origin===_&&d.source===u.contentWindow){const w=`${e}_oidc_tokens:`,v=`${e}_oidc_error:`,A=`${e}_oidc_exception:`,b=d.data;if(b&&typeof b=="string"&&!h){if(b.startsWith(w)){const k=JSON.parse(d.data.replace(w,""));t(p.silentLoginAsync_end,{}),l(k),y()}else if(b.startsWith(v)){const k=JSON.parse(d.data.replace(v,""));t(p.silentLoginAsync_error,k),l({error:"oidc_"+k.error,tokens:null,sessionState:null}),y()}else if(b.startsWith(A)){const k=JSON.parse(d.data.replace(A,""));t(p.silentLoginAsync_error,k),f(new Error(k.error)),y()}}}};try{window.addEventListener("message",m);const d=n.silent_login_timeout;setTimeout(()=>{h||(y(),t(p.silentLoginAsync_error,{reason:"timeout"}),f(new Error("timeout")))},d)}catch(d){y(),t(p.silentLoginAsync_error,d),f(d)}})}catch(i){throw t(p.silentLoginAsync_error,i),i}},sn=(e,n,t,s,o)=>(r=null,i=void 0)=>{r={...r};const a=(_,u,l)=>ie(n,t,s.bind(o))(_,u,l);return(async()=>{o.timeoutId&&V.clearTimeout(o.timeoutId);let _;r&&"state"in r&&(_=r.state,delete r.state);try{const u=t.extras?{...t.extras,...r}:r,l=await a({...u,prompt:"none"},_,i);if(l)return o.tokens=l.tokens,s(p.token_aquired,{}),o.timeoutId=J(o,o.tokens.expiresAt,r),{}}catch(u){return u}})()},on=(e,n,t)=>(s,o,r,i=!1)=>{const a=(c,_=void 0,u=void 0)=>ie(e.configurationName,t,e.publishEvent.bind(e))(c,_,u);return new Promise((c,_)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&r&&!i){const u=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const f=l.idToken,h=l.idTokenPayload;return a({prompt:"none",id_token_hint:f,scope:t.scope||"openid"}).then(y=>{if(y.error)throw new Error(y.error);const m=y.tokens.idTokenPayload;if(h.sub===m.sub){const d=y.sessionState;e.checkSessionIFrame.start(y.sessionState),h.sid===m.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",d):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",d)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",m.sub)}).catch(async y=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",y);for(const[m,d]of Object.entries(n))await d.logoutOtherTabAsync(t.client_id,h.sub)})};e.checkSessionIFrame=new Ce(u,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(r),c(e.checkSessionIFrame)}).catch(l=>{_(l)})}else c(null)})},Ee=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},rn=e=>{const n=Ee(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},B=e=>{const n=Ee(e),{search:t}=n;return an(t)},an=e=>{const n={};let t,s,o;const r=e.split("&");for(s=0,o=r.length;s<o;s++)t=r[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},cn=(e,n,t,s,o)=>(r=void 0,i=null,a=!1,c=void 0)=>{const _=i;return i={...i},(async()=>{const l=r||o.getPath();if("state"in i||(i.state=oe(16)),t(p.loginAsync_begin,{}),i)for(const f of Object.keys(i))f.endsWith(":token_request")&&delete i[f];try{const f=a?n.silent_redirect_uri:n.redirect_uri;c||(c=n.scope);const h=n.extras?{...n.extras,...i}:i;h.nonce||(h.nonce=oe(12));const y={nonce:h.nonce},m=await I(n,e),d=await s(n.authority,n.authority_configuration);let w;if(m)m.setLoginParams({callbackPath:l,extras:_}),await m.initAsync(d,"loginAsync",n),await m.setNonceAsync(y),m.startKeepAliveServiceWorker(),w=m;else{const A=P(e,n.storage??sessionStorage);A.setLoginParams({callbackPath:l,extras:_}),await A.setNonceAsync(y),w=A}const v={client_id:n.client_id,redirect_uri:f,scope:c,response_type:"code",...h};await Ze(w,o)(d.authorizationEndpoint,v)}catch(f){throw t(p.loginAsync_error,f),f}})()},ln=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,r=t.authority,i=t.token_request_timeout,a=await e.initAsync(r,t.authority_configuration),c=e.location.getCurrentHref(),u=B(c).session_state,l=await I(t,e.configurationName);let f,h,y,m;if(l)await l.initAsync(a,"loginCallbackAsync",t),await l.setSessionStateAsync(u),h=await l.getNonceAsync(),y=l.getLoginParams(),m=await l.getStateAsync(),l.startKeepAliveServiceWorker(),f=l;else{const E=P(e.configurationName,t.storage??sessionStorage);await E.setSessionStateAsync(u),h=await E.getNonceAsync(),y=E.getLoginParams(),m=await E.getStateAsync(),f=E}const d=B(c);if(d.error||d.error_description)throw new Error(`Error from OIDC server: ${d.error} - ${d.error_description}`);if(d.iss&&d.iss!==a.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${a.issuer}, received: ${d.iss})`);if(d.state&&d.state!==m)throw new Error(`State not valid (expected: ${m}, received: ${d.state})`);const w={code:d.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},v={};if(t.token_request_extras)for(const[E,q]of Object.entries(t.token_request_extras))v[E]=q;if(y&&y.extras)for(const[E,q]of Object.entries(y.extras))E.endsWith(":token_request")&&(v[E.replace(":token_request","")]=q);const A=a.tokenEndpoint,b={};if(t.demonstrating_proof_of_possession)if(l)b.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const E=await je(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await P(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(E),b.DPoP=await we(window)(t.demonstrating_proof_of_possession_configuration)(E,"POST",A)}const k=await en(f)(A,{...w,...v},b,e.configuration.token_renew_mode,i);if(!k.success)throw new Error("Token request failed");let g;const S=k.data.tokens,T=k.data.demonstratingProofOfPossessionNonce;if(k.data.state!==v.state)throw new Error("state is not valid");const{isValid:L,reason:U}=de(S,h.nonce,a);if(!L)throw new Error(`Tokens are not OpenID valid, reason: ${U}`);if(l){if(S.refreshToken&&!S.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(T&&S.accessToken&&S.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(l)await l.initAsync(a,"syncTokensAsync",t),g=l.getLoginParams(),T&&await l.setDemonstratingProofOfPossessionNonce(T);else{const E=P(e.configurationName,t.storage);g=E.getLoginParams(),T&&await E.setDemonstratingProofOfPossessionNonce(T)}return await e.startCheckSessionAsync(a.checkSessionIframe,s,u,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:S,state:"request.state",callbackPath:g.callbackPath}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Oe={access_token:"access_token",refresh_token:"refresh_token"},ae=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const r=s.replace(n,"");t[r]=o}return t}return t},un=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},fn=e=>async n=>{V.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await I(e.configuration,e.configurationName);t?await t.clearAsync(n):await P(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},_n=(e,n,t,s,o)=>async(r=void 0,i=null)=>{const a=e.configuration,c=await e.initAsync(a.authority,a.authority_configuration);r&&typeof r!="string"&&(r=void 0,s.warn("callbackPathOrUrl path is not a string"));const _=r??o.getPath();let u=!1;r&&(u=r.includes("https://")||r.includes("http://"));const l=u?r:o.getOrigin()+_,f=e.tokens?e.tokens.idToken:"";try{const w=c.revocationEndpoint;if(w){const v=[],A=e.tokens?e.tokens.accessToken:null;if(A&&a.logout_tokens_to_invalidate.includes(Oe.access_token)){const k=ae(i,":revoke_access_token"),g=ve(t)(w,A,re.access_token,a.client_id,k);v.push(g)}const b=e.tokens?e.tokens.refreshToken:null;if(b&&a.logout_tokens_to_invalidate.includes(Oe.refresh_token)){const k=ae(i,":revoke_refresh_token"),g=ve(t)(w,b,re.refresh_token,a.client_id,k);v.push(g)}v.length>0&&await Promise.all(v)}}catch(w){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(w)}const h=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;await e.destroyAsync("LOGGED_OUT");for(const[w,v]of Object.entries(n))v!==e?await e.logoutSameTabAsync(e.configuration.client_id,h):e.publishEvent(p.logout_from_same_tab,{});const y=ae(i,":oidc");if(y&&y.no_reload==="true")return;const d=un(i);if(c.endSessionEndpoint){"id_token_hint"in d||(d.id_token_hint=f),!("post_logout_redirect_uri"in d)&&r!==null&&(d.post_logout_redirect_uri=l);let w="";for(const[v,A]of Object.entries(d))A!=null&&(w===""?w+="?":w+="&",w+=`${v}=${encodeURIComponent(A)}`);o.open(`${c.endSessionEndpoint}${w}`)}else o.reload()},Pe=(e,n,t=!1)=>async(...s)=>{var h;const[o,r,...i]=s,a=r?{...r}:{method:"GET"};let c=new Headers;a.headers&&(c=a.headers instanceof Headers?a.headers:new Headers(a.headers));const _=n,u=await _e(_),l=(h=u==null?void 0:u.tokens)==null?void 0:h.accessToken;if(c.has("Accept")||c.set("Accept","application/json"),l){if(_.configuration.demonstrating_proof_of_possession&&t){const y=await _.generateDemonstrationOfProofOfPossessionAsync(l,o.toString(),a.method);c.set("Authorization",`PoP ${l}`),c.set("DPoP",y)}else c.set("Authorization",`Bearer ${l}`);a.credentials||(a.credentials="same-origin")}const f={...a,headers:c};return await e(o,f,...i)},dn=e=>async(n=!1,t=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const s=e.configuration,r=(await e.initAsync(s.authority,s.authority_configuration)).userInfoEndpoint,a=await(async()=>{const _=await Pe(fetch,e,t)(r);return _.status!==200?null:_.json()})();return e.userInfo=a,a};class j{open(n){window.location.href=n}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const hn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),yn=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;const r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const a in r){const c=r[a];if(c.r.test(t)){o=c.s;break}}let i=s;switch(/Windows/.test(o)&&(i=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":i=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t)[1];break;case"iOS":{const a=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);a!=null&&a.length>2&&(i=a[1]+"."+a[2]+"."+(parseInt(a[3])|0));break}}return{os:o,osVersion:i}};function gn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const kn=()=>{const{name:e,version:n}=gn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=yn(navigator);return!hn(t)},mn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await I(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const r=n.getLoginParams(e.configurationName);e.timeoutId=J(e,e.tokens.expiresAt,r.extras);const i=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,i),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=P(e.configurationName,t.storage??sessionStorage),{tokens:r}=await o.initAsync();if(r){e.tokens=X(r,null,t.token_renew_mode);const i=o.getLoginParams();e.timeoutId=J(e,e.tokens.expiresAt,i.extras);const a=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,a),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=()=>fetch;class ce{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const W={},pn=(e,n=new j)=>(t,s="default")=>(W[s]||(W[s]=new N(t,s,e,n)),W[s]),wn=async e=>{const{parsedTokens:n,callbackPath:t}=await e.loginCallbackAsync();return e.timeoutId=J(e,n.expiresAt),{callbackPath:t}},An=e=>Math.floor(Math.random()*e),H=class H{constructor(n,t="default",s,o=new j){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let r=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(r=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let i=n.refresh_time_before_tokens_expiration_in_second??120;i>60&&(i=i-Math.floor(Math.random()*40)),this.location=o??new j;const a=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:r,token_automatic_renew_mode:n.token_automatic_renew_mode??R.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:i,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??Y.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:a,service_worker_activate:n.service_worker_activate??kn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ve,preload_user_info:n.preload_user_info??!1},this.getFetch=s??Ie,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const t=An(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(W,n)&&t)throw Error(`OIDC library does seem initialized.
2
- Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return W[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,t=B(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const t=this.location,s=B(t.getCurrentHref());s.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,t.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,t){if(this.initPromise!==null)return this.initPromise;const s=async()=>{if(t!=null)return new ce({authorization_endpoint:t.authorization_endpoint,end_session_endpoint:t.end_session_endpoint,revocation_endpoint:t.revocation_endpoint,token_endpoint:t.token_endpoint,userinfo_endpoint:t.userinfo_endpoint,check_session_iframe:t.check_session_iframe,issuer:t.issuer});const r=await I(this.configuration,this.configurationName)?window.localStorage:null;return await ze(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??60*60,r,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=s(),this.initPromise.then(o=>(this.initPromise=null,o))}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=mn(this),this.tryKeepExistingSessionPromise.then(n=>(this.tryKeepExistingSessionPromise=null,n)))}async startCheckSessionAsync(n,t,s,o=!1){await on(this,W,this.configuration)(n,t,s,o)}async loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this.loginPromise!==null?this.loginPromise:r?sn(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,o):(this.loginPromise=cn(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,t,s,o),this.loginPromise.then(i=>(this.loginPromise=null,i)))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const t=async()=>{const s=await ln(this)(n),o=s.tokens;return this.tokens=o,await I(this.configuration,this.configurationName)||P(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(H.eventNames.token_aquired,o),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:o,state:s.state,callbackPath:s.callbackPath}};return this.loginCallbackPromise=t(),this.loginCallbackPromise.then(s=>(this.loginCallbackPromise=null,s))}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){const r=this.configuration,i={ath:await Se(n),...o},a=await I(r,this.configurationName);let c;if(a)return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}`;const _=P(this.configurationName,r.storage);let u=await _.getDemonstratingProofOfPossessionJwkAsync();return c=await _.getDemonstratingProofOfPossessionNonce(),c&&(i.nonce=c),await we(window)(r.demonstrating_proof_of_possession_configuration)(u,s,t,i)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=wn(this),this.loginCallbackWithAutoTokensRenewPromise.then(n=>(this.loginCallbackWithAutoTokensRenewPromise=null,n)))}userInfoAsync(n=!1,t=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=dn(this)(n,t),this.userInfoPromise.then(s=>(this.userInfoPromise=null,s)))}async renewTokensAsync(n=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return V.clearTimeout(this.timeoutId),this.renewTokensPromise=be(this,!0,n),this.renewTokensPromise.then(t=>(this.renewTokensPromise=null,t))}async destroyAsync(n){return await fn(this)(n)}async logoutSameTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_same_tab,{mmessage:"SessionMonitor",sub:t}))}async logoutOtherTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_another_tab,{message:"SessionMonitor",sub:t}))}async logoutAsync(n=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=_n(this,W,this.getFetch(),console,this.location)(n,t),this.logoutPromise.then(s=>(this.logoutPromise=null,s)))}};H.getOrCreate=(n,t)=>(s,o="default")=>pn(n,t)(s,o),H.eventNames=p;let N=H;const K=class K{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,t){this._oidc.publishEvent(n,t)}static get(n="default"){return new K(N.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this._oidc.loginAsync(n,t,s,o,r)}logoutAsync(n=void 0,t=null){return this._oidc.logoutAsync(n,t)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null){return this._oidc.renewTokensAsync(n)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,t,s,o)}async getValidTokenAsync(n=200,t=50){return _e(this._oidc,n,t)}fetchWithTokens(n,t){return Pe(n,this,t)}async userInfoAsync(n=!1,t=!1){return this._oidc.userInfoAsync(n,t)}userInfo(){return this._oidc.userInfo}};K.getOrCreate=(n,t=new j)=>(s,o="default")=>new K(N.getOrCreate(n,t)(s,o)),K.eventNames=N.eventNames;let le=K;C.OidcClient=le,C.OidcLocation=j,C.TokenAutomaticRenewMode=R,C.TokenRenewMode=Y,C.getFetchDefault=Ie,C.getParseQueryStringFromLocation=B,C.getPath=rn,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
1
+ (function(C,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(C=typeof globalThis<"u"?globalThis:C||self,G(C["oidc-client"]={}))})(this,function(C){"use strict";const D=console;class Ce{constructor(n,t,s,o=2e3,r=!0){this._callback=n,this._client_id=t,this._url=s,this._interval=o||2e3,this._stopOnError=r;const i=s.indexOf("/",s.indexOf("//")+2);this._frame_origin=s.substr(0,i),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=s}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(D.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(D.debug(n),D.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):D.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){D.debug("CheckSessionIFrame.start :"+n),this.stop();const t=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};t(),this._timer=window.setInterval(t,this._interval)}stop(){this._timer&&(D.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const p={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_aquired:"token_aquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},P=(e,n=sessionStorage)=>{const t=k=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:k}),Promise.resolve()),s=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const k=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:k.tokens,status:k.status})},o=k=>{n[`oidc.${e}`]=JSON.stringify({tokens:k})},r=async k=>{n[`oidc.session_state.${e}`]=k},i=async()=>n[`oidc.session_state.${e}`],a=k=>{n[`oidc.nonce.${e}`]=k.nonce},c=k=>{n[`oidc.jwk.${e}`]=JSON.stringify(k)},_=()=>JSON.parse(n[`oidc.jwk.${e}`]),u=async()=>({nonce:n[`oidc.nonce.${e}`]}),l=async k=>{n[`oidc.dpop_nonce.${e}`]=k},f=()=>n[`oidc.dpop_nonce.${e}`],h=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null;let y={};return{clearAsync:t,initAsync:s,setTokens:o,getTokens:h,setSessionStateAsync:r,getSessionStateAsync:i,setNonceAsync:a,getNonceAsync:u,setLoginParams:k=>{y[e]=k,n[`oidc.login.${e}`]=JSON.stringify(k)},getLoginParams:()=>{const k=n[`oidc.login.${e}`];return k?(y[e]||(y[e]=JSON.parse(k)),y[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async k=>{n[`oidc.state.${e}`]=k},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async k=>{n[`oidc.code_verifier.${e}`]=k},setDemonstratingProofOfPossessionNonce:l,getDemonstratingProofOfPossessionNonce:f,setDemonstratingProofOfPossessionJwkAsync:c,getDemonstratingProofOfPossessionJwkAsync:_}};var R=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(R||{});const Ne=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),xe=e=>JSON.parse(Ne(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),ue=e=>{try{return e&&We(e,".")===2?xe(e.split(".")[1]):null}catch(n){console.warn(n)}return null},We=(e,n)=>e.split(n).length-1,Y={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function Le(e,n,t){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:t&&t.iat?t.iat:new Date().getTime()/1e3;return e.issuedAt}const X=(e,n=null,t)=>{if(!e)return null;let s;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?s=e.accessTokenPayload:s=ue(e.accessToken);let r;n!=null&&"idToken"in n&&!("idToken"in e)?r=n.idToken:r=e.idToken;const i=e.idTokenPayload?e.idTokenPayload:ue(r),a=i&&i.exp?i.exp:Number.MAX_VALUE,c=s&&s.exp?s.exp:e.issuedAt+o;e.issuedAt=Le(e,s,i);let _;e.expiresAt?_=e.expiresAt:t===Y.access_token_invalid?_=c:t===Y.id_token_invalid?_=a:_=a<c?a:c;const u={...e,idTokenPayload:i,accessTokenPayload:s,expiresAt:_,idToken:r};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const l=n.refreshToken;return{...u,refreshToken:l}}return u},ne=(e,n,t)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const s={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(s.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(s.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(s.idTokenPayload=e.idTokenPayload),X(s,n,t)},F=(e,n)=>{const t=new Date().getTime()/1e3,s=n-t;return Math.round(s-e)},fe=e=>e?F(0,e.expiresAt)>0:!1,_e=async(e,n=200,t=50)=>{let s=t;if(!e.tokens)return null;for(;!fe(e.tokens)&&s>0;){if(e.configuration.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await Q({milliseconds:n});s=s-1}return{isTokensValid:fe(e.tokens),tokens:e.tokens,numberWaited:s-t}},de=(e,n,t)=>{if(e.idTokenPayload){const s=e.idTokenPayload;if(t.issuer!==s.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${t.issuer} !== (idTokenPayload issuer) ${s.iss}`};const o=new Date().getTime()/1e3;if(s.exp&&s.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${s.exp} < (currentTimeUnixSecond) ${o}`};const r=60*60*24*7;if(s.iat&&s.iat+r<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${s.iat+r} < (currentTimeUnixSecond) ${o}`};if(s.nonce&&s.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${s.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},V=function(){const e=function(){let c,_;const u=(function(){const f={},h={setTimeout:function(m,d,w){f[d]=setTimeout(function(){m.postMessage(d),f[d]=null},w)},setInterval:function(m,d,w){f[d]=setInterval(function(){m.postMessage(d)},w)},clearTimeout:function(m,d){clearTimeout(f[d]),f[d]=null},clearInterval:function(m,d){clearInterval(f[d]),f[d]=null}};function y(m,d){const w=d.data[0],v=d.data[1],A=d.data[2];h[w]&&h[w](m,v,A)}this.onmessage=function(m){y(self,m)},this.onconnect=function(m){const d=m.ports[0];d.onmessage=function(w){y(d,w)}}}).toString(),l=typeof process>"u";try{const f=new Blob(["(",u,")()"],{type:"application/javascript"});_=URL.createObjectURL(f)}catch{return l&&console.warn("BlobUrl not available"),null}try{if(SharedWorker)return c=new SharedWorker(_),c.port}catch{l&&console.warn("SharedWorker not available")}try{if(Worker)return c=new Worker(_),c}catch{l&&console.warn("Worker not available")}return null}();if(!e){const c=typeof window>"u"?global:window;return console.log("Worker not available, using setTimeout"+(c===global?" in NodeJS":"")+"."),{setTimeout:setTimeout.bind(c),clearTimeout:clearTimeout.bind(c),setInterval:setInterval.bind(c),clearInterval:clearInterval.bind(c)}}const n=function(){let c=0;return function(){return c++,c}}(),t={},s={};e.onmessage=function(c){const _=c.data,u=t[_];if(u){u(),t[_]=null;return}const l=s[_];l&&l()};function o(c,_){const u=n();return e.postMessage(["setTimeout",u,_]),t[u]=c,u}function r(c){e.postMessage(["clearTimeout",c]),t[c]=null}function i(c,_){const u=n();return e.postMessage(["setInterval",u,_]),s[u]=c,u}function a(c){e.postMessage(["clearInterval",c]),s[c]=null}return{setTimeout:o,clearTimeout:r,setInterval:i,clearInterval:a}}(),he="7.22.8-alpha.1449";let ye=null,z;const Q=({milliseconds:e})=>new Promise(n=>V.setTimeout(n,e)),ge=(e="/")=>{try{z=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:z.signal}).catch(s=>{console.log(s)}),Q({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},De=()=>{z&&z.abort()},Re=(e="/")=>fetch(`${e}OidcKeepAliveServiceWorker.json`,{headers:{"oidc-vanilla":"true"}}).then(n=>n.statusText==="oidc-service-worker").catch(n=>{console.log(n)}),$e=e=>async(n,t)=>{t(),await n.update();const s=await n.unregister();console.log(`Service worker unregistering ${s}`),await Q({milliseconds:2e3}),e.reload()},O=e=>n=>new Promise(function(t,s){const o=new MessageChannel;o.port1.onmessage=function(r){r.data&&r.data.error?s(r.data.error):t(r.data)},e.active.postMessage(n,[o.port2])}),I=async(e,n)=>{const t=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!t||e.service_worker_activate()===!1)return null;let s=null;e.register?s=await e.service_worker_register(t):s=await navigator.serviceWorker.register(t);try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await O(s)({type:"claim"})}catch{return null}const o=async g=>O(s)({type:"clear",data:{status:g},configurationName:n}),r=async(g,S,T)=>{const L=await O(s)({type:"init",data:{oidcServerConfiguration:g,where:S,oidcConfiguration:{token_renew_mode:T.token_renew_mode,service_worker_convert_all_requests_to_cors:T.service_worker_convert_all_requests_to_cors}},configurationName:n}),K=L.version;return K!==he&&(console.warn(`Service worker ${K} version mismatch with js client version ${he}, unregistering and reloading`),await T.service_worker_update_require_callback(s,De)),{tokens:ne(L.tokens,null,T.token_renew_mode),status:L.status}},i=(g="/")=>{ye==null&&(ye="not_null",ge(g))},a=g=>O(s)({type:"setSessionState",data:{sessionState:g},configurationName:n}),c=async()=>(await O(s)({type:"getSessionState",data:null,configurationName:n})).sessionState,_=g=>(sessionStorage[`oidc.nonce.${n}`]=g.nonce,O(s)({type:"setNonce",data:{nonce:g},configurationName:n})),u=async()=>{let S=(await O(s)({type:"getNonce",data:null,configurationName:n})).nonce;return S||(S=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:S}};let l={};return{clearAsync:o,initAsync:r,startKeepAliveServiceWorker:()=>i(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:a,getSessionStateAsync:c,setNonceAsync:_,getNonceAsync:u,setLoginParams:g=>{l[n]=g,localStorage[`oidc.login.${n}`]=JSON.stringify(g)},getLoginParams:()=>{const g=localStorage[`oidc.login.${n}`];return l[n]||(l[n]=JSON.parse(g)),l[n]},getStateAsync:async()=>{let S=(await O(s)({type:"getState",data:null,configurationName:n})).state;return S||(S=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),S},setStateAsync:async g=>(sessionStorage[`oidc.state.${n}`]=g,O(s)({type:"setState",data:{state:g},configurationName:n})),getCodeVerifierAsync:async()=>{let S=(await O(s)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return S||(S=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),S},setCodeVerifierAsync:async g=>(sessionStorage[`oidc.code_verifier.${n}`]=g,O(s)({type:"setCodeVerifier",data:{codeVerifier:g},configurationName:n})),setDemonstratingProofOfPossessionNonce:async g=>{await O(s)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:g},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await O(s)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async g=>{const S=JSON.stringify(g);await O(s)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:S},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const g=await O(s)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return g.demonstratingProofOfPossessionJwkJson?JSON.parse(g.demonstratingProofOfPossessionJwkJson):null}}},$={},Ue=(e,n=window.sessionStorage,t)=>{if(!$[e]&&n){const o=n.getItem(e);o&&($[e]=JSON.parse(o))}const s=1e3*t;return $[e]&&$[e].timestamp+s>Date.now()?$[e].result:null},Ke=(e,n,t=window.sessionStorage)=>{const s=Date.now();$[e]={result:n,timestamp:s},t&&t.setItem(e,JSON.stringify({result:n,timestamp:s}))};function ke(e){return new TextEncoder().encode(e)}function me(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Fe(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(t,s){return String.fromCharCode(parseInt(s,16))})}const te=e=>{let n="";return e.forEach(function(t){n+=String.fromCharCode(t)}),me(n)};function pe(e){return me(Fe(e))}const Ve={importKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256",hash:{name:"ES256"}},signAlgorithm:{name:"ECDSA",hash:{name:"SHA-256"}},generateKeyAlgorithm:{name:"ECDSA",namedCurve:"P-256"},digestAlgorithm:{name:"SHA-256"},jwtHeaderAlgorithm:"ES256"};var Me={sign:e=>async(n,t,s,o,r="dpop+jwt")=>{switch(n=Object.assign({},n),t.typ=r,t.alg=o.jwtHeaderAlgorithm,t.alg){case"ES256":t.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":t.jwk={kty:n.kty,n:n.n,e:n.e,kid:t.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const i={protected:pe(JSON.stringify(t)),payload:pe(JSON.stringify(s))},a=o.importKeyAlgorithm,c=!0,_=["sign"],u=await e.crypto.subtle.importKey("jwk",n,a,c,_),l=ke(`${i.protected}.${i.payload}`),f=o.signAlgorithm,h=await e.crypto.subtle.sign(f,u,l);return i.signature=te(new Uint8Array(h)),`${i.protected}.${i.payload}.${i.signature}`}};const Je={generate:e=>async n=>{const t=n,s=!0,o=["sign","verify"],r=await e.crypto.subtle.generateKey(t,s,o);return await e.crypto.subtle.exportKey("jwk",r.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}};var Be={thumbprint:e=>async(n,t)=>{let s;switch(n.kty){case"EC":s='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":s='{"e":"E","kty":"RSA","n":"N"}'.replace("E",n.e).replace("N",n.n);break;default:throw new Error("Unknown or not implemented JWK type")}const o=await e.crypto.subtle.digest(t,ke(s));return te(new Uint8Array(o))}};const je=e=>async n=>await Je.generate(e)(n),we=e=>n=>async(t,s="POST",o,r={})=>{const i={jti:btoa(He()),htm:s,htu:o,iat:Math.round(Date.now()/1e3),...r},a=await Be.thumbprint(e)(t,n.digestAlgorithm);return await Me.sign(e)(t,{kid:a},i,n)},He=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let t=0,s="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(t=Math.random()*16|0),e[o]==="x"?s+=n[t]:e[o]==="y"?(t&=3,t|=8,s+=n[t]):s+=e[o];return s},Ae=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",qe=e=>{const n=[];for(let t=0;t<e.byteLength;t+=1){const s=e[t]%se.length;n.push(se[s])}return n.join("")},oe=e=>{const n=new Uint8Array(e),{hasCrypto:t}=Ae();if(t)window.crypto.getRandomValues(n);else for(let s=0;s<e;s+=1)n[s]=Math.random()*se.length|0;return qe(n)};function Ge(e){const n=new ArrayBuffer(e.length),t=new Uint8Array(n);for(let s=0;s<e.length;s++)t[s]=e.charCodeAt(s);return t}function Se(e){return new Promise((n,t)=>{crypto.subtle.digest("SHA-256",Ge(e)).then(s=>n(te(new Uint8Array(s))),s=>t(s))})}const Ye=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Ae();return n?Se(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},Xe=60*60,ze=e=>async(n,t=Xe,s=window.sessionStorage,o=1e4)=>{const r=`${n}/.well-known/openid-configuration`,i=`oidc.server:${n}`,a=Ue(i,s,t);if(a)return new ce(a);const c=await M(e)(r,{},o);if(c.status!==200)return null;const _=await c.json();return Ke(i,_,s),new ce(_)},M=e=>async(n,t={},s=1e4,o=0)=>{let r;try{const i=new AbortController;setTimeout(()=>i.abort(),s),r=await e(n,{...t,signal:i.signal})}catch(i){if(i.name==="AbortError"||i.message==="Network request failed"){if(o<=1)return await M(e)(n,t,s,o+1);throw i}else throw console.error(i.message),i}return r},re={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,t,s=re.refresh_token,o,r={},i=1e4)=>{const a={token:t,token_type_hint:s,client_id:o};for(const[l,f]of Object.entries(r))a[l]===void 0&&(a[l]=f);const c=[];for(const l in a){const f=encodeURIComponent(l),h=encodeURIComponent(a[l]);c.push(`${f}=${h}`)}const _=c.join("&");return(await M(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:_},i)).status!==200?{success:!1}:{success:!0}},Qe=e=>async(n,t,s,o,r={},i,a=1e4)=>{for(const[h,y]of Object.entries(s))t[h]===void 0&&(t[h]=y);const c=[];for(const h in t){const y=encodeURIComponent(h),m=encodeURIComponent(t[h]);c.push(`${y}=${m}`)}const _=c.join("&"),u=await M(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...r},body:_},a);if(u.status!==200)return{success:!1,status:u.status,demonstratingProofOfPossessionNonce:null};const l=await u.json();let f=null;return u.headers.has(Z)&&(f=u.headers.get(Z)),{success:!0,status:u.status,data:ne(l,o,i),demonstratingProofOfPossessionNonce:f}},Ze=(e,n)=>async(t,s)=>{s=s?{...s}:{};const o=oe(128),r=await Ye(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(s.state),s.code_challenge=r,s.code_challenge_method="S256";let i="";if(s)for(const[a,c]of Object.entries(s))i===""?i+="?":i+="&",i+=`${a}=${encodeURIComponent(c)}`;n.open(`${t}${i}`)},Z="DPoP-Nonce",en=e=>async(n,t,s,o,r=1e4)=>{t=t?{...t}:{},t.code_verifier=await e.getCodeVerifierAsync();const i=[];for(const l in t){const f=encodeURIComponent(l),h=encodeURIComponent(t[l]);i.push(`${f}=${h}`)}const a=i.join("&"),c=await M(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...s},body:a},r);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),c.status!==200)return{success:!1,status:c.status};let _=null;c.headers.has(Z)&&(_=c.headers.get(Z));const u=await c.json();return{success:!0,data:{state:t.state,tokens:ne(u,null,o),demonstratingProofOfPossessionNonce:_}}};async function Te(e,n,t){const s=a=>{e.tokens=a},{tokens:o,status:r}=await ee(e)(0,n,t,s);return await I(e.configuration,e.configurationName)||await P(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?o:(await e.destroyAsync(r),null)}const nn=async(e,n)=>{const t=await I(n,e.configurationName);if(t){const s=await e.initAsync(n.authority,n.authority_configuration),{tokens:o}=await t.initAsync(s,"tryKeepExistingSessionAsync",n);return o}else{const s=P(e.configurationName,n.storage??sessionStorage);let{tokens:o}=await s.initAsync();return o=X(o,e.tokens,n.token_renew_mode),o}};async function be(e,n=!1,t=null){const s=e.configuration,o=`${s.client_id}_${e.configurationName}_${s.authority}`;let r;const i=await I(e.configuration,e.configurationName);return(s==null?void 0:s.storage)===(window==null?void 0:window.sessionStorage)&&!i?r=await Te(e,n,t):r=await navigator.locks.request(o,{ifAvailable:!0},async a=>a?await Te(e,n,t):(e.publishEvent(N.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),await nn(e,s))),r?(e.timeoutId&&(e.timeoutId=J(e,e.tokens.expiresAt,t)),e.tokens):null}const J=(e,n,t=null)=>{const s=e.configuration.refresh_time_before_tokens_expiration_in_second;return console.log("autoRenewTokens",s,n),V.setTimeout(async()=>{const r={timeLeft:F(s,n)};console.log("autoRenewTokens",r),e.publishEvent(N.eventNames.token_timer,r),await be(e,!1,t)},1e3)},x={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",LOGOUT_FROM_ANOTHER_TAB:"LOGOUT_FROM_ANOTHER_TAB",REQUIRE_SYNC_TOKENS:"REQUIRE_SYNC_TOKENS"},tn=e=>async(n,t,s,o=!1)=>{const r={nonce:null};if(!s)return{tokens:null,status:"NOT_CONNECTED",nonce:r};let i=r;const a=await e.initAsync(n.authority,n.authority_configuration),c=await I(n,t);if(c){const{status:l,tokens:f}=await c.initAsync(a,"syncTokensAsync",n);if(l==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};if(l==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(!l||!f)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:r};if(f.issuedAt!==s.issuedAt){const y=F(n.refresh_time_before_tokens_expiration_in_second,f.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",m=await c.getNonceAsync();return{tokens:f,status:y,nonce:m}}i=await c.getNonceAsync()}else{const l=P(t,n.storage??sessionStorage);let{tokens:f,status:h}=await l.initAsync();if(f&&(f=X(f,e.tokens,n.token_renew_mode)),f){if(h==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:r};if(f.issuedAt!==s.issuedAt){const m=F(n.refresh_time_before_tokens_expiration_in_second,f.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",d=await l.getNonceAsync();return{tokens:f,status:m,nonce:d}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:r};i=await l.getNonceAsync()}const u=F(n.refresh_time_before_tokens_expiration_in_second,s.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:s,status:"FORCE_REFRESH",nonce:i}:{tokens:s,status:u,nonce:i}},ee=e=>async(n=0,t=!1,s=null,o)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let r=6;for(;!navigator.onLine&&r>0;)await Q({milliseconds:1e3}),r--,e.publishEvent(p.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const i=n+1;s||(s={});const a=e.configuration,c=(u,l=null,f=null)=>ie(e.configurationName,e.configuration,e.publishEvent.bind(e))(u,l,f),_=async()=>{try{let u;const l=await I(a,e.configurationName);l?u=l.getLoginParams():u=P(e.configurationName,a.storage).getLoginParams();const f=await c({...u.extras,...s,prompt:"none"});return f?f.error?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(o(f.tokens),e.publishEvent(N.eventNames.token_renewed,{}),{tokens:f.tokens,status:"LOGGED"}):(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(u){return console.error(u),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:u.message}),await ee(e)(i,t,s,o)}};try{const{status:u,tokens:l,nonce:f}=await tn(e)(a,e.configurationName,e.tokens,t);switch(u){case x.SESSION_LOST:return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case x.NOT_CONNECTED:return o(null),{tokens:null,status:null};case x.TOKENS_VALID:return o(l),{tokens:l,status:"LOGGED_IN"};case x.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return o(l),e.publishEvent(N.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:l,status:"LOGGED_IN"};case x.LOGOUT_FROM_ANOTHER_TAB:return o(null),e.publishEvent(p.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case x.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted&&x.FORCE_REFRESH!==u?(e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(p.refreshTokensAsync_begin,{tryNumber:n}),await _());default:{if(a.token_automatic_renew_mode==R.AutomaticOnlyWhenFetchExecuted&&x.FORCE_REFRESH!==u)return e.publishEvent(p.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(p.refreshTokensAsync_begin,{refreshToken:l.refreshToken,status:u,tryNumber:n}),!l.refreshToken)return await _();const h=a.client_id,y=a.redirect_uri,m=a.authority,w={...a.token_request_extras?a.token_request_extras:{}};for(const[A,b]of Object.entries(s))A.endsWith(":token_request")&&(w[A.replace(":token_request","")]=b);return await(async()=>{const A={client_id:h,redirect_uri:y,grant_type:"refresh_token",refresh_token:l.refreshToken},b=await e.initAsync(m,a.authority_configuration),k=document.hidden?1e4:3e4*10,g=b.tokenEndpoint,S={};a.demonstrating_proof_of_possession&&(S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(l.accessToken,g,"POST"));const T=await Qe(e.getFetch())(g,A,w,l,S,a.token_renew_mode,k);if(T.success){const{isValid:L,reason:K}=de(T.data,f.nonce,b);if(!L)return o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${K}`}),{tokens:null,status:"SESSION_LOST"};if(o(T.data),T.demonstratingProofOfPossessionNonce){const E=await I(a,e.configurationName);E?await E.setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce):await P(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce)}return e.publishEvent(p.refreshTokensAsync_end,{success:T.success}),e.publishEvent(N.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:T.data,status:"LOGGED_IN"}}else return e.publishEvent(p.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:T}),T.status>=400&&T.status<500?(o(null),e.publishEvent(p.refreshTokensAsync_error,{message:`session lost: ${T.status}`}),{tokens:null,status:"SESSION_LOST"}):await ee(e)(i,t,s,o)})()}}}catch(u){return console.error(u),e.publishEvent(p.refreshTokensAsync_silent_error,{message:"exception",exception:u.message}),ee(e)(i,t,s,o)}},ie=(e,n,t)=>(s=null,o=null,r=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{t(p.silentLoginAsync_begin,{});let i="";if(o&&(s==null&&(s={}),s.state=o),r&&(s==null&&(s={}),s.scope=r),s!=null)for(const[l,f]of Object.entries(s))i===""?i=`?${encodeURIComponent(l)}=${encodeURIComponent(f)}`:i+=`&${encodeURIComponent(l)}=${encodeURIComponent(f)}`;const a=n.silent_login_uri+i,c=a.indexOf("/",a.indexOf("//")+2),_=a.substring(0,c),u=document.createElement("iframe");return u.width="0px",u.height="0px",u.id=`${e}_oidc_iframe`,u.setAttribute("src",a),document.body.appendChild(u),new Promise((l,f)=>{let h=!1;const y=()=>{window.removeEventListener("message",m),u.remove(),h=!0},m=d=>{if(d.origin===_&&d.source===u.contentWindow){const w=`${e}_oidc_tokens:`,v=`${e}_oidc_error:`,A=`${e}_oidc_exception:`,b=d.data;if(b&&typeof b=="string"&&!h){if(b.startsWith(w)){const k=JSON.parse(d.data.replace(w,""));t(p.silentLoginAsync_end,{}),l(k),y()}else if(b.startsWith(v)){const k=JSON.parse(d.data.replace(v,""));t(p.silentLoginAsync_error,k),l({error:"oidc_"+k.error,tokens:null,sessionState:null}),y()}else if(b.startsWith(A)){const k=JSON.parse(d.data.replace(A,""));t(p.silentLoginAsync_error,k),f(new Error(k.error)),y()}}}};try{window.addEventListener("message",m);const d=n.silent_login_timeout;setTimeout(()=>{h||(y(),t(p.silentLoginAsync_error,{reason:"timeout"}),f(new Error("timeout")))},d)}catch(d){y(),t(p.silentLoginAsync_error,d),f(d)}})}catch(i){throw t(p.silentLoginAsync_error,i),i}},sn=(e,n,t,s,o)=>(r=null,i=void 0)=>{r={...r};const a=(_,u,l)=>ie(n,t,s.bind(o))(_,u,l);return(async()=>{o.timeoutId&&V.clearTimeout(o.timeoutId);let _;r&&"state"in r&&(_=r.state,delete r.state);try{const u=t.extras?{...t.extras,...r}:r,l=await a({...u,prompt:"none"},_,i);if(l)return o.tokens=l.tokens,s(p.token_aquired,{}),o.timeoutId=J(o,o.tokens.expiresAt,r),{}}catch(u){return u}})()},on=(e,n,t)=>(s,o,r,i=!1)=>{const a=(c,_=void 0,u=void 0)=>ie(e.configurationName,t,e.publishEvent.bind(e))(c,_,u);return new Promise((c,_)=>{if(t.silent_login_uri&&t.silent_redirect_uri&&t.monitor_session&&s&&r&&!i){const u=()=>{e.checkSessionIFrame.stop();const l=e.tokens;if(l===null)return;const f=l.idToken,h=l.idTokenPayload;return a({prompt:"none",id_token_hint:f,scope:t.scope||"openid"}).then(y=>{if(y.error)throw new Error(y.error);const m=y.tokens.idTokenPayload;if(h.sub===m.sub){const d=y.sessionState;e.checkSessionIFrame.start(y.sessionState),h.sid===m.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",d):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",d)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",m.sub)}).catch(async y=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",y);for(const[m,d]of Object.entries(n))await d.logoutOtherTabAsync(t.client_id,h.sub)})};e.checkSessionIFrame=new Ce(u,o,s),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(r),c(e.checkSessionIFrame)}).catch(l=>{_(l)})}else c(null)})},Ee=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let t=n[6],s=n[7];if(s){const o=s.split("?");o.length===2&&(s=o[0],t=o[1])}return t.startsWith("?")&&(t=t.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:t,hash:s}},rn=e=>{const n=Ee(e);let{path:t}=n;t.endsWith("/")&&(t=t.slice(0,-1));let{hash:s}=n;return s==="#_=_"&&(s=""),s&&(t+=s),t},B=e=>{const n=Ee(e),{search:t}=n;return an(t)},an=e=>{const n={};let t,s,o;const r=e.split("&");for(s=0,o=r.length;s<o;s++)t=r[s].split("="),n[decodeURIComponent(t[0])]=decodeURIComponent(t[1]);return n},cn=(e,n,t,s,o)=>(r=void 0,i=null,a=!1,c=void 0)=>{const _=i;return i={...i},(async()=>{const l=r||o.getPath();if("state"in i||(i.state=oe(16)),t(p.loginAsync_begin,{}),i)for(const f of Object.keys(i))f.endsWith(":token_request")&&delete i[f];try{const f=a?n.silent_redirect_uri:n.redirect_uri;c||(c=n.scope);const h=n.extras?{...n.extras,...i}:i;h.nonce||(h.nonce=oe(12));const y={nonce:h.nonce},m=await I(n,e),d=await s(n.authority,n.authority_configuration);let w;if(m)m.setLoginParams({callbackPath:l,extras:_}),await m.initAsync(d,"loginAsync",n),await m.setNonceAsync(y),m.startKeepAliveServiceWorker(),w=m;else{const A=P(e,n.storage??sessionStorage);A.setLoginParams({callbackPath:l,extras:_}),await A.setNonceAsync(y),w=A}const v={client_id:n.client_id,redirect_uri:f,scope:c,response_type:"code",...h};await Ze(w,o)(d.authorizationEndpoint,v)}catch(f){throw t(p.loginAsync_error,f),f}})()},ln=e=>async(n=!1)=>{try{e.publishEvent(p.loginCallbackAsync_begin,{});const t=e.configuration,s=t.client_id,o=n?t.silent_redirect_uri:t.redirect_uri,r=t.authority,i=t.token_request_timeout,a=await e.initAsync(r,t.authority_configuration),c=e.location.getCurrentHref(),u=B(c).session_state,l=await I(t,e.configurationName);let f,h,y,m;if(l)await l.initAsync(a,"loginCallbackAsync",t),await l.setSessionStateAsync(u),h=await l.getNonceAsync(),y=l.getLoginParams(),m=await l.getStateAsync(),l.startKeepAliveServiceWorker(),f=l;else{const E=P(e.configurationName,t.storage??sessionStorage);await E.setSessionStateAsync(u),h=await E.getNonceAsync(),y=E.getLoginParams(),m=await E.getStateAsync(),f=E}const d=B(c);if(d.error||d.error_description)throw new Error(`Error from OIDC server: ${d.error} - ${d.error_description}`);if(d.iss&&d.iss!==a.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${a.issuer}, received: ${d.iss})`);if(d.state&&d.state!==m)throw new Error(`State not valid (expected: ${m}, received: ${d.state})`);const w={code:d.code,grant_type:"authorization_code",client_id:t.client_id,redirect_uri:o},v={};if(t.token_request_extras)for(const[E,q]of Object.entries(t.token_request_extras))v[E]=q;if(y&&y.extras)for(const[E,q]of Object.entries(y.extras))E.endsWith(":token_request")&&(v[E.replace(":token_request","")]=q);const A=a.tokenEndpoint,b={};if(t.demonstrating_proof_of_possession)if(l)b.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const E=await je(window)(t.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await P(e.configurationName,t.storage).setDemonstratingProofOfPossessionJwkAsync(E),b.DPoP=await we(window)(t.demonstrating_proof_of_possession_configuration)(E,"POST",A)}const k=await en(f)(A,{...w,...v},b,e.configuration.token_renew_mode,i);if(!k.success)throw new Error("Token request failed");let g;const S=k.data.tokens,T=k.data.demonstratingProofOfPossessionNonce;if(k.data.state!==v.state)throw new Error("state is not valid");const{isValid:L,reason:K}=de(S,h.nonce,a);if(!L)throw new Error(`Tokens are not OpenID valid, reason: ${K}`);if(l){if(S.refreshToken&&!S.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(T&&S.accessToken&&S.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(l)await l.initAsync(a,"syncTokensAsync",t),g=l.getLoginParams(),T&&await l.setDemonstratingProofOfPossessionNonce(T);else{const E=P(e.configurationName,t.storage);g=E.getLoginParams(),T&&await E.setDemonstratingProofOfPossessionNonce(T)}return await e.startCheckSessionAsync(a.checkSessionIframe,s,u,n),e.publishEvent(p.loginCallbackAsync_end,{}),{tokens:S,state:"request.state",callbackPath:g.callbackPath}}catch(t){throw console.error(t),e.publishEvent(p.loginCallbackAsync_error,t),t}},Oe={access_token:"access_token",refresh_token:"refresh_token"},ae=(e,n)=>{const t={};if(e){for(const[s,o]of Object.entries(e))if(s.endsWith(n)){const r=s.replace(n,"");t[r]=o}return t}return t},un=e=>{const n={};if(e){for(const[t,s]of Object.entries(e))t.includes(":")||(n[t]=s);return n}return n},fn=e=>async n=>{V.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const t=await I(e.configuration,e.configurationName);t?await t.clearAsync(n):await P(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},_n=(e,n,t,s,o)=>async(r=void 0,i=null)=>{const a=e.configuration,c=await e.initAsync(a.authority,a.authority_configuration);r&&typeof r!="string"&&(r=void 0,s.warn("callbackPathOrUrl path is not a string"));const _=r??o.getPath();let u=!1;r&&(u=r.includes("https://")||r.includes("http://"));const l=u?r:o.getOrigin()+_,f=e.tokens?e.tokens.idToken:"";try{const w=c.revocationEndpoint;if(w){const v=[],A=e.tokens?e.tokens.accessToken:null;if(A&&a.logout_tokens_to_invalidate.includes(Oe.access_token)){const k=ae(i,":revoke_access_token"),g=ve(t)(w,A,re.access_token,a.client_id,k);v.push(g)}const b=e.tokens?e.tokens.refreshToken:null;if(b&&a.logout_tokens_to_invalidate.includes(Oe.refresh_token)){const k=ae(i,":revoke_refresh_token"),g=ve(t)(w,b,re.refresh_token,a.client_id,k);v.push(g)}v.length>0&&await Promise.all(v)}}catch(w){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(w)}const h=e.tokens&&e.tokens.idTokenPayload?e.tokens.idTokenPayload.sub:null;await e.destroyAsync("LOGGED_OUT");for(const[w,v]of Object.entries(n))v!==e?await e.logoutSameTabAsync(e.configuration.client_id,h):e.publishEvent(p.logout_from_same_tab,{});const y=ae(i,":oidc");if(y&&y.no_reload==="true")return;const d=un(i);if(c.endSessionEndpoint){"id_token_hint"in d||(d.id_token_hint=f),!("post_logout_redirect_uri"in d)&&r!==null&&(d.post_logout_redirect_uri=l);let w="";for(const[v,A]of Object.entries(d))A!=null&&(w===""?w+="?":w+="&",w+=`${v}=${encodeURIComponent(A)}`);o.open(`${c.endSessionEndpoint}${w}`)}else o.reload()},Pe=(e,n,t=!1)=>async(...s)=>{var h;const[o,r,...i]=s,a=r?{...r}:{method:"GET"};let c=new Headers;a.headers&&(c=a.headers instanceof Headers?a.headers:new Headers(a.headers));const _=n,u=await _e(_),l=(h=u==null?void 0:u.tokens)==null?void 0:h.accessToken;if(c.has("Accept")||c.set("Accept","application/json"),l){if(_.configuration.demonstrating_proof_of_possession&&t){const y=await _.generateDemonstrationOfProofOfPossessionAsync(l,o.toString(),a.method);c.set("Authorization",`PoP ${l}`),c.set("DPoP",y)}else c.set("Authorization",`Bearer ${l}`);a.credentials||(a.credentials="same-origin")}const f={...a,headers:c};return await e(o,f,...i)},dn=e=>async(n=!1,t=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const s=e.configuration,r=(await e.initAsync(s.authority,s.authority_configuration)).userInfoEndpoint,a=await(async()=>{const _=await Pe(fetch,e,t)(r);return _.status!==200?null:_.json()})();return e.userInfo=a,a};class j{open(n){window.location.href=n}reload(){window.location.reload()}getCurrentHref(){return window.location.href}getPath(){const n=window.location;return n.pathname+(n.search||"")+(n.hash||"")}getOrigin(){return window.origin}}const hn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),yn=e=>{const n=e.appVersion,t=e.userAgent,s="-";let o=s;const r=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const a in r){const c=r[a];if(c.r.test(t)){o=c.s;break}}let i=s;switch(/Windows/.test(o)&&(i=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":i=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(t)[1];break;case"iOS":{const a=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);a!=null&&a.length>2&&(i=a[1]+"."+a[2]+"."+(parseInt(a[3])|0));break}}return{os:o,osVersion:i}};function gn(){const e=navigator.userAgent;let n,t=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(t[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(t[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let s=n[1];if(!s){const o=e.split(n[0]+"/");o.length>1&&(s=o[1])}return{name:"opera",version:s}}return t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&t.splice(1,1,n[1]),{name:t[0].toLowerCase(),version:t[1]}}const kn=()=>{const{name:e,version:n}=gn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const t=yn(navigator);return!hn(t)},mn=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(p.tryKeepExistingSessionAsync_begin,{});try{const t=e.configuration,s=await e.initAsync(t.authority,t.authority_configuration);if(n=await I(t,e.configurationName),n){const{tokens:o}=await n.initAsync(s,"tryKeepExistingSessionAsync",t);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const r=n.getLoginParams(e.configurationName);e.timeoutId=J(e,e.tokens.expiresAt,r.extras);const i=await n.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,i),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{t.service_worker_relative_url&&e.publishEvent(p.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=P(e.configurationName,t.storage??sessionStorage),{tokens:r}=await o.initAsync();if(r){e.tokens=X(r,null,t.token_renew_mode);const i=o.getLoginParams();e.timeoutId=J(e,e.tokens.expiresAt,i.extras);const a=await o.getSessionStateAsync();return await e.startCheckSessionAsync(s.check_session_iframe,t.client_id,a),t.preload_user_info&&await e.userInfoAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(p.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(t){return console.error(t),n&&await n.clearAsync(),e.publishEvent(p.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Ie=()=>fetch;class ce{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const W={},pn=(e,n=new j)=>(t,s="default")=>(W[s]||(W[s]=new N(t,s,e,n)),W[s]),wn=async e=>{const{parsedTokens:n,callbackPath:t}=await e.loginCallbackAsync();return e.timeoutId=J(e,n.expiresAt),{callbackPath:t}},An=e=>Math.floor(Math.random()*e),H=class H{constructor(n,t="default",s,o=new j){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let r=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(r=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let i=n.refresh_time_before_tokens_expiration_in_second??120;i>60&&(i=i-Math.floor(Math.random()*40)),this.location=o??new j;const a=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:r,token_automatic_renew_mode:n.token_automatic_renew_mode??R.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:i,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??Y.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:a,service_worker_activate:n.service_worker_activate??kn,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Ve,preload_user_info:n.preload_user_info??!1},this.getFetch=s??Ie,this.configurationName=t,this.tokens=null,this.userInfo=null,this.events=[],this.timeoutId=null,this.loginCallbackWithAutoTokensRenewAsync.bind(this),this.initAsync.bind(this),this.loginCallbackAsync.bind(this),this.subscribeEvents.bind(this),this.removeEventSubscription.bind(this),this.publishEvent.bind(this),this.destroyAsync.bind(this),this.logoutAsync.bind(this),this.renewTokensAsync.bind(this),this.initAsync(this.configuration.authority,this.configuration.authority_configuration)}subscribeEvents(n){const t=An(9999999999999).toString();return this.events.push({id:t,func:n}),t}removeEventSubscription(n){const t=this.events.filter(s=>s.id!==n);this.events=t}publishEvent(n,t){this.events.forEach(s=>{s.func(n,t)})}static get(n="default"){const t=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(W,n)&&t)throw Error(`OIDC library does seem initialized.
2
+ Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return W[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,t=B(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:t.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const t=this.location,s=B(t.getCurrentHref());s.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:s.error})}`,t.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,t.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,t){if(this.initPromise!==null)return this.initPromise;const s=async()=>{if(t!=null)return new ce({authorization_endpoint:t.authorization_endpoint,end_session_endpoint:t.end_session_endpoint,revocation_endpoint:t.revocation_endpoint,token_endpoint:t.token_endpoint,userinfo_endpoint:t.userinfo_endpoint,check_session_iframe:t.check_session_iframe,issuer:t.issuer});const r=await I(this.configuration,this.configurationName)?window.localStorage:null;return await ze(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??60*60,r,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=s(),this.initPromise.then(o=>(this.initPromise=null,o))}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=mn(this),this.tryKeepExistingSessionPromise.then(n=>(this.tryKeepExistingSessionPromise=null,n)))}async startCheckSessionAsync(n,t,s,o=!1){await on(this,W,this.configuration)(n,t,s,o)}async loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this.loginPromise!==null?this.loginPromise:r?sn(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(t,o):(this.loginPromise=cn(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,t,s,o),this.loginPromise.then(i=>(this.loginPromise=null,i)))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const t=async()=>{const s=await ln(this)(n),o=s.tokens;return this.tokens=o,await I(this.configuration,this.configurationName)||P(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(H.eventNames.token_aquired,o),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:o,state:s.state,callbackPath:s.callbackPath}};return this.loginCallbackPromise=t(),this.loginCallbackPromise.then(s=>(this.loginCallbackPromise=null,s))}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){const r=this.configuration,i={ath:await Se(n),...o},a=await I(r,this.configurationName);let c;if(a)return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}`;const _=P(this.configurationName,r.storage);let u=await _.getDemonstratingProofOfPossessionJwkAsync();return c=await _.getDemonstratingProofOfPossessionNonce(),c&&(i.nonce=c),await we(window)(r.demonstrating_proof_of_possession_configuration)(u,s,t,i)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=wn(this),this.loginCallbackWithAutoTokensRenewPromise.then(n=>(this.loginCallbackWithAutoTokensRenewPromise=null,n)))}userInfoAsync(n=!1,t=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=dn(this)(n,t),this.userInfoPromise.then(s=>(this.userInfoPromise=null,s)))}async renewTokensAsync(n=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return V.clearTimeout(this.timeoutId),this.renewTokensPromise=be(this,!0,n),this.renewTokensPromise.then(t=>(this.renewTokensPromise=null,t))}async destroyAsync(n){return await fn(this)(n)}async logoutSameTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_same_tab,{mmessage:"SessionMonitor",sub:t}))}async logoutOtherTabAsync(n,t){this.configuration.monitor_session&&this.configuration.client_id===n&&t&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===t&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(p.logout_from_another_tab,{message:"SessionMonitor",sub:t}))}async logoutAsync(n=void 0,t=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=_n(this,W,this.getFetch(),console,this.location)(n,t),this.logoutPromise.then(s=>(this.logoutPromise=null,s)))}};H.getOrCreate=(n,t)=>(s,o="default")=>pn(n,t)(s,o),H.eventNames=p;let N=H;const U=class U{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,t){this._oidc.publishEvent(n,t)}static get(n="default"){return new U(N.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,t=null,s=!1,o=void 0,r=!1){return this._oidc.loginAsync(n,t,s,o,r)}logoutAsync(n=void 0,t=null){return this._oidc.logoutAsync(n,t)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null){return this._oidc.renewTokensAsync(n)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,t,s,o={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,t,s,o)}async getValidTokenAsync(n=200,t=50){return _e(this._oidc,n,t)}fetchWithTokens(n,t){return Pe(n,this,t)}async userInfoAsync(n=!1,t=!1){return this._oidc.userInfoAsync(n,t)}userInfo(){return this._oidc.userInfo}};U.getOrCreate=(n,t=new j)=>(s,o="default")=>new U(N.getOrCreate(n,t)(s,o)),U.eventNames=N.eventNames;let le=U;C.OidcClient=le,C.OidcLocation=j,C.TokenAutomaticRenewMode=R,C.TokenRenewMode=Y,C.getFetchDefault=Ie,C.getParseQueryStringFromLocation=B,C.getPath=rn,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"renewTokens.d.ts","sourceRoot":"","sources":["../src/renewTokens.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAgD,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAEvF,OAAO,EAAC,iBAAiB,EAAE,SAAS,EAA0B,MAAM,YAAY,CAAC;AAuCjF,wBAAsB,6BAA6B,CAAC,IAAI,KAAA,EAAE,YAAY,UAAQ,EAAE,MAAM,GAAC,SAAgB,gBA+BtG;AAED,eAAO,MAAM,eAAe,SAAS,IAAI,2BAAoB,SAAS,4BAQrE,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;CAQnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,IAAI,qBAA0B,iBAAiB,qBAAqB,MAAM,iBAAiB,MAAM;;;;;;EAkD1I,CAAA"}
1
+ {"version":3,"file":"renewTokens.d.ts","sourceRoot":"","sources":["../src/renewTokens.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAgD,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAEvF,OAAO,EAAC,iBAAiB,EAAE,SAAS,EAA0B,MAAM,YAAY,CAAC;AAuCjF,wBAAsB,6BAA6B,CAAC,IAAI,KAAA,EAAE,YAAY,UAAQ,EAAE,MAAM,GAAC,SAAgB,gBA+BtG;AAED,eAAO,MAAM,eAAe,SAAS,IAAI,2BAAoB,SAAS,4BAUrE,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;CAQnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,IAAI,qBAA0B,iBAAiB,qBAAqB,MAAM,iBAAiB,MAAM;;;;;;EAkD1I,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,KAAK;;;;;;;;;;CAgKP,CAAC;AAEL,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,KAAK;;;;;;;;;;CAmKP,CAAC;AAEL,eAAe,KAAK,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "7.22.7";
1
+ declare const _default: "7.22.8-alpha.1449";
2
2
  export default _default;
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA,wBAAwB"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA,wBAAmC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/oidc-client",
3
- "version": "7.22.7",
3
+ "version": "7.22.8-alpha.1449",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/AxaFrance/oidc-client.git"
21
21
  },
22
22
  "dependencies": {
23
- "@axa-fr/oidc-client-service-worker": "7.22.7"
23
+ "@axa-fr/oidc-client-service-worker": "7.22.8-alpha.1449"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/dom": "10.1.0",
@@ -77,9 +77,11 @@ export async function renewTokensAndStartTimerAsync(oidc, forceRefresh = false,
77
77
 
78
78
  export const autoRenewTokens = (oidc:Oidc, expiresAt, extras:StringMap = null) => {
79
79
  const refreshTimeBeforeTokensExpirationInSecond = oidc.configuration.refresh_time_before_tokens_expiration_in_second;
80
+ console.log('autoRenewTokens', refreshTimeBeforeTokensExpirationInSecond, expiresAt)
80
81
  return timer.setTimeout(async () => {
81
82
  const timeLeft = computeTimeLeft(refreshTimeBeforeTokensExpirationInSecond, expiresAt);
82
83
  const timeInfo = { timeLeft };
84
+ console.log('autoRenewTokens', timeInfo)
83
85
  oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
84
86
  await renewTokensAndStartTimerAsync(oidc, false, extras);
85
87
  }, 1000);
package/src/timer.ts CHANGED
@@ -2,7 +2,7 @@ const timer = (function () {
2
2
  const workerPort = (function () {
3
3
  let worker;
4
4
  let blobURL;
5
-
5
+
6
6
  const workerCode = function () {
7
7
  const innerIdsByOuterIds = {};
8
8
 
@@ -55,14 +55,17 @@ const timer = (function () {
55
55
  };
56
56
  };
57
57
  }.toString();
58
-
58
+ const isInsideBrowser = (typeof process === 'undefined');
59
59
  try {
60
60
  const blob = new Blob(['(', workerCode, ')()'], { type: 'application/javascript' });
61
61
  blobURL = URL.createObjectURL(blob);
62
62
  } catch (error) {
63
+ if (isInsideBrowser) {
64
+ console.warn('BlobUrl not available');
65
+ }
63
66
  return null;
64
67
  }
65
- const isInsideBrowser = (typeof process === 'undefined');
68
+
66
69
  try {
67
70
  if (SharedWorker) {
68
71
  worker = new SharedWorker(blobURL);
@@ -91,7 +94,7 @@ const timer = (function () {
91
94
  // In NextJS with SSR (Server Side Rendering) during rending in Node JS, the window object is undefined,
92
95
  // the global object is used instead as it is the closest approximation of a browsers window object.
93
96
  const bindContext = (typeof window === 'undefined') ? global : window;
94
-
97
+ console.log('Worker not available, using setTimeout' + (bindContext === global ? ' in NodeJS' : '') + '.');
95
98
  return {
96
99
  setTimeout: setTimeout.bind(bindContext),
97
100
  clearTimeout: clearTimeout.bind(bindContext),
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '7.22.7';
1
+ export default '7.22.8-alpha.1449';