@axa-fr/oidc-client 7.24.1 → 7.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crypto.d.ts +1 -1
- package/dist/crypto.d.ts.map +1 -1
- package/dist/index.js +402 -383
- package/dist/index.umd.cjs +2 -2
- package/dist/initWorker.d.ts.map +1 -1
- package/dist/keepSession.d.ts.map +1 -1
- package/dist/login.d.ts +2 -0
- package/dist/login.d.ts.map +1 -1
- package/dist/oidc.d.ts +3 -0
- package/dist/oidc.d.ts.map +1 -1
- package/dist/silentLogin.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/initWorker.ts +1 -0
- package/src/keepSession.ts +12 -2
- package/src/login.ts +13 -11
- package/src/oidc.ts +13 -3
- package/src/silentLogin.ts +0 -1
- package/src/version.ts +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(P,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(P=typeof globalThis<"u"?globalThis:P||self,L(P["oidc-client"]={}))})(this,function(P){"use strict";class L{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 le=2e3,K=console;class Ne{constructor(n,s,t,o=le,i=!0){this._callback=n,this._client_id=s,this._url=t,this._interval=o||le,this._stopOnError=i;const r=t.indexOf("/",t.indexOf("//")+2);this._frame_origin=t.substring(0,r),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=t}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?(K.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?(K.debug(n),K.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):K.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){K.debug("CheckSessionIFrame.start :"+n),this.stop();const s=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};s(),this._timer=window.setInterval(s,this._interval)}stop(){this._timer&&(K.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const m={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_acquired:"token_acquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},I=(e,n=sessionStorage)=>{const s=h=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:h}),Promise.resolve()),t=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const h=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:h.tokens,status:h.status})},o=h=>{n[`oidc.${e}`]=JSON.stringify({tokens:h})},i=async h=>{n[`oidc.session_state.${e}`]=h},r=async()=>n[`oidc.session_state.${e}`],l=h=>{n[`oidc.nonce.${e}`]=h.nonce},a=h=>{n[`oidc.jwk.${e}`]=JSON.stringify(h)},d=()=>JSON.parse(n[`oidc.jwk.${e}`]),_=async()=>({nonce:n[`oidc.nonce.${e}`]}),c=async h=>{n[`oidc.dpop_nonce.${e}`]=h},u=()=>n[`oidc.dpop_nonce.${e}`],f=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null,g={};return{clearAsync:s,initAsync:t,setTokens:o,getTokens:f,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:l,getNonceAsync:_,setLoginParams:h=>{g[e]=h,n[`oidc.login.${e}`]=JSON.stringify(h)},getLoginParams:()=>{const h=n[`oidc.login.${e}`];return h?(g[e]||(g[e]=JSON.parse(h)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async h=>{n[`oidc.state.${e}`]=h},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async h=>{n[`oidc.code_verifier.${e}`]=h},setDemonstratingProofOfPossessionNonce:c,getDemonstratingProofOfPossessionNonce:u,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:d}};var U=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(U||{});const xe=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),We=e=>JSON.parse(xe(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),ue=e=>{try{return e&&Le(e,".")===2?We(e.split(".")[1]):null}catch(n){console.warn(n)}return null},Le=(e,n)=>e.split(n).length-1,G={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 De(e,n,s){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:s&&s.iat?s.iat:new Date().getTime()/1e3;return e.issuedAt}const Z=(e,n=null,s)=>{if(!e)return null;let t;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?t=e.accessTokenPayload:t=ue(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:ue(i),l=r&&r.exp?r.exp:Number.MAX_VALUE,a=t&&t.exp?t.exp:e.issuedAt+o;e.issuedAt=De(e,t,r);let d;e.expiresAt?d=e.expiresAt:s===G.access_token_invalid?d=a:s===G.id_token_invalid?d=l:d=l<a?l:a;const _={...e,idTokenPayload:r,accessTokenPayload:t,expiresAt:d,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const c=n.refreshToken;return{..._,refreshToken:c}}return _},ee=(e,n,s)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const t={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(t.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(t.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(t.idTokenPayload=e.idTokenPayload),Z(t,n,s)},J=(e,n)=>{const s=new Date().getTime()/1e3,t=n-s;return Math.round(t-e)},_e=(e,n=0)=>e?J(n,e.expiresAt)>0:!1,fe=async(e,n=200,s=50)=>{let t=s;if(!e.getTokens())return null;for(;!_e(e.getTokens(),e.configuration.refresh_time_before_tokens_expiration_in_second)&&t>0;){if(e.configuration.token_automatic_renew_mode==U.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await X({milliseconds:n});t=t-1}return{isTokensValid:_e(e.getTokens()),tokens:e.getTokens(),numberWaited:t-s}},de=(e,n,s)=>{if(e.idTokenPayload){const t=e.idTokenPayload;if(s.issuer!==t.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${s.issuer} !== (idTokenPayload issuer) ${t.iss}`};const o=new Date().getTime()/1e3;if(t.exp&&t.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${t.exp} < (currentTimeUnixSecond) ${o}`};const i=60*60*24*7;if(t.iat&&t.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${t.iat+i} < (currentTimeUnixSecond) ${o}`};if(t.nonce&&t.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},F=function(){const e=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}}(),he="7.24.1";let ye=null,Y;const X=({milliseconds:e})=>new Promise(n=>F.setTimeout(n,e)),ge=(e="/")=>{try{Y=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:Y.signal}).catch(t=>{console.log(t)}),X({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},ke=()=>{Y&&Y.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,s)=>{s(),await n.update();const t=await n.unregister();console.log(`Service worker unregistration ${t?"successful":"failed"}`),await X({milliseconds:2e3}),e.reload()},Ke=e=>{const n=sessionStorage.getItem(`oidc.tabId.${e}`);if(n)return n;const s=globalThis.crypto.randomUUID();return sessionStorage.setItem(`oidc.tabId.${e}`,s),s},O=e=>n=>new Promise(function(s,t){const o=new MessageChannel;o.port1.onmessage=function(i){i!=null&&i.data.error?t(i.data.error):s(i.data),o.port1.close(),o.port2.close()},e.active.postMessage({...n,tabId:Ke(n.configurationName)},[o.port2])}),C=async(e,n)=>{var x;const s=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!s||e.service_worker_activate()===!1)return null;let t=null;e.service_worker_register?t=await e.service_worker_register(s):(t=await navigator.serviceWorker.register(s),t.active&&t.waiting&&(console.log("Detected new service worker waiting, unregistering and reloading"),await((x=e.service_worker_update_require_callback)==null?void 0:x.call(e,t,ke))));try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await O(t)({type:"claim"})}catch{return null}const o=async y=>O(t)({type:"clear",data:{status:y},configurationName:n}),i=async(y,w,T)=>{var W;const $=await O(t)({type:"init",data:{oidcServerConfiguration:y,where:w,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}),v=$.version;return v!==he&&(console.warn(`Service worker ${v} version mismatch with js client version ${he}, unregistering and reloading`),await((W=T.service_worker_update_require_callback)==null?void 0:W.call(T,t,ke))),{tokens:ee($.tokens,null,T.token_renew_mode),status:$.status}},r=(y="/")=>{ye==null&&(ye="not_null",ge(y))},l=y=>O(t)({type:"setSessionState",data:{sessionState:y},configurationName:n}),a=async()=>(await O(t)({type:"getSessionState",data:null,configurationName:n})).sessionState,d=y=>(sessionStorage[`oidc.nonce.${n}`]=y.nonce,O(t)({type:"setNonce",data:{nonce:y},configurationName:n})),_=async()=>{let w=(await O(t)({type:"getNonce",data:null,configurationName:n})).nonce;return w||(w=sessionStorage[`oidc.nonce.${n}`],console.warn("nonce not found in service worker, using sessionStorage")),{nonce:w}},c={};return{clearAsync:o,initAsync:i,startKeepAliveServiceWorker:()=>r(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:l,getSessionStateAsync:a,setNonceAsync:d,getNonceAsync:_,setLoginParams:y=>{c[n]=y,localStorage[`oidc.login.${n}`]=JSON.stringify(y)},getLoginParams:()=>{const y=localStorage[`oidc.login.${n}`];return c[n]||(c[n]=JSON.parse(y)),c[n]},getStateAsync:async()=>{let w=(await O(t)({type:"getState",data:null,configurationName:n})).state;return w||(w=sessionStorage[`oidc.state.${n}`],console.warn("state not found in service worker, using sessionStorage")),w},setStateAsync:async y=>(sessionStorage[`oidc.state.${n}`]=y,O(t)({type:"setState",data:{state:y},configurationName:n})),getCodeVerifierAsync:async()=>{let w=(await O(t)({type:"getCodeVerifier",data:null,configurationName:n})).codeVerifier;return w||(w=sessionStorage[`oidc.code_verifier.${n}`],console.warn("codeVerifier not found in service worker, using sessionStorage")),w},setCodeVerifierAsync:async y=>(sessionStorage[`oidc.code_verifier.${n}`]=y,O(t)({type:"setCodeVerifier",data:{codeVerifier:y},configurationName:n})),setDemonstratingProofOfPossessionNonce:async y=>{await O(t)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:y},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await O(t)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async y=>{const w=JSON.stringify(y);await O(t)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:w},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const y=await O(t)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return y.demonstratingProofOfPossessionJwkJson?JSON.parse(y.demonstratingProofOfPossessionJwkJson):null}}},V={},Ue=(e,n=window.sessionStorage,s)=>{if(!V[e]&&n){const o=n.getItem(e);o&&(V[e]=JSON.parse(o))}const t=1e3*s;return V[e]&&V[e].timestamp+t>Date.now()?V[e].result:null},Fe=(e,n,s=window.sessionStorage)=>{const t=Date.now();V[e]={result:n,timestamp:t},s&&s.setItem(e,JSON.stringify({result:n,timestamp:t}))};function me(e){return new TextEncoder().encode(e)}function pe(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Ve(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(s,t){return String.fromCharCode(parseInt(t,16))})}const ne=e=>{let n="";return e.forEach(function(s){n+=String.fromCharCode(s)}),pe(n)};function we(e){return pe(Ve(e))}const Me={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"},Je={sign:e=>async(n,s,t,o,i="dpop+jwt")=>{switch(n=Object.assign({},n),s.typ=i,s.alg=o.jwtHeaderAlgorithm,s.alg){case"ES256":s.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":s.jwk={kty:n.kty,n:n.n,e:n.e,kid:s.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const r={protected:we(JSON.stringify(s)),payload:we(JSON.stringify(t))},l=o.importKeyAlgorithm,a=!0,d=["sign"],_=await e.crypto.subtle.importKey("jwk",n,l,a,d),c=me(`${r.protected}.${r.payload}`),u=o.signAlgorithm,f=await e.crypto.subtle.sign(u,_,c);return r.signature=ne(new Uint8Array(f)),`${r.protected}.${r.payload}.${r.signature}`}},Be={generate:e=>async n=>{const s=n,t=!0,o=["sign","verify"],i=await e.crypto.subtle.generateKey(s,t,o);return await e.crypto.subtle.exportKey("jwk",i.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}},He={thumbprint:e=>async(n,s)=>{let t;switch(n.kty){case"EC":t='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":t='{"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(s,me(t));return ne(new Uint8Array(o))}},je=e=>async n=>await Be.generate(e)(n),Ae=e=>n=>async(s,t="POST",o,i={})=>{const r={jti:btoa(qe()),htm:t,htu:o,iat:Math.round(Date.now()/1e3),...i},l=await He.thumbprint(e)(s,n.digestAlgorithm);return await Je.sign(e)(s,{kid:l},r,n)},qe=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let s=0,t="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(s=Math.random()*16|0),e[o]==="x"?t+=n[s]:e[o]==="y"?(s&=3,s|=8,t+=n[s]):t+=e[o];return t},Se=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Ge=e=>{const n=[];for(let s=0;s<e.byteLength;s+=1){const t=e[s]%se.length;n.push(se[t])}return n.join("")},te=e=>{const n=new Uint8Array(e),{hasCrypto:s}=Se();if(s)window.crypto.getRandomValues(n);else for(let t=0;t<e;t+=1)n[t]=Math.random()*se.length|0;return Ge(n)};function Ye(e){const n=new ArrayBuffer(e.length),s=new Uint8Array(n);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s}function Te(e){return new Promise((n,s)=>{crypto.subtle.digest("SHA-256",Ye(e)).then(t=>n(ne(new Uint8Array(t))),t=>s(t))})}const Xe=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Se();return n?Te(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},ze=60*60,Qe=e=>async(n,s=ze,t=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,l=Ue(r,t,s);if(l)return new ae(l);const a=await B(e)(i,{},o);if(a.status!==200)return null;const d=await a.json();return Fe(r,d,t),new ae(d)},B=e=>async(n,s={},t=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),t),i=await e(n,{...s,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await B(e)(n,s,t,o+1);throw r}else throw console.error(r.message),r}return i},oe={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,s,t=oe.refresh_token,o,i={},r=1e4)=>{const l={token:s,token_type_hint:t,client_id:o};for(const[c,u]of Object.entries(i))l[c]===void 0&&(l[c]=u);const a=[];for(const c in l){const u=encodeURIComponent(c),f=encodeURIComponent(l[c]);a.push(`${u}=${f}`)}const d=a.join("&");return(await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:d},r)).status!==200?{success:!1}:{success:!0}},Ze=e=>async(n,s,t,o,i={},r,l=1e4)=>{for(const[f,g]of Object.entries(t))s[f]===void 0&&(s[f]=g);const a=[];for(const f in s){const g=encodeURIComponent(f),p=encodeURIComponent(s[f]);a.push(`${g}=${p}`)}const d=a.join("&"),_=await B(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:d},l);if(_.status!==200)return{success:!1,status:_.status,demonstratingProofOfPossessionNonce:null};const c=await _.json();let u=null;return _.headers.has(z)&&(u=_.headers.get(z)),{success:!0,status:_.status,data:ee(c,o,r),demonstratingProofOfPossessionNonce:u}},en=(e,n)=>async(s,t)=>{t=t?{...t}:{};const o=te(128),i=await Xe(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(t.state),t.code_challenge=i,t.code_challenge_method="S256";let r="";if(t)for(const[l,a]of Object.entries(t))r===""?r+="?":r+="&",r+=`${l}=${encodeURIComponent(a)}`;n.open(`${s}${r}`)},z="DPoP-Nonce",nn=e=>async(n,s,t,o,i=1e4)=>{s=s?{...s}:{},s.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const c in s){const u=encodeURIComponent(c),f=encodeURIComponent(s[c]);r.push(`${u}=${f}`)}const l=r.join("&"),a=await B(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...t},body:l},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let d=null;a.headers.has(z)&&(d=a.headers.get(z));const _=await a.json();return{success:!0,data:{state:s.state,tokens:ee(_,null,o),demonstratingProofOfPossessionNonce:d}}};async function be(e,n,s,t=null){const o=a=>{e.tokens=a},{tokens:i,status:r}=await Q(e)(o,0,n,s,t);return await C(e.configuration,e.configurationName)||await I(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?i:(await e.destroyAsync(r),null)}async function Ee(e,n=!1,s=null,t=null){const o=e.configuration,i=`${o.client_id}_${e.configurationName}_${o.authority}`;let r;const l=await C(e.configuration,e.configurationName);if((o==null?void 0:o.storage)===(window==null?void 0:window.sessionStorage)&&!l||!navigator.locks)r=await be(e,n,s,t);else{let a="retry";for(;a==="retry";)a=await navigator.locks.request(i,{ifAvailable:!0},async d=>d?await be(e,n,s,t):(e.publishEvent(N.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),"retry"));r=a}return r?(e.timeoutId&&(e.timeoutId=H(e,e.tokens.expiresAt,s,t)),e.tokens):null}const H=(e,n,s=null,t=null)=>{const o=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&F.clearTimeout(e.timeoutId),F.setTimeout(async()=>{const r={timeLeft:J(o,n)};e.publishEvent(N.eventNames.token_timer,r),await Ee(e,!1,s,t)},1e3)},D={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"},sn=e=>async(n,s,t,o=!1)=>{const i={nonce:null};if(!t)return{tokens:null,status:"NOT_CONNECTED",nonce:i};let r=i;const l=await e.initAsync(n.authority,n.authority_configuration),a=await C(n,s);if(a){const{status:c,tokens:u}=await a.initAsync(l,"syncTokensAsync",n);if(c==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};if(c==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(!c||!u)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:i};if(u.issuedAt!==t.issuedAt){const g=J(n.refresh_time_before_tokens_expiration_in_second,u.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",p=await a.getNonceAsync();return{tokens:u,status:g,nonce:p}}r=await a.getNonceAsync()}else{const c=I(s,n.storage??sessionStorage),u=await c.initAsync();let{tokens:f}=u;const{status:g}=u;if(f&&(f=Z(f,e.tokens,n.token_renew_mode)),f){if(g==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(f.issuedAt!==t.issuedAt){const k=J(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",E=await c.getNonceAsync();return{tokens:f,status:k,nonce:E}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};r=await c.getNonceAsync()}const _=J(n.refresh_time_before_tokens_expiration_in_second,t.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:t,status:"FORCE_REFRESH",nonce:r}:{tokens:t,status:_,nonce:r}},Q=e=>async(n,s=0,t=!1,o=null,i=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let r=6;for(;!navigator.onLine&&r>0;)await X({milliseconds:1e3}),r--,e.publishEvent(m.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const l=s+1;o||(o={});const a=e.configuration,d=(c,u=null,f=null)=>ie(e.configurationName,e.configuration,e.publishEvent.bind(e))(c,u,f),_=async()=>{try{let c;const u=await C(a,e.configurationName);u?c=u.getLoginParams():c=I(e.configurationName,a.storage).getLoginParams();const f=await d({...c.extras,...o,prompt:"none",scope:i});return f?f.error?(n(null),e.publishEvent(m.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(n(f.tokens),e.publishEvent(N.eventNames.token_renewed,{}),{tokens:f.tokens,status:"LOGGED"}):(n(null),e.publishEvent(m.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(c){return console.error(c),e.publishEvent(m.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:c.message}),await Q(e)(n,l,t,o,i)}};try{const{status:c,tokens:u,nonce:f}=await sn(e)(a,e.configurationName,e.tokens,t);switch(c){case D.SESSION_LOST:return n(null),e.publishEvent(m.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case D.NOT_CONNECTED:return n(null),{tokens:null,status:null};case D.TOKENS_VALID:return n(u),{tokens:u,status:"LOGGED_IN"};case D.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(u),e.publishEvent(N.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:u,status:"LOGGED_IN"};case D.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(m.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case D.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==U.AutomaticOnlyWhenFetchExecuted&&D.FORCE_REFRESH!==c?(e.publishEvent(m.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(m.refreshTokensAsync_begin,{tryNumber:s}),await _());default:{if(a.token_automatic_renew_mode==U.AutomaticOnlyWhenFetchExecuted&&D.FORCE_REFRESH!==c)return e.publishEvent(m.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(m.refreshTokensAsync_begin,{refreshToken:u.refreshToken,status:c,tryNumber:s}),!u.refreshToken)return await _();const g=a.client_id,p=a.redirect_uri,k=a.authority,b={...a.token_request_extras?a.token_request_extras:{}};for(const[S,h]of Object.entries(o))S.endsWith(":token_request")&&(b[S.replace(":token_request","")]=h);return await(async()=>{const S={client_id:g,redirect_uri:p,grant_type:"refresh_token",refresh_token:u.refreshToken},h=await e.initAsync(k,a.authority_configuration),x=document.hidden?1e4:3e4*10,y=h.tokenEndpoint,w={};a.demonstrating_proof_of_possession&&(w.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(u.accessToken,y,"POST"));const T=await Ze(e.getFetch())(y,S,b,u,w,a.token_renew_mode,x);if(T.success){const{isValid:$,reason:v}=de(T.data,f.nonce,h);if(!$)return n(null),e.publishEvent(m.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${v}`}),{tokens:null,status:"SESSION_LOST"};if(n(T.data),T.demonstratingProofOfPossessionNonce){const W=await C(a,e.configurationName);W?await W.setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce):await I(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(T.demonstratingProofOfPossessionNonce)}return e.publishEvent(m.refreshTokensAsync_end,{success:T.success}),e.publishEvent(N.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:T.data,status:"LOGGED_IN"}}else return e.publishEvent(m.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:T}),T.status>=400&&T.status<500?(n(null),e.publishEvent(m.refreshTokensAsync_error,{message:`session lost: ${T.status}`}),{tokens:null,status:"SESSION_LOST"}):await Q(e)(n,l,t,o,i)})()}}}catch(c){return console.error(c),e.publishEvent(m.refreshTokensAsync_silent_error,{message:"exception",exception:c.message}),new Promise((u,f)=>{setTimeout(()=>{Q(e)(n,l,t,o,i).then(u).catch(f)},1e3)})}},ie=(e,n,s)=>(t=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{s(m.silentLoginAsync_begin,{});let r="";if(o&&(t==null&&(t={}),t.state=o),i!=null&&(t==null&&(t={}),t.scope=i),t!=null)for(const[c,u]of Object.entries(t))r===""?r=`?${encodeURIComponent(c)}=${encodeURIComponent(u)}`:r+=`&${encodeURIComponent(c)}=${encodeURIComponent(u)}`;const l=n.silent_login_uri+r,a=l.indexOf("/",l.indexOf("//")+2),d=l.substring(0,a),_=document.createElement("iframe");return _.width="0px",_.height="0px",_.id=`${e}_oidc_iframe`,_.setAttribute("src",l),document.body.appendChild(_),new Promise((c,u)=>{let f=!1;const g=()=>{window.removeEventListener("message",p),_.remove(),f=!0},p=k=>{if(k.origin===d&&k.source===_.contentWindow){const E=`${e}_oidc_tokens:`,b=`${e}_oidc_error:`,A=`${e}_oidc_exception:`,S=k.data;if(S&&typeof S=="string"&&!f){if(S.startsWith(E)){const h=JSON.parse(k.data.replace(E,""));s(m.silentLoginAsync_end,{}),c(h),g()}else if(S.startsWith(b)){const h=JSON.parse(k.data.replace(b,""));s(m.silentLoginAsync_error,h),c({error:"oidc_"+h.error,tokens:null,sessionState:null}),g()}else if(S.startsWith(A)){const h=JSON.parse(k.data.replace(A,""));s(m.silentLoginAsync_error,h),u(new Error(h.error)),g()}}}};try{window.addEventListener("message",p);const k=n.silent_login_timeout;setTimeout(()=>{f||(g(),s(m.silentLoginAsync_error,{reason:"timeout"}),u(new Error("timeout")))},k)}catch(k){g(),s(m.silentLoginAsync_error,k),u(k)}})}catch(r){throw s(m.silentLoginAsync_error,r),r}},tn=(e,n,s,t,o)=>(i=null,r=void 0)=>{i={...i};const l=(d,_,c)=>ie(n,s,t.bind(o))(d,_,c);return(async()=>{o.timeoutId&&F.clearTimeout(o.timeoutId);let d;i&&"state"in i&&(d=i.state,delete i.state);try{const _=s.extras?{...s.extras,...i}:i,c=await l({..._,prompt:"none"},d,r);if(c)return o.tokens=c.tokens,t(m.token_acquired,{}),o.timeoutId=H(o,o.tokens.expiresAt,i,r),{}}catch(_){return _}})()},on=(e,n,s)=>(t,o,i,r=!1)=>{const l=(a,d=void 0,_=void 0)=>ie(e.configurationName,s,e.publishEvent.bind(e))(a,d,_);return new Promise((a,d)=>{if(s.silent_login_uri&&s.silent_redirect_uri&&s.monitor_session&&t&&i&&!r){const _=()=>{e.checkSessionIFrame.stop();const c=e.tokens;if(c===null)return;const u=c.idToken,f=c.idTokenPayload;return l({prompt:"none",id_token_hint:u,scope:s.scope||"openid"}).then(g=>{if(g.error)throw new Error(g.error);const p=g.tokens.idTokenPayload;if(f.sub===p.sub){const k=g.sessionState;e.checkSessionIFrame.start(g.sessionState),f.sid===p.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",k):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",k)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",p.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[,p]of Object.entries(n))await p.logoutOtherTabAsync(s.client_id,f.sub)})};e.checkSessionIFrame=new Ne(_,o,t),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),a(e.checkSessionIFrame)}).catch(c=>{d(c)})}else a(null)})},rn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),an=e=>{const n=e.appVersion,s=e.userAgent,t="-";let o=t;const i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const l in i){const a=i[l];if(a.r.test(s)){o=a.s;break}}let r=t;switch(/Windows/.test(o)&&(r=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":r=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];break;case"iOS":{const l=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);l!=null&&l.length>2&&(r=l[1]+"."+l[2]+"."+(parseInt(l[3])|0));break}}return{os:o,osVersion:r}};function cn(){const e=navigator.userAgent;let n,s=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(s[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(s[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let t=n[1];if(!t){const o=e.split(n[0]+"/");o.length>1&&(t=o[1])}return{name:"opera",version:t}}return s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&s.splice(1,1,n[1]),{name:s[0].toLowerCase(),version:s[1]}}const ln=()=>{const{name:e,version:n}=cn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const s=an(navigator);return!rn(s)},un=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(m.tryKeepExistingSessionAsync_begin,{});try{const s=e.configuration,t=await e.initAsync(s.authority,s.authority_configuration);if(n=await C(s,e.configurationName),n){const{tokens:o}=await n.initAsync(t,"tryKeepExistingSessionAsync",s);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=H(e,e.tokens.expiresAt,i.extras);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,r),s.preload_user_info&&await e.userInfoAsync(),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{s.service_worker_relative_url&&e.publishEvent(m.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=I(e.configurationName,s.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=Z(i,null,s.token_renew_mode);const r=o.getLoginParams();e.timeoutId=H(e,e.tokens.expiresAt,r.extras);const l=await o.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,l),s.preload_user_info&&await e.userInfoAsync(),e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(m.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(s){return console.error(s),n&&await n.clearAsync(),e.publishEvent(m.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Oe=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let s=n[6],t=n[7];if(t){const o=t.split("?");o.length===2&&(t=o[0],s=o[1])}return s.startsWith("?")&&(s=s.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:s,hash:t}},_n=e=>{const n=Oe(e);let{path:s}=n;s.endsWith("/")&&(s=s.slice(0,-1));let{hash:t}=n;return t==="#_=_"&&(t=""),t&&(s+=t),s},j=e=>{const n=Oe(e),{search:s}=n;return fn(s)},fn=e=>{const n={};let s,t,o;const i=e.split("&");for(t=0,o=i.length;t<o;t++)s=i[t].split("="),n[decodeURIComponent(s[0])]=decodeURIComponent(s[1]);return n},dn=(e,n,s,t,o)=>(i=void 0,r=null,l=!1,a=void 0)=>{const d=r;return r={...r},(async()=>{const c=i||o.getPath();if("state"in r||(r.state=te(16)),s(m.loginAsync_begin,{}),r)for(const u of Object.keys(r))u.endsWith(":token_request")&&delete r[u];try{const u=l?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const f=n.extras?{...n.extras,...r}:r;f.nonce||(f.nonce=te(12));const g={nonce:f.nonce},p=await C(n,e),k=await t(n.authority,n.authority_configuration);let E;if(p)p.setLoginParams({callbackPath:c,extras:d}),await p.initAsync(k,"loginAsync",n),await p.setNonceAsync(g),p.startKeepAliveServiceWorker(),E=p;else{const A=I(e,n.storage??sessionStorage);A.setLoginParams({callbackPath:c,extras:d}),await A.setNonceAsync(g),E=A}const b={client_id:n.client_id,redirect_uri:u,scope:a,response_type:"code",...f};await en(E,o)(k.authorizationEndpoint,b)}catch(u){throw s(m.loginAsync_error,u),u}})()},hn=e=>async(n=!1)=>{try{e.publishEvent(m.loginCallbackAsync_begin,{});const s=e.configuration,t=s.client_id,o=n?s.silent_redirect_uri:s.redirect_uri,i=s.authority,r=s.token_request_timeout,l=await e.initAsync(i,s.authority_configuration),a=e.location.getCurrentHref(),_=j(a).session_state,c=await C(s,e.configurationName);let u,f,g,p;if(c)await c.initAsync(l,"loginCallbackAsync",s),await c.setSessionStateAsync(_),f=await c.getNonceAsync(),g=c.getLoginParams(),p=await c.getStateAsync(),c.startKeepAliveServiceWorker(),u=c;else{const v=I(e.configurationName,s.storage??sessionStorage);await v.setSessionStateAsync(_),f=await v.getNonceAsync(),g=v.getLoginParams(),p=await v.getStateAsync(),u=v}const k=j(a);if(k.error||k.error_description)throw new Error(`Error from OIDC server: ${k.error} - ${k.error_description}`);if(k.iss&&k.iss!==l.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${l.issuer}, received: ${k.iss})`);if(k.state&&k.state!==p)throw new Error(`State not valid (expected: ${p}, received: ${k.state})`);const E={code:k.code,grant_type:"authorization_code",client_id:s.client_id,redirect_uri:o},b={};if(s.token_request_extras)for(const[v,W]of Object.entries(s.token_request_extras))b[v]=W;if(g!=null&&g.extras)for(const[v,W]of Object.entries(g.extras))v.endsWith(":token_request")&&(b[v.replace(":token_request","")]=W);const A=l.tokenEndpoint,S={};if(s.demonstrating_proof_of_possession)if(c)S.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const v=await je(window)(s.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await I(e.configurationName,s.storage).setDemonstratingProofOfPossessionJwkAsync(v),S.DPoP=await Ae(window)(s.demonstrating_proof_of_possession_configuration)(v,"POST",A)}const h=await nn(u)(A,{...E,...b},S,e.configuration.token_renew_mode,r);if(!h.success)throw new Error("Token request failed");let x;const y=h.data.tokens,w=h.data.demonstratingProofOfPossessionNonce;if(h.data.state!==b.state)throw new Error("state is not valid");const{isValid:T,reason:$}=de(y,f.nonce,l);if(!T)throw new Error(`Tokens are not OpenID valid, reason: ${$}`);if(c){if(y.refreshToken&&!y.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(w&&(y!=null&&y.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(c)await c.initAsync(l,"syncTokensAsync",s),x=c.getLoginParams(),w&&await c.setDemonstratingProofOfPossessionNonce(w);else{const v=I(e.configurationName,s.storage);x=v.getLoginParams(),w&&await v.setDemonstratingProofOfPossessionNonce(w)}return await e.startCheckSessionAsync(l.checkSessionIframe,t,_,n),e.publishEvent(m.loginCallbackAsync_end,{}),{tokens:y,state:"request.state",callbackPath:x.callbackPath}}catch(s){throw console.error(s),e.publishEvent(m.loginCallbackAsync_error,s),s}},Pe={access_token:"access_token",refresh_token:"refresh_token"},re=(e,n)=>{const s={};if(e){for(const[t,o]of Object.entries(e))if(t.endsWith(n)){const i=t.replace(n,"");s[i]=o}return s}return s},yn=e=>{const n={};if(e){for(const[s,t]of Object.entries(e))s.includes(":")||(n[s]=t);return n}return n},gn=e=>async n=>{F.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const s=await C(e.configuration,e.configurationName);s?await s.clearAsync(n):await I(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},kn=(e,n,s,t,o)=>async(i=void 0,r=null)=>{var E,b;const l=e.configuration,a=await e.initAsync(l.authority,l.authority_configuration);i&&typeof i!="string"&&(i=void 0,t.warn("callbackPathOrUrl path is not a string"));const d=i??o.getPath();let _=!1;i&&(_=i.includes("https://")||i.includes("http://"));const c=_?i:o.getOrigin()+d,u=e.tokens?e.tokens.idToken:"";try{const A=a.revocationEndpoint;if(A){const S=[],h=e.tokens?e.tokens.accessToken:null;if(h&&l.logout_tokens_to_invalidate.includes(Pe.access_token)){const y=re(r,":revoke_access_token"),w=ve(s)(A,h,oe.access_token,l.client_id,y);S.push(w)}const x=e.tokens?e.tokens.refreshToken:null;if(x&&l.logout_tokens_to_invalidate.includes(Pe.refresh_token)){const y=re(r,":revoke_refresh_token"),w=ve(s)(A,x,oe.refresh_token,l.client_id,y);S.push(w)}S.length>0&&await Promise.all(S)}}catch(A){t.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),t.warn(A)}const f=((b=(E=e.tokens)==null?void 0:E.idTokenPayload)==null?void 0:b.sub)??null;await e.destroyAsync("LOGGED_OUT");for(const[,A]of Object.entries(n))A!==e?await e.logoutSameTabAsync(e.configuration.client_id,f):e.publishEvent(m.logout_from_same_tab,{});const g=re(r,":oidc");if(g&&g.no_reload==="true")return;const k=yn(r);if(a.endSessionEndpoint){"id_token_hint"in k||(k.id_token_hint=u),!("post_logout_redirect_uri"in k)&&i!==null&&(k.post_logout_redirect_uri=c);let A="";for(const[S,h]of Object.entries(k))h!=null&&(A===""?A+="?":A+="&",A+=`${S}=${encodeURIComponent(h)}`);o.open(`${a.endSessionEndpoint}${A}`)}else o.reload()},Ie=(e,n,s=!1)=>async(...t)=>{var f;const[o,i,...r]=t,l=i?{...i}:{method:"GET"};let a=new Headers;l.headers&&(a=l.headers instanceof Headers?l.headers:new Headers(l.headers));const d={getTokens:()=>n.tokens,configuration:{token_automatic_renew_mode:n.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:n.configuration.refresh_time_before_tokens_expiration_in_second},renewTokensAsync:n.renewTokensAsync.bind(n)},_=await fe(d),c=(f=_==null?void 0:_.tokens)==null?void 0:f.accessToken;if(a.has("Accept")||a.set("Accept","application/json"),c){if(n.configuration.demonstrating_proof_of_possession&&s){const g=await n.generateDemonstrationOfProofOfPossessionAsync(c,o.toString(),l.method);a.set("Authorization",`DPoP ${c}`),a.set("DPoP",g)}else a.set("Authorization",`Bearer ${c}`);l.credentials||(l.credentials="same-origin")}const u={...l,headers:a};return await e(o,u,...r)},mn=e=>async(n=!1,s=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const t=e.configuration,i=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,l=await(async()=>{const d=await Ie(fetch,e,s)(i);return d.status!==200?null:d.json()})();return e.userInfo=l,l},Ce=()=>fetch;class ae{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const R={},pn=(e,n=new L)=>(s,t="default")=>(R[t]||(R[t]=new N(s,t,e,n)),R[t]),wn=async e=>{const{parsedTokens:n,callbackPath:s}=await e.loginCallbackAsync();return e.timeoutId=H(e,n.expiresAt),{callbackPath:s}},An=e=>Math.floor(Math.random()*e),q=class q{constructor(n,s="default",t,o=new L){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let i=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(i=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let r=n.refresh_time_before_tokens_expiration_in_second??120;r>60&&(r=r-Math.floor(Math.random()*40)),this.location=o??new L;const l=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:i,token_automatic_renew_mode:n.token_automatic_renew_mode??U.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:r,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??G.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:l,service_worker_activate:n.service_worker_activate??ln,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Me,preload_user_info:n.preload_user_info??!1},this.getFetch=t??Ce,this.configurationName=s,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 s=An(9999999999999).toString();return this.events.push({id:s,func:n}),s}removeEventSubscription(n){const s=this.events.filter(t=>t.id!==n);this.events=s}publishEvent(n,s){this.events.forEach(t=>{t.func(n,s)})}static get(n="default"){const s=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(R,n)&&s)throw Error(`OIDC library does seem initialized.
|
|
2
|
-
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return R[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,s=
|
|
1
|
+
(function(I,W){typeof exports=="object"&&typeof module<"u"?W(exports):typeof define=="function"&&define.amd?define(["exports"],W):(I=typeof globalThis<"u"?globalThis:I||self,W(I["oidc-client"]={}))})(this,function(I){"use strict";class W{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 le=2e3,$=console;class Ne{constructor(n,s,t,o=le,i=!0){this._callback=n,this._client_id=s,this._url=t,this._interval=o||le,this._stopOnError=i;const r=t.indexOf("/",t.indexOf("//")+2);this._frame_origin=t.substring(0,r),this._frame=window.document.createElement("iframe"),this._frame.style.visibility="hidden",this._frame.style.position="absolute",this._frame.style.display="none",this._frame.width=0,this._frame.height=0,this._frame.src=t}load(){return new Promise(n=>{this._frame.onload=()=>{n()},window.document.body.appendChild(this._frame),this._boundMessageEvent=this._message.bind(this),window.addEventListener("message",this._boundMessageEvent,!1)})}_message(n){n.origin===this._frame_origin&&n.source===this._frame.contentWindow&&(n.data==="error"?($.error("CheckSessionIFrame: error message from check session op iframe"),this._stopOnError&&this.stop()):n.data==="changed"?($.debug(n),$.debug("CheckSessionIFrame: changed message from check session op iframe"),this.stop(),this._callback()):$.debug("CheckSessionIFrame: "+n.data+" message from check session op iframe"))}start(n){$.debug("CheckSessionIFrame.start :"+n),this.stop();const s=()=>{this._frame.contentWindow.postMessage(this._client_id+" "+n,this._frame_origin)};s(),this._timer=window.setInterval(s,this._interval)}stop(){this._timer&&($.debug("CheckSessionIFrame.stop"),window.clearInterval(this._timer),this._timer=null)}}const k={service_worker_not_supported_by_browser:"service_worker_not_supported_by_browser",token_acquired:"token_acquired",logout_from_another_tab:"logout_from_another_tab",logout_from_same_tab:"logout_from_same_tab",token_renewed:"token_renewed",token_timer:"token_timer",loginAsync_begin:"loginAsync_begin",loginAsync_error:"loginAsync_error",loginCallbackAsync_begin:"loginCallbackAsync_begin",loginCallbackAsync_end:"loginCallbackAsync_end",loginCallbackAsync_error:"loginCallbackAsync_error",refreshTokensAsync_begin:"refreshTokensAsync_begin",refreshTokensAsync:"refreshTokensAsync",refreshTokensAsync_end:"refreshTokensAsync_end",refreshTokensAsync_error:"refreshTokensAsync_error",refreshTokensAsync_silent_error:"refreshTokensAsync_silent_error",tryKeepExistingSessionAsync_begin:"tryKeepExistingSessionAsync_begin",tryKeepExistingSessionAsync_end:"tryKeepExistingSessionAsync_end",tryKeepExistingSessionAsync_error:"tryKeepExistingSessionAsync_error",silentLoginAsync_begin:"silentLoginAsync_begin",silentLoginAsync:"silentLoginAsync",silentLoginAsync_end:"silentLoginAsync_end",silentLoginAsync_error:"silentLoginAsync_error",syncTokensAsync_begin:"syncTokensAsync_begin",syncTokensAsync_lock_not_available:"syncTokensAsync_lock_not_available",syncTokensAsync_end:"syncTokensAsync_end",syncTokensAsync_error:"syncTokensAsync_error",tokensInvalidAndWaitingActionsToRefresh:"tokensInvalidAndWaitingActionsToRefresh"},C=(e,n=sessionStorage)=>{const s=h=>(n[`oidc.${e}`]=JSON.stringify({tokens:null,status:h}),Promise.resolve()),t=async()=>{if(!n[`oidc.${e}`])return n[`oidc.${e}`]=JSON.stringify({tokens:null,status:null}),{tokens:null,status:null};const h=JSON.parse(n[`oidc.${e}`]);return Promise.resolve({tokens:h.tokens,status:h.status})},o=h=>{n[`oidc.${e}`]=JSON.stringify({tokens:h})},i=async h=>{n[`oidc.session_state.${e}`]=h},r=async()=>n[`oidc.session_state.${e}`],l=h=>{n[`oidc.nonce.${e}`]=h.nonce},a=h=>{n[`oidc.jwk.${e}`]=JSON.stringify(h)},u=()=>JSON.parse(n[`oidc.jwk.${e}`]),f=async()=>({nonce:n[`oidc.nonce.${e}`]}),c=async h=>{n[`oidc.dpop_nonce.${e}`]=h},_=()=>n[`oidc.dpop_nonce.${e}`],d=()=>n[`oidc.${e}`]?JSON.stringify({tokens:JSON.parse(n[`oidc.${e}`]).tokens}):null,g={};return{clearAsync:s,initAsync:t,setTokens:o,getTokens:d,setSessionStateAsync:i,getSessionStateAsync:r,setNonceAsync:l,getNonceAsync:f,setLoginParams:h=>{g[e]=h,n[`oidc.login.${e}`]=JSON.stringify(h)},getLoginParams:()=>{const h=n[`oidc.login.${e}`];return h?(g[e]||(g[e]=JSON.parse(h)),g[e]):(console.warn(`storage[oidc.login.${e}] is empty, you should have an bad OIDC or code configuration somewhere.`),null)},getStateAsync:async()=>n[`oidc.state.${e}`],setStateAsync:async h=>{n[`oidc.state.${e}`]=h},getCodeVerifierAsync:async()=>n[`oidc.code_verifier.${e}`],setCodeVerifierAsync:async h=>{n[`oidc.code_verifier.${e}`]=h},setDemonstratingProofOfPossessionNonce:c,getDemonstratingProofOfPossessionNonce:_,setDemonstratingProofOfPossessionJwkAsync:a,getDemonstratingProofOfPossessionJwkAsync:u}};var K=(e=>(e.AutomaticBeforeTokenExpiration="AutomaticBeforeTokensExpiration",e.AutomaticOnlyWhenFetchExecuted="AutomaticOnlyWhenFetchExecuted",e))(K||{});const xe=e=>decodeURIComponent(Array.prototype.map.call(atob(e),n=>"%"+("00"+n.charCodeAt(0).toString(16)).slice(-2)).join("")),We=e=>JSON.parse(xe(e.replaceAll(/-/g,"+").replaceAll(/_/g,"/"))),ue=e=>{try{return e&&Le(e,".")===2?We(e.split(".")[1]):null}catch(n){console.warn(n)}return null},Le=(e,n)=>e.split(n).length-1,q={access_token_or_id_token_invalid:"access_token_or_id_token_invalid",access_token_invalid:"access_token_invalid",id_token_invalid:"id_token_invalid"};function De(e,n,s){if(e.issuedAt){if(typeof e.issuedAt=="string")return parseInt(e.issuedAt,10)}else return n&&n.iat?n.iat:s&&s.iat?s.iat:new Date().getTime()/1e3;return e.issuedAt}const Z=(e,n=null,s)=>{if(!e)return null;let t;const o=typeof e.expiresIn=="string"?parseInt(e.expiresIn,10):e.expiresIn;e.accessTokenPayload!==void 0?t=e.accessTokenPayload:t=ue(e.accessToken);let i;n!=null&&"idToken"in n&&!("idToken"in e)?i=n.idToken:i=e.idToken;const r=e.idTokenPayload?e.idTokenPayload:ue(i),l=r&&r.exp?r.exp:Number.MAX_VALUE,a=t&&t.exp?t.exp:e.issuedAt+o;e.issuedAt=De(e,t,r);let u;e.expiresAt?u=e.expiresAt:s===q.access_token_invalid?u=a:s===q.id_token_invalid?u=l:u=l<a?l:a;const f={...e,idTokenPayload:r,accessTokenPayload:t,expiresAt:u,idToken:i};if(n!=null&&"refreshToken"in n&&!("refreshToken"in e)){const c=n.refreshToken;return{...f,refreshToken:c}}return f},ee=(e,n,s)=>{if(!e)return null;if(!e.issued_at){const o=new Date().getTime()/1e3;e.issued_at=o}const t={accessToken:e.access_token,expiresIn:e.expires_in,idToken:e.id_token,scope:e.scope,tokenType:e.token_type,issuedAt:e.issued_at};return"refresh_token"in e&&(t.refreshToken=e.refresh_token),e.accessTokenPayload!==void 0&&(t.accessTokenPayload=e.accessTokenPayload),e.idTokenPayload!==void 0&&(t.idTokenPayload=e.idTokenPayload),Z(t,n,s)},M=(e,n)=>{const s=new Date().getTime()/1e3,t=n-s;return Math.round(t-e)},_e=(e,n=0)=>e?M(n,e.expiresAt)>0:!1,fe=async(e,n=200,s=50)=>{let t=s;if(!e.getTokens())return null;for(;!_e(e.getTokens(),e.configuration.refresh_time_before_tokens_expiration_in_second)&&t>0;){if(e.configuration.token_automatic_renew_mode==K.AutomaticOnlyWhenFetchExecuted){await e.renewTokensAsync({});break}else await Y({milliseconds:n});t=t-1}return{isTokensValid:_e(e.getTokens()),tokens:e.getTokens(),numberWaited:t-s}},de=(e,n,s)=>{if(e.idTokenPayload){const t=e.idTokenPayload;if(s.issuer!==t.iss)return{isValid:!1,reason:`Issuer does not match (oidcServerConfiguration issuer) ${s.issuer} !== (idTokenPayload issuer) ${t.iss}`};const o=new Date().getTime()/1e3;if(t.exp&&t.exp<o)return{isValid:!1,reason:`Token expired (idTokenPayload exp) ${t.exp} < (currentTimeUnixSecond) ${o}`};const i=60*60*24*7;if(t.iat&&t.iat+i<o)return{isValid:!1,reason:`Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${t.iat+i} < (currentTimeUnixSecond) ${o}`};if(t.nonce&&t.nonce!==n)return{isValid:!1,reason:`Nonce does not match (idTokenPayload nonce) ${t.nonce} !== (nonce) ${n}`}}return{isValid:!0,reason:""}},U=function(){const e=typeof window>"u"?global:window;return{setTimeout:setTimeout.bind(e),clearTimeout:clearTimeout.bind(e),setInterval:setInterval.bind(e),clearInterval:clearInterval.bind(e)}}(),he="7.25.0";let ye=null,G;const Y=({milliseconds:e})=>new Promise(n=>U.setTimeout(n,e)),ge=(e="/")=>{try{G=new AbortController,fetch(`${e}OidcKeepAliveServiceWorker.json?minSleepSeconds=150`,{signal:G.signal}).catch(t=>{console.log(t)}),Y({milliseconds:150*1e3}).then(ge)}catch(n){console.log(n)}},ke=()=>{G&&G.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,s)=>{s(),await n.update();const t=await n.unregister();console.log(`Service worker unregistration ${t?"successful":"failed"}`),await Y({milliseconds:2e3}),e.reload()},Ke=e=>{const n=sessionStorage.getItem(`oidc.tabId.${e}`);if(n)return n;const s=globalThis.crypto.randomUUID();return sessionStorage.setItem(`oidc.tabId.${e}`,s),s},E=e=>n=>new Promise(function(s,t){const o=new MessageChannel;o.port1.onmessage=function(i){i!=null&&i.data.error?t(i.data.error):s(i.data),o.port1.close(),o.port2.close()},e.active.postMessage({...n,tabId:Ke(n.configurationName)},[o.port2])}),N=async(e,n)=>{var P;const s=e.service_worker_relative_url;if(typeof window>"u"||typeof navigator>"u"||!navigator.serviceWorker||!s||e.service_worker_activate()===!1)return null;let t=null;e.service_worker_register?t=await e.service_worker_register(s):(t=await navigator.serviceWorker.register(s),t.active&&t.waiting&&(console.log("Detected new service worker waiting, unregistering and reloading"),await((P=e.service_worker_update_require_callback)==null?void 0:P.call(e,t,ke))));try{await navigator.serviceWorker.ready,navigator.serviceWorker.controller||await E(t)({type:"claim"})}catch(y){return console.warn(`Failed init ServiceWorker ${y.toString()}`),null}const o=async y=>E(t)({type:"clear",data:{status:y},configurationName:n}),i=async(y,S,v)=>{var j;const T=await E(t)({type:"init",data:{oidcServerConfiguration:y,where:S,oidcConfiguration:{token_renew_mode:v.token_renew_mode,service_worker_convert_all_requests_to_cors:v.service_worker_convert_all_requests_to_cors}},configurationName:n}),L=T.version;return L!==he&&(console.warn(`Service worker ${L} version mismatch with js client version ${he}, unregistering and reloading`),await((j=v.service_worker_update_require_callback)==null?void 0:j.call(v,t,ke))),{tokens:ee(T.tokens,null,v.token_renew_mode),status:T.status}},r=(y="/")=>{ye==null&&(ye="not_null",ge(y))},l=y=>E(t)({type:"setSessionState",data:{sessionState:y},configurationName:n}),a=async()=>(await E(t)({type:"getSessionState",data:null,configurationName:n})).sessionState,u=y=>(sessionStorage[`oidc.nonce.${n}`]=y.nonce,E(t)({type:"setNonce",data:{nonce:y},configurationName:n})),f=async()=>{let S=(await E(t)({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}},c={};return{clearAsync:o,initAsync:i,startKeepAliveServiceWorker:()=>r(e.service_worker_keep_alive_path),isServiceWorkerProxyActiveAsync:()=>Re(e.service_worker_keep_alive_path),setSessionStateAsync:l,getSessionStateAsync:a,setNonceAsync:u,getNonceAsync:f,setLoginParams:y=>{c[n]=y,localStorage[`oidc.login.${n}`]=JSON.stringify(y)},getLoginParams:()=>{const y=localStorage[`oidc.login.${n}`];return c[n]||(c[n]=JSON.parse(y)),c[n]},getStateAsync:async()=>{let S=(await E(t)({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 y=>(sessionStorage[`oidc.state.${n}`]=y,E(t)({type:"setState",data:{state:y},configurationName:n})),getCodeVerifierAsync:async()=>{let S=(await E(t)({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 y=>(sessionStorage[`oidc.code_verifier.${n}`]=y,E(t)({type:"setCodeVerifier",data:{codeVerifier:y},configurationName:n})),setDemonstratingProofOfPossessionNonce:async y=>{await E(t)({type:"setDemonstratingProofOfPossessionNonce",data:{demonstratingProofOfPossessionNonce:y},configurationName:n})},getDemonstratingProofOfPossessionNonce:async()=>(await E(t)({type:"getDemonstratingProofOfPossessionNonce",data:null,configurationName:n})).demonstratingProofOfPossessionNonce,setDemonstratingProofOfPossessionJwkAsync:async y=>{const S=JSON.stringify(y);await E(t)({type:"setDemonstratingProofOfPossessionJwk",data:{demonstratingProofOfPossessionJwkJson:S},configurationName:n})},getDemonstratingProofOfPossessionJwkAsync:async()=>{const y=await E(t)({type:"getDemonstratingProofOfPossessionJwk",data:null,configurationName:n});return y.demonstratingProofOfPossessionJwkJson?JSON.parse(y.demonstratingProofOfPossessionJwkJson):null}}},F={},Ue=(e,n=window.sessionStorage,s)=>{if(!F[e]&&n){const o=n.getItem(e);o&&(F[e]=JSON.parse(o))}const t=1e3*s;return F[e]&&F[e].timestamp+t>Date.now()?F[e].result:null},Fe=(e,n,s=window.sessionStorage)=>{const t=Date.now();F[e]={result:n,timestamp:t},s&&s.setItem(e,JSON.stringify({result:n,timestamp:t}))};function me(e){return new TextEncoder().encode(e)}function pe(e){return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+/g,"")}function Ve(e){return encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(s,t){return String.fromCharCode(parseInt(t,16))})}const ne=e=>{let n="";return e.forEach(function(s){n+=String.fromCharCode(s)}),pe(n)};function we(e){return pe(Ve(e))}const Me={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"},Je={sign:e=>async(n,s,t,o,i="dpop+jwt")=>{switch(n=Object.assign({},n),s.typ=i,s.alg=o.jwtHeaderAlgorithm,s.alg){case"ES256":s.jwk={kty:n.kty,crv:n.crv,x:n.x,y:n.y};break;case"RS256":s.jwk={kty:n.kty,n:n.n,e:n.e,kid:s.kid};break;default:throw new Error("Unknown or not implemented JWS algorithm")}const r={protected:we(JSON.stringify(s)),payload:we(JSON.stringify(t))},l=o.importKeyAlgorithm,a=!0,u=["sign"],f=await e.crypto.subtle.importKey("jwk",n,l,a,u),c=me(`${r.protected}.${r.payload}`),_=o.signAlgorithm,d=await e.crypto.subtle.sign(_,f,c);return r.signature=ne(new Uint8Array(d)),`${r.protected}.${r.payload}.${r.signature}`}},Be={generate:e=>async n=>{const s=n,t=!0,o=["sign","verify"],i=await e.crypto.subtle.generateKey(s,t,o);return await e.crypto.subtle.exportKey("jwk",i.privateKey)},neuter:e=>{const n=Object.assign({},e);return delete n.d,n.key_ops=["verify"],n}},He={thumbprint:e=>async(n,s)=>{let t;switch(n.kty){case"EC":t='{"crv":"CRV","kty":"EC","x":"X","y":"Y"}'.replace("CRV",n.crv).replace("X",n.x).replace("Y",n.y);break;case"RSA":t='{"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(s,me(t));return ne(new Uint8Array(o))}},je=e=>async n=>await Be.generate(e)(n),Ae=e=>n=>async(s,t="POST",o,i={})=>{const r={jti:btoa(qe()),htm:t,htu:o,iat:Math.round(Date.now()/1e3),...i},l=await He.thumbprint(e)(s,n.digestAlgorithm);return await Je.sign(e)(s,{kid:l},r,n)},qe=()=>{const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef";let s=0,t="";for(let o=0;o<36;o++)e[o]!=="-"&&e[o]!=="4"&&(s=Math.random()*16|0),e[o]==="x"?t+=n[s]:e[o]==="y"?(s&=3,s|=8,t+=n[s]):t+=e[o];return t},Se=()=>{const e=typeof window<"u"&&!!window.crypto,n=e&&!!window.crypto.subtle;return{hasCrypto:e,hasSubtleCrypto:n}},se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",Ge=e=>{const n=[];for(let s=0;s<e.byteLength;s+=1){const t=e[s]%se.length;n.push(se[t])}return n.join("")},te=e=>{const n=new Uint8Array(e),{hasCrypto:s}=Se();if(s)window.crypto.getRandomValues(n);else for(let t=0;t<e;t+=1)n[t]=Math.random()*se.length|0;return Ge(n)};function Ye(e){const n=new ArrayBuffer(e.length),s=new Uint8Array(n);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s}function Te(e){return new Promise((n,s)=>{crypto.subtle.digest("SHA-256",Ye(e)).then(t=>n(ne(new Uint8Array(t))),t=>s(t))})}const Xe=e=>{if(e.length<43||e.length>128)return Promise.reject(new Error("Invalid code length."));const{hasSubtleCrypto:n}=Se();return n?Te(e):Promise.reject(new Error("window.crypto.subtle is unavailable."))},ze=60*60,Qe=e=>async(n,s=ze,t=window.sessionStorage,o=1e4)=>{const i=`${n}/.well-known/openid-configuration`,r=`oidc.server:${n}`,l=Ue(r,t,s);if(l)return new ae(l);const a=await J(e)(i,{},o);if(a.status!==200)return null;const u=await a.json();return Fe(r,u,t),new ae(u)},J=e=>async(n,s={},t=1e4,o=0)=>{let i;try{const r=new AbortController;setTimeout(()=>r.abort(),t),i=await e(n,{...s,signal:r.signal})}catch(r){if(r.name==="AbortError"||r.message==="Network request failed"){if(o<=1)return await J(e)(n,s,t,o+1);throw r}else throw console.error(r.message),r}return i},oe={refresh_token:"refresh_token",access_token:"access_token"},ve=e=>async(n,s,t=oe.refresh_token,o,i={},r=1e4)=>{const l={token:s,token_type_hint:t,client_id:o};for(const[c,_]of Object.entries(i))l[c]===void 0&&(l[c]=_);const a=[];for(const c in l){const _=encodeURIComponent(c),d=encodeURIComponent(l[c]);a.push(`${_}=${d}`)}const u=a.join("&");return(await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:u},r)).status!==200?{success:!1}:{success:!0}},Ze=e=>async(n,s,t,o,i={},r,l=1e4)=>{for(const[d,g]of Object.entries(t))s[d]===void 0&&(s[d]=g);const a=[];for(const d in s){const g=encodeURIComponent(d),p=encodeURIComponent(s[d]);a.push(`${g}=${p}`)}const u=a.join("&"),f=await J(e)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...i},body:u},l);if(f.status!==200)return{success:!1,status:f.status,demonstratingProofOfPossessionNonce:null};const c=await f.json();let _=null;return f.headers.has(X)&&(_=f.headers.get(X)),{success:!0,status:f.status,data:ee(c,o,r),demonstratingProofOfPossessionNonce:_}},en=(e,n)=>async(s,t)=>{t=t?{...t}:{};const o=te(128),i=await Xe(o);await e.setCodeVerifierAsync(o),await e.setStateAsync(t.state),t.code_challenge=i,t.code_challenge_method="S256";let r="";if(t)for(const[l,a]of Object.entries(t))r===""?r+="?":r+="&",r+=`${l}=${encodeURIComponent(a)}`;n.open(`${s}${r}`)},X="DPoP-Nonce",nn=e=>async(n,s,t,o,i=1e4)=>{s=s?{...s}:{},s.code_verifier=await e.getCodeVerifierAsync();const r=[];for(const c in s){const _=encodeURIComponent(c),d=encodeURIComponent(s[c]);r.push(`${_}=${d}`)}const l=r.join("&"),a=await J(fetch)(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8",...t},body:l},i);if(await Promise.all([e.setCodeVerifierAsync(null),e.setStateAsync(null)]),a.status!==200)return{success:!1,status:a.status};let u=null;a.headers.has(X)&&(u=a.headers.get(X));const f=await a.json();return{success:!0,data:{state:s.state,tokens:ee(f,null,o),demonstratingProofOfPossessionNonce:u}}};async function be(e,n,s,t=null){const o=a=>{e.tokens=a},{tokens:i,status:r}=await z(e)(o,0,n,s,t);return await N(e.configuration,e.configurationName)||await C(e.configurationName,e.configuration.storage).setTokens(e.tokens),e.tokens?i:(await e.destroyAsync(r),null)}async function Ee(e,n=!1,s=null,t=null){const o=e.configuration,i=`${o.client_id}_${e.configurationName}_${o.authority}`;let r;const l=await N(e.configuration,e.configurationName);if((o==null?void 0:o.storage)===(window==null?void 0:window.sessionStorage)&&!l||!navigator.locks)r=await be(e,n,s,t);else{let a="retry";for(;a==="retry";)a=await navigator.locks.request(i,{ifAvailable:!0},async u=>u?await be(e,n,s,t):(e.publishEvent(x.eventNames.syncTokensAsync_lock_not_available,{lock:"lock not available"}),"retry"));r=a}return r?(e.timeoutId&&(e.timeoutId=B(e,e.tokens.expiresAt,s,t)),e.tokens):null}const B=(e,n,s=null,t=null)=>{const o=e.configuration.refresh_time_before_tokens_expiration_in_second;return e.timeoutId&&U.clearTimeout(e.timeoutId),U.setTimeout(async()=>{const r={timeLeft:M(o,n)};e.publishEvent(x.eventNames.token_timer,r),await Ee(e,!1,s,t)},1e3)},D={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"},sn=e=>async(n,s,t,o=!1)=>{const i={nonce:null};if(!t)return{tokens:null,status:"NOT_CONNECTED",nonce:i};let r=i;const l=await e.initAsync(n.authority,n.authority_configuration),a=await N(n,s);if(a){const{status:c,tokens:_}=await a.initAsync(l,"syncTokensAsync",n);if(c==="LOGGED_OUT")return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};if(c==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(!c||!_)return{tokens:null,status:"REQUIRE_SYNC_TOKENS",nonce:i};if(_.issuedAt!==t.issuedAt){const g=M(n.refresh_time_before_tokens_expiration_in_second,_.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",p=await a.getNonceAsync();return{tokens:_,status:g,nonce:p}}r=await a.getNonceAsync()}else{const c=C(s,n.storage??sessionStorage),_=await c.initAsync();let{tokens:d}=_;const{status:g}=_;if(d&&(d=Z(d,e.tokens,n.token_renew_mode)),d){if(g==="SESSIONS_LOST")return{tokens:null,status:"SESSIONS_LOST",nonce:i};if(d.issuedAt!==t.issuedAt){const m=M(n.refresh_time_before_tokens_expiration_in_second,d.expiresAt)>0?"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID",b=await c.getNonceAsync();return{tokens:d,status:m,nonce:b}}}else return{tokens:null,status:"LOGOUT_FROM_ANOTHER_TAB",nonce:i};r=await c.getNonceAsync()}const f=M(n.refresh_time_before_tokens_expiration_in_second,t.expiresAt)>0?"TOKENS_VALID":"TOKENS_INVALID";return o?{tokens:t,status:"FORCE_REFRESH",nonce:r}:{tokens:t,status:f,nonce:r}},z=e=>async(n,s=0,t=!1,o=null,i=null)=>{if(!navigator.onLine&&document.hidden)return{tokens:e.tokens,status:"GIVE_UP"};let r=6;for(;!navigator.onLine&&r>0;)await Y({milliseconds:1e3}),r--,e.publishEvent(k.refreshTokensAsync,{message:`wait because navigator is offline try ${r}`});const l=s+1;o||(o={});const a=e.configuration,u=(c,_=null,d=null)=>ie(e.configurationName,e.configuration,e.publishEvent.bind(e))(c,_,d),f=async()=>{try{let c;const _=await N(a,e.configurationName);_?c=_.getLoginParams():c=C(e.configurationName,a.storage).getLoginParams();const d=await u({...c.extras,...o,prompt:"none",scope:i});return d?d.error?(n(null),e.publishEvent(k.refreshTokensAsync_error,{message:"refresh token silent"}),{tokens:null,status:"SESSION_LOST"}):(n(d.tokens),e.publishEvent(x.eventNames.token_renewed,{}),{tokens:d.tokens,status:"LOGGED"}):(n(null),e.publishEvent(k.refreshTokensAsync_error,{message:"refresh token silent not active"}),{tokens:null,status:"SESSION_LOST"})}catch(c){return console.error(c),e.publishEvent(k.refreshTokensAsync_silent_error,{message:"exceptionSilent",exception:c.message}),await z(e)(n,l,t,o,i)}};try{const{status:c,tokens:_,nonce:d}=await sn(e)(a,e.configurationName,e.tokens,t);switch(c){case D.SESSION_LOST:return n(null),e.publishEvent(k.refreshTokensAsync_error,{message:"refresh token session lost"}),{tokens:null,status:"SESSION_LOST"};case D.NOT_CONNECTED:return n(null),{tokens:null,status:null};case D.TOKENS_VALID:return n(_),{tokens:_,status:"LOGGED_IN"};case D.TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID:return n(_),e.publishEvent(x.eventNames.token_renewed,{reason:"TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID"}),{tokens:_,status:"LOGGED_IN"};case D.LOGOUT_FROM_ANOTHER_TAB:return n(null),e.publishEvent(k.logout_from_another_tab,{status:"session syncTokensAsync"}),{tokens:null,status:"LOGGED_OUT"};case D.REQUIRE_SYNC_TOKENS:return a.token_automatic_renew_mode==K.AutomaticOnlyWhenFetchExecuted&&D.FORCE_REFRESH!==c?(e.publishEvent(k.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"}):(e.publishEvent(k.refreshTokensAsync_begin,{tryNumber:s}),await f());default:{if(a.token_automatic_renew_mode==K.AutomaticOnlyWhenFetchExecuted&&D.FORCE_REFRESH!==c)return e.publishEvent(k.tokensInvalidAndWaitingActionsToRefresh,{}),{tokens:e.tokens,status:"GIVE_UP"};if(e.publishEvent(k.refreshTokensAsync_begin,{refreshToken:_.refreshToken,status:c,tryNumber:s}),!_.refreshToken)return await f();const g=a.client_id,p=a.redirect_uri,m=a.authority,O={...a.token_request_extras?a.token_request_extras:{}};for(const[A,h]of Object.entries(o))A.endsWith(":token_request")&&(O[A.replace(":token_request","")]=h);return await(async()=>{const A={client_id:g,redirect_uri:p,grant_type:"refresh_token",refresh_token:_.refreshToken},h=await e.initAsync(m,a.authority_configuration),P=document.hidden?1e4:3e4*10,y=h.tokenEndpoint,S={};a.demonstrating_proof_of_possession&&(S.DPoP=await e.generateDemonstrationOfProofOfPossessionAsync(_.accessToken,y,"POST"));const v=await Ze(e.getFetch())(y,A,O,_,S,a.token_renew_mode,P);if(v.success){const{isValid:T,reason:L}=de(v.data,d.nonce,h);if(!T)return n(null),e.publishEvent(k.refreshTokensAsync_error,{message:`refresh token return not valid tokens, reason: ${L}`}),{tokens:null,status:"SESSION_LOST"};if(n(v.data),v.demonstratingProofOfPossessionNonce){const j=await N(a,e.configurationName);j?await j.setDemonstratingProofOfPossessionNonce(v.demonstratingProofOfPossessionNonce):await C(e.configurationName,a.storage).setDemonstratingProofOfPossessionNonce(v.demonstratingProofOfPossessionNonce)}return e.publishEvent(k.refreshTokensAsync_end,{success:v.success}),e.publishEvent(x.eventNames.token_renewed,{reason:"REFRESH_TOKEN"}),{tokens:v.data,status:"LOGGED_IN"}}else return e.publishEvent(k.refreshTokensAsync_silent_error,{message:"bad request",tokenResponse:v}),v.status>=400&&v.status<500?(n(null),e.publishEvent(k.refreshTokensAsync_error,{message:`session lost: ${v.status}`}),{tokens:null,status:"SESSION_LOST"}):await z(e)(n,l,t,o,i)})()}}}catch(c){return console.error(c),e.publishEvent(k.refreshTokensAsync_silent_error,{message:"exception",exception:c.message}),new Promise((_,d)=>{setTimeout(()=>{z(e)(n,l,t,o,i).then(_).catch(d)},1e3)})}},ie=(e,n,s)=>(t=null,o=null,i=null)=>{if(!n.silent_redirect_uri||!n.silent_login_uri)return Promise.resolve(null);try{s(k.silentLoginAsync_begin,{});let r="";if(o&&(t==null&&(t={}),t.state=o),i!=null&&(t==null&&(t={}),t.scope=i),t!=null)for(const[c,_]of Object.entries(t))r===""?r=`?${encodeURIComponent(c)}=${encodeURIComponent(_)}`:r+=`&${encodeURIComponent(c)}=${encodeURIComponent(_)}`;const l=n.silent_login_uri+r,a=l.indexOf("/",l.indexOf("//")+2),u=l.substring(0,a),f=document.createElement("iframe");return f.width="0px",f.height="0px",f.id=`${e}_oidc_iframe`,f.setAttribute("src",l),document.body.appendChild(f),new Promise((c,_)=>{let d=!1;const g=()=>{window.removeEventListener("message",p),f.remove(),d=!0},p=m=>{if(m.origin===u&&m.source===f.contentWindow){const b=`${e}_oidc_tokens:`,O=`${e}_oidc_error:`,w=`${e}_oidc_exception:`,A=m.data;if(A&&typeof A=="string"&&!d){if(A.startsWith(b)){const h=JSON.parse(m.data.replace(b,""));s(k.silentLoginAsync_end,{}),c(h),g()}else if(A.startsWith(O)){const h=JSON.parse(m.data.replace(O,""));s(k.silentLoginAsync_error,h),c({error:"oidc_"+h.error,tokens:null,sessionState:null}),g()}else if(A.startsWith(w)){const h=JSON.parse(m.data.replace(w,""));s(k.silentLoginAsync_error,h),_(new Error(h.error)),g()}}}};try{window.addEventListener("message",p);const m=n.silent_login_timeout;setTimeout(()=>{d||(g(),s(k.silentLoginAsync_error,{reason:"timeout"}),_(new Error("timeout")))},m)}catch(m){g(),s(k.silentLoginAsync_error,m),_(m)}})}catch(r){throw s(k.silentLoginAsync_error,r),r}},tn=(e,n,s,t,o)=>(i=null,r=void 0)=>{i={...i};const l=(u,f,c)=>ie(n,s,t.bind(o))(u,f,c);return(async()=>{o.timeoutId&&U.clearTimeout(o.timeoutId);let u;i&&"state"in i&&(u=i.state,delete i.state);try{const f=s.extras?{...s.extras,...i}:i,c=await l({...f,prompt:"none"},u,r);if(c)return o.tokens=c.tokens,t(k.token_acquired,{}),o.timeoutId=B(o,o.tokens.expiresAt,i,r),{}}catch(f){return f}})()},on=(e,n,s)=>(t,o,i,r=!1)=>{const l=(a,u=void 0,f=void 0)=>ie(e.configurationName,s,e.publishEvent.bind(e))(a,u,f);return new Promise((a,u)=>{if(s.silent_login_uri&&s.silent_redirect_uri&&s.monitor_session&&t&&i&&!r){const f=()=>{e.checkSessionIFrame.stop();const c=e.tokens;if(c===null)return;const _=c.idToken,d=c.idTokenPayload;return l({prompt:"none",id_token_hint:_,scope:s.scope||"openid"}).then(g=>{if(g.error)throw new Error(g.error);const p=g.tokens.idTokenPayload;if(d.sub===p.sub){const m=g.sessionState;e.checkSessionIFrame.start(g.sessionState),d.sid===p.sid?console.debug("SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:",m):console.debug("SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:",m)}else console.debug("SessionMonitor._callback: Different subject signed into OP:",p.sub)}).catch(async g=>{console.warn("SessionMonitor._callback: Silent login failed, logging out other tabs:",g);for(const[,p]of Object.entries(n))await p.logoutOtherTabAsync(s.client_id,d.sub)})};e.checkSessionIFrame=new Ne(f,o,t),e.checkSessionIFrame.load().then(()=>{e.checkSessionIFrame.start(i),a(e.checkSessionIFrame)}).catch(c=>{u(c)})}else a(null)})},rn=e=>!!(e.os==="iOS"&&e.osVersion.startsWith("12")||e.os==="Mac OS X"&&e.osVersion.startsWith("10_15_6")),an=e=>{const n=e.appVersion,s=e.userAgent,t="-";let o=t;const i=[{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(const l in i){const a=i[l];if(a.r.test(s)){o=a.s;break}}let r=t;switch(/Windows/.test(o)&&(r=/Windows (.*)/.exec(o)[1],o="Windows"),o){case"Mac OS":case"Mac OS X":case"Android":r=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(s)[1];break;case"iOS":{const l=/OS (\d+)_(\d+)_?(\d+)?/.exec(n);l!=null&&l.length>2&&(r=l[1]+"."+l[2]+"."+(parseInt(l[3])|0));break}}return{os:o,osVersion:r}};function cn(){const e=navigator.userAgent;let n,s=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(s[1]))return n=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"ie",version:n[1]||""};if(s[1]==="Chrome"&&(n=e.match(/\bOPR|Edge\/(\d+)/),n!=null)){let t=n[1];if(!t){const o=e.split(n[0]+"/");o.length>1&&(t=o[1])}return{name:"opera",version:t}}return s=s[2]?[s[1],s[2]]:[navigator.appName,navigator.appVersion,"-?"],(n=e.match(/version\/(\d+)/i))!=null&&s.splice(1,1,n[1]),{name:s[0].toLowerCase(),version:s[1]}}const ln=()=>{const{name:e,version:n}=cn();if(e==="chrome"&&parseInt(n)<=70||e==="opera"&&(!n||parseInt(n.split(".")[0])<80)||e==="ie")return!1;const s=an(navigator);return!rn(s)},un=async e=>{let n;if(e.tokens!=null)return!1;e.publishEvent(k.tryKeepExistingSessionAsync_begin,{});try{const s=e.configuration,t=await e.initAsync(s.authority,s.authority_configuration);if(n=await N(s,e.configurationName),n){const{tokens:o}=await n.initAsync(t,"tryKeepExistingSessionAsync",s);if(o){n.startKeepAliveServiceWorker(),e.tokens=o;const i=n.getLoginParams(e.configurationName);e.timeoutId=B(e,e.tokens.expiresAt,i.extras,i.scope);const r=await n.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,r),s.preload_user_info&&await e.userInfoAsync(),e.publishEvent(k.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside ServiceWorker are valid"}),!0}e.publishEvent(k.tryKeepExistingSessionAsync_end,{success:!1,message:"no exiting session found"})}else{s.service_worker_relative_url&&e.publishEvent(k.service_worker_not_supported_by_browser,{message:"service worker is not supported by this browser"});const o=C(e.configurationName,s.storage??sessionStorage),{tokens:i}=await o.initAsync();if(i){e.tokens=Z(i,null,s.token_renew_mode);const r=o.getLoginParams();e.timeoutId=B(e,e.tokens.expiresAt,r.extras,r.scope);const l=await o.getSessionStateAsync();return await e.startCheckSessionAsync(t.check_session_iframe,s.client_id,l),s.preload_user_info&&await e.userInfoAsync(),e.publishEvent(k.tryKeepExistingSessionAsync_end,{success:!0,message:"tokens inside storage are valid"}),!0}}return e.publishEvent(k.tryKeepExistingSessionAsync_end,{success:!1,message:n?"service worker sessions not retrieved":"session storage sessions not retrieved"}),!1}catch(s){return console.error(s),n&&await n.clearAsync(),e.publishEvent(k.tryKeepExistingSessionAsync_error,"tokens inside ServiceWorker are invalid"),!1}},Oe=e=>{const n=e.match(/^([a-z][\w-]+\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);if(!n)throw new Error("Invalid URL");let s=n[6],t=n[7];if(t){const o=t.split("?");o.length===2&&(t=o[0],s=o[1])}return s.startsWith("?")&&(s=s.slice(1)),n&&{href:e,protocol:n[1],host:n[2],hostname:n[3],port:n[4],path:n[5],search:s,hash:t}},_n=e=>{const n=Oe(e);let{path:s}=n;s.endsWith("/")&&(s=s.slice(0,-1));let{hash:t}=n;return t==="#_=_"&&(t=""),t&&(s+=t),s},Q=e=>{const n=Oe(e),{search:s}=n;return fn(s)},fn=e=>{const n={};let s,t,o;const i=e.split("&");for(t=0,o=i.length;t<o;t++)s=i[t].split("="),n[decodeURIComponent(s[0])]=decodeURIComponent(s[1]);return n},dn=(e,n,s,t,o)=>(i=void 0,r=null,l=!1,a=void 0)=>{const u=r;return r={...r},(async()=>{const c=i||o.getPath();if("state"in r||(r.state=te(16)),s(k.loginAsync_begin,{}),r)for(const _ of Object.keys(r))_.endsWith(":token_request")&&delete r[_];try{const _=l?n.silent_redirect_uri:n.redirect_uri;a||(a=n.scope);const d=n.extras?{...n.extras,...r}:r;d.nonce||(d.nonce=te(12));const g={nonce:d.nonce},p=await N(n,e),m=await t(n.authority,n.authority_configuration);let b;if(p)p.setLoginParams({callbackPath:c,extras:u,scope:a}),await p.initAsync(m,"loginAsync",n),await p.setNonceAsync(g),p.startKeepAliveServiceWorker(),b=p;else{const w=C(e,n.storage??sessionStorage);w.setLoginParams({callbackPath:c,extras:u,scope:a}),await w.setNonceAsync(g),b=w}const O={client_id:n.client_id,redirect_uri:_,scope:a,response_type:"code",...d};await en(b,o)(m.authorizationEndpoint,O)}catch(_){throw s(k.loginAsync_error,_),_}})()},hn=e=>async(n=!1)=>{try{e.publishEvent(k.loginCallbackAsync_begin,{});const s=e.configuration,t=s.client_id,o=n?s.silent_redirect_uri:s.redirect_uri,i=s.authority,r=s.token_request_timeout,l=await e.initAsync(i,s.authority_configuration),a=e.location.getCurrentHref(),u=Q(a),f=u.session_state,c=await N(s,e.configurationName);let _,d,g,p;if(c)await c.initAsync(l,"loginCallbackAsync",s),await c.setSessionStateAsync(f),d=await c.getNonceAsync(),g=c.getLoginParams(),p=await c.getStateAsync(),c.startKeepAliveServiceWorker(),_=c;else{const T=C(e.configurationName,s.storage??sessionStorage);await T.setSessionStateAsync(f),d=await T.getNonceAsync(),g=T.getLoginParams(),p=await T.getStateAsync(),_=T}if(u.error||u.error_description)throw new Error(`Error from OIDC server: ${u.error} - ${u.error_description}`);if(u.iss&&u.iss!==l.issuer)throw console.error(),new Error(`Issuer not valid (expected: ${l.issuer}, received: ${u.iss})`);if(u.state&&u.state!==p)throw new Error(`State not valid (expected: ${p}, received: ${u.state})`);const m={code:u.code,grant_type:"authorization_code",client_id:s.client_id,redirect_uri:o},b={};if(s.token_request_extras)for(const[T,L]of Object.entries(s.token_request_extras))b[T]=L;if(g!=null&&g.extras)for(const[T,L]of Object.entries(g.extras))T.endsWith(":token_request")&&(b[T.replace(":token_request","")]=L);const O=l.tokenEndpoint,w={};if(s.demonstrating_proof_of_possession)if(c)w.DPoP=`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${e.configurationName}`;else{const T=await je(window)(s.demonstrating_proof_of_possession_configuration.generateKeyAlgorithm);await C(e.configurationName,s.storage).setDemonstratingProofOfPossessionJwkAsync(T),w.DPoP=await Ae(window)(s.demonstrating_proof_of_possession_configuration)(T,"POST",O)}const A=await nn(_)(O,{...m,...b},w,e.configuration.token_renew_mode,r);if(!A.success)throw new Error("Token request failed");let h;const P=A.data.tokens,y=A.data.demonstratingProofOfPossessionNonce;if(A.data.state!==b.state)throw new Error("state is not valid");const{isValid:S,reason:v}=de(P,d.nonce,l);if(!S)throw new Error(`Tokens are not OpenID valid, reason: ${v}`);if(c){if(P.refreshToken&&!P.refreshToken.includes("SECURED_BY_OIDC_SERVICE_WORKER"))throw new Error("Refresh token should be hidden by service worker");if(y&&(P!=null&&P.accessToken.includes("SECURED_BY_OIDC_SERVICE_WORKER")))throw new Error("Demonstration of proof of possession require Access token not hidden by service worker")}if(c)await c.initAsync(l,"syncTokensAsync",s),h=c.getLoginParams(),y&&await c.setDemonstratingProofOfPossessionNonce(y);else{const T=C(e.configurationName,s.storage);h=T.getLoginParams(),y&&await T.setDemonstratingProofOfPossessionNonce(y)}return await e.startCheckSessionAsync(l.checkSessionIframe,t,f,n),e.publishEvent(k.loginCallbackAsync_end,{}),{tokens:P,state:"request.state",callbackPath:h.callbackPath,scope:u.scope,extras:h.extras}}catch(s){throw console.error(s),e.publishEvent(k.loginCallbackAsync_error,s),s}},Pe={access_token:"access_token",refresh_token:"refresh_token"},re=(e,n)=>{const s={};if(e){for(const[t,o]of Object.entries(e))if(t.endsWith(n)){const i=t.replace(n,"");s[i]=o}return s}return s},yn=e=>{const n={};if(e){for(const[s,t]of Object.entries(e))s.includes(":")||(n[s]=t);return n}return n},gn=e=>async n=>{U.clearTimeout(e.timeoutId),e.timeoutId=null,e.checkSessionIFrame&&e.checkSessionIFrame.stop();const s=await N(e.configuration,e.configurationName);s?await s.clearAsync(n):await C(e.configurationName,e.configuration.storage).clearAsync(n),e.tokens=null,e.userInfo=null},kn=(e,n,s,t,o)=>async(i=void 0,r=null)=>{var b,O;const l=e.configuration,a=await e.initAsync(l.authority,l.authority_configuration);i&&typeof i!="string"&&(i=void 0,t.warn("callbackPathOrUrl path is not a string"));const u=i??o.getPath();let f=!1;i&&(f=i.includes("https://")||i.includes("http://"));const c=f?i:o.getOrigin()+u,_=e.tokens?e.tokens.idToken:"";try{const w=a.revocationEndpoint;if(w){const A=[],h=e.tokens?e.tokens.accessToken:null;if(h&&l.logout_tokens_to_invalidate.includes(Pe.access_token)){const y=re(r,":revoke_access_token"),S=ve(s)(w,h,oe.access_token,l.client_id,y);A.push(S)}const P=e.tokens?e.tokens.refreshToken:null;if(P&&l.logout_tokens_to_invalidate.includes(Pe.refresh_token)){const y=re(r,":revoke_refresh_token"),S=ve(s)(w,P,oe.refresh_token,l.client_id,y);A.push(S)}A.length>0&&await Promise.all(A)}}catch(w){t.warn("logoutAsync: error when revoking tokens, if the error persist, you ay configure property logout_tokens_to_invalidate from configuration to avoid this error"),t.warn(w)}const d=((O=(b=e.tokens)==null?void 0:b.idTokenPayload)==null?void 0:O.sub)??null;await e.destroyAsync("LOGGED_OUT");for(const[,w]of Object.entries(n))w!==e?await e.logoutSameTabAsync(e.configuration.client_id,d):e.publishEvent(k.logout_from_same_tab,{});const g=re(r,":oidc");if(g&&g.no_reload==="true")return;const m=yn(r);if(a.endSessionEndpoint){"id_token_hint"in m||(m.id_token_hint=_),!("post_logout_redirect_uri"in m)&&i!==null&&(m.post_logout_redirect_uri=c);let w="";for(const[A,h]of Object.entries(m))h!=null&&(w===""?w+="?":w+="&",w+=`${A}=${encodeURIComponent(h)}`);o.open(`${a.endSessionEndpoint}${w}`)}else o.reload()},Ie=(e,n,s=!1)=>async(...t)=>{var d;const[o,i,...r]=t,l=i?{...i}:{method:"GET"};let a=new Headers;l.headers&&(a=l.headers instanceof Headers?l.headers:new Headers(l.headers));const u={getTokens:()=>n.tokens,configuration:{token_automatic_renew_mode:n.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:n.configuration.refresh_time_before_tokens_expiration_in_second},renewTokensAsync:n.renewTokensAsync.bind(n)},f=await fe(u),c=(d=f==null?void 0:f.tokens)==null?void 0:d.accessToken;if(a.has("Accept")||a.set("Accept","application/json"),c){if(n.configuration.demonstrating_proof_of_possession&&s){const g=await n.generateDemonstrationOfProofOfPossessionAsync(c,o.toString(),l.method);a.set("Authorization",`DPoP ${c}`),a.set("DPoP",g)}else a.set("Authorization",`Bearer ${c}`);l.credentials||(l.credentials="same-origin")}const _={...l,headers:a};return await e(o,_,...r)},mn=e=>async(n=!1,s=!1)=>{if(e.userInfo!=null&&!n)return e.userInfo;const t=e.configuration,i=(await e.initAsync(t.authority,t.authority_configuration)).userInfoEndpoint,l=await(async()=>{const u=await Ie(fetch,e,s)(i);return u.status!==200?null:u.json()})();return e.userInfo=l,l},Ce=()=>fetch;class ae{constructor(n){this.authorizationEndpoint=n.authorization_endpoint,this.tokenEndpoint=n.token_endpoint,this.revocationEndpoint=n.revocation_endpoint,this.userInfoEndpoint=n.userinfo_endpoint,this.checkSessionIframe=n.check_session_iframe,this.issuer=n.issuer,this.endSessionEndpoint=n.end_session_endpoint}}const R={},pn=(e,n=new W)=>(s,t="default")=>(R[t]||(R[t]=new x(s,t,e,n)),R[t]),wn=async e=>{const{parsedTokens:n,callbackPath:s,extras:t,scope:o}=await e.loginCallbackAsync();return e.timeoutId=B(e,n.expiresAt,t,o),{callbackPath:s}},An=e=>Math.floor(Math.random()*e),H=class H{constructor(n,s="default",t,o=new W){this.initPromise=null,this.tryKeepExistingSessionPromise=null,this.loginPromise=null,this.loginCallbackPromise=null,this.loginCallbackWithAutoTokensRenewPromise=null,this.userInfoPromise=null,this.renewTokensPromise=null,this.logoutPromise=null;let i=n.silent_login_uri;n.silent_redirect_uri&&!n.silent_login_uri&&(i=`${n.silent_redirect_uri.replace("-callback","").replace("callback","")}-login`);let r=n.refresh_time_before_tokens_expiration_in_second??120;r>60&&(r=r-Math.floor(Math.random()*40)),this.location=o??new W;const l=n.service_worker_update_require_callback??$e(this.location);this.configuration={...n,silent_login_uri:i,token_automatic_renew_mode:n.token_automatic_renew_mode??K.AutomaticBeforeTokenExpiration,monitor_session:n.monitor_session??!1,refresh_time_before_tokens_expiration_in_second:r,silent_login_timeout:n.silent_login_timeout??12e3,token_renew_mode:n.token_renew_mode??q.access_token_or_id_token_invalid,demonstrating_proof_of_possession:n.demonstrating_proof_of_possession??!1,authority_timeout_wellknowurl_in_millisecond:n.authority_timeout_wellknowurl_in_millisecond??1e4,logout_tokens_to_invalidate:n.logout_tokens_to_invalidate??["access_token","refresh_token"],service_worker_update_require_callback:l,service_worker_activate:n.service_worker_activate??ln,demonstrating_proof_of_possession_configuration:n.demonstrating_proof_of_possession_configuration??Me,preload_user_info:n.preload_user_info??!1},this.getFetch=t??Ce,this.configurationName=s,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 s=An(9999999999999).toString();return this.events.push({id:s,func:n}),s}removeEventSubscription(n){const s=this.events.filter(t=>t.id!==n);this.events=s}publishEvent(n,s){this.events.forEach(t=>{t.func(n,s)})}static get(n="default"){const s=typeof process>"u";if(!Object.prototype.hasOwnProperty.call(R,n)&&s)throw Error(`OIDC library does seem initialized.
|
|
2
|
+
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${n}"></OidcProvider> component.`);return R[n]}_silentLoginCallbackFromIFrame(){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const n=this.location,s=Q(n.getCurrentHref());window.parent.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({tokens:this.tokens,sessionState:s.session_state})}`,n.getOrigin())}}_silentLoginErrorCallbackFromIFrame(n=null){if(this.configuration.silent_redirect_uri&&this.configuration.silent_login_uri){const s=this.location,t=Q(s.getCurrentHref());t.error?window.parent.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({error:t.error})}`,s.getOrigin()):window.parent.postMessage(`${this.configurationName}_oidc_exception:${JSON.stringify({error:n==null?"":n.toString()})}`,s.getOrigin())}}async silentLoginCallbackAsync(){try{await this.loginCallbackAsync(!0),this._silentLoginCallbackFromIFrame()}catch(n){console.error(n),this._silentLoginErrorCallbackFromIFrame(n)}}async initAsync(n,s){if(this.initPromise!==null)return this.initPromise;const t=async()=>{if(s!=null)return new ae({authorization_endpoint:s.authorization_endpoint,end_session_endpoint:s.end_session_endpoint,revocation_endpoint:s.revocation_endpoint,token_endpoint:s.token_endpoint,userinfo_endpoint:s.userinfo_endpoint,check_session_iframe:s.check_session_iframe,issuer:s.issuer});const i=await N(this.configuration,this.configurationName)?window.localStorage:null;return await Qe(this.getFetch())(n,this.configuration.authority_time_cache_wellknowurl_in_second??60*60,i,this.configuration.authority_timeout_wellknowurl_in_millisecond)};return this.initPromise=t(),this.initPromise.finally(()=>{this.initPromise=null})}async tryKeepExistingSessionAsync(){return this.tryKeepExistingSessionPromise!==null?this.tryKeepExistingSessionPromise:(this.tryKeepExistingSessionPromise=un(this),this.tryKeepExistingSessionPromise.finally(()=>{this.tryKeepExistingSessionPromise=null}))}async startCheckSessionAsync(n,s,t,o=!1){await on(this,R,this.configuration)(n,s,t,o)}async loginAsync(n=void 0,s=null,t=!1,o=void 0,i=!1){return this.logoutPromise&&await this.logoutPromise,this.loginPromise!==null?this.loginPromise:(i?this.loginPromise=tn(window,this.configurationName,this.configuration,this.publishEvent.bind(this),this)(s,o):this.loginPromise=dn(this.configurationName,this.configuration,this.publishEvent.bind(this),this.initAsync.bind(this),this.location)(n,s,t,o),this.loginPromise.finally(()=>{this.loginPromise=null}))}async loginCallbackAsync(n=!1){if(this.loginCallbackPromise!==null)return this.loginCallbackPromise;const s=async()=>{const t=await hn(this)(n),o=t.tokens;return this.tokens=o,await N(this.configuration,this.configurationName)||C(this.configurationName,this.configuration.storage).setTokens(o),this.publishEvent(H.eventNames.token_acquired,o),this.configuration.preload_user_info&&await this.userInfoAsync(),{parsedTokens:o,state:t.state,callbackPath:t.callbackPath,scope:t.scope,extras:t.extras}};return this.loginCallbackPromise=s(),this.loginCallbackPromise.finally(()=>{this.loginCallbackPromise=null})}async generateDemonstrationOfProofOfPossessionAsync(n,s,t,o={}){const i=this.configuration,r={ath:await Te(n),...o};if(await N(i,this.configurationName))return`DPOP_SECURED_BY_OIDC_SERVICE_WORKER_${this.configurationName}`;const a=C(this.configurationName,i.storage),u=await a.getDemonstratingProofOfPossessionJwkAsync(),f=a.getDemonstratingProofOfPossessionNonce();return f&&(r.nonce=f),await Ae(window)(i.demonstrating_proof_of_possession_configuration)(u,t,s,r)}loginCallbackWithAutoTokensRenewAsync(){return this.loginCallbackWithAutoTokensRenewPromise!==null?this.loginCallbackWithAutoTokensRenewPromise:(this.loginCallbackWithAutoTokensRenewPromise=wn(this),this.loginCallbackWithAutoTokensRenewPromise.finally(()=>{this.loginCallbackWithAutoTokensRenewPromise=null}))}userInfoAsync(n=!1,s=!1){return this.userInfoPromise!==null?this.userInfoPromise:(this.userInfoPromise=mn(this)(n,s),this.userInfoPromise.finally(()=>{this.userInfoPromise=null}))}async renewTokensAsync(n=null,s=null){if(this.renewTokensPromise!==null)return this.renewTokensPromise;if(this.timeoutId)return U.clearTimeout(this.timeoutId),this.renewTokensPromise=Ee(this,!0,n,s),this.renewTokensPromise.finally(()=>{this.renewTokensPromise=null})}async destroyAsync(n){return await gn(this)(n)}async logoutSameTabAsync(n,s){this.configuration.monitor_session&&this.configuration.client_id===n&&s&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===s&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(k.logout_from_same_tab,{mmessage:"SessionMonitor",sub:s}))}async logoutOtherTabAsync(n,s){this.configuration.monitor_session&&this.configuration.client_id===n&&s&&this.tokens&&this.tokens.idTokenPayload&&this.tokens.idTokenPayload.sub===s&&(await this.destroyAsync("LOGGED_OUT"),this.publishEvent(k.logout_from_another_tab,{message:"SessionMonitor",sub:s}))}async logoutAsync(n=void 0,s=null){return this.logoutPromise?this.logoutPromise:(this.logoutPromise=kn(this,R,this.getFetch(),console,this.location)(n,s),this.logoutPromise.finally(()=>{this.logoutPromise=null}))}};H.getOrCreate=(n,s)=>(t,o="default")=>pn(n,s)(t,o),H.eventNames=k;let x=H;const V=class V{constructor(n){this._oidc=n}subscribeEvents(n){return this._oidc.subscribeEvents(n)}removeEventSubscription(n){this._oidc.removeEventSubscription(n)}publishEvent(n,s){this._oidc.publishEvent(n,s)}static get(n="default"){return new V(x.get(n))}tryKeepExistingSessionAsync(){return this._oidc.tryKeepExistingSessionAsync()}loginAsync(n=void 0,s=null,t=!1,o=void 0,i=!1){return this._oidc.loginAsync(n,s,t,o,i)}logoutAsync(n=void 0,s=null){return this._oidc.logoutAsync(n,s)}silentLoginCallbackAsync(){return this._oidc.silentLoginCallbackAsync()}renewTokensAsync(n=null,s=null){return this._oidc.renewTokensAsync(n,s)}loginCallbackAsync(){return this._oidc.loginCallbackWithAutoTokensRenewAsync()}get tokens(){return this._oidc.tokens}get configuration(){return this._oidc.configuration}async generateDemonstrationOfProofOfPossessionAsync(n,s,t,o={}){return this._oidc.generateDemonstrationOfProofOfPossessionAsync(n,s,t,o)}async getValidTokenAsync(n=200,s=50){const t=this._oidc,o={getTokens:()=>t.tokens,configuration:{token_automatic_renew_mode:t.configuration.token_automatic_renew_mode,refresh_time_before_tokens_expiration_in_second:t.configuration.refresh_time_before_tokens_expiration_in_second},renewTokensAsync:t.renewTokensAsync.bind(t)};return fe(o,n,s)}fetchWithTokens(n,s=!1){return Ie(n,this._oidc,s)}async userInfoAsync(n=!1,s=!1){return this._oidc.userInfoAsync(n,s)}userInfo(){return this._oidc.userInfo}};V.getOrCreate=(n,s=new W)=>(t,o="default")=>new V(x.getOrCreate(n,s)(t,o)),V.eventNames=x.eventNames;let ce=V;I.OidcClient=ce,I.OidcLocation=W,I.TokenAutomaticRenewMode=K,I.TokenRenewMode=q,I.getFetchDefault=Ce,I.getParseQueryStringFromLocation=Q,I.getPath=_n,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|
package/dist/initWorker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initWorker.d.ts","sourceRoot":"","sources":["../src/initWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK/C,eAAO,MAAM,UAAU,qBAAsB;IAAE,YAAY,EAAE,GAAG,CAAA;CAAE,qBAEjE,CAAC;AAuCF,eAAO,MAAM,yCAAyC,aACzC,cAAc,oBAA0B,GAAG,iBAAiB,MAAM,IAAI,kBAOhF,CAAC;AAmCJ,eAAO,MAAM,eAAe,kBACX,iBAAiB,qBACb,MAAM;;
|
|
1
|
+
{"version":3,"file":"initWorker.d.ts","sourceRoot":"","sources":["../src/initWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK/C,eAAO,MAAM,UAAU,qBAAsB;IAAE,YAAY,EAAE,GAAG,CAAA;CAAE,qBAEjE,CAAC;AAuCF,eAAO,MAAM,yCAAyC,aACzC,cAAc,oBAA0B,GAAG,iBAAiB,MAAM,IAAI,kBAOhF,CAAC;AAmCJ,eAAO,MAAM,eAAe,kBACX,iBAAiB,qBACb,MAAM;;6EA2CJ,iBAAiB;;;;;;yCAuCM,MAAM;;;;;;;;;2BAiHd,MAAM;;yCAwBQ,MAAM;kFAhFjB,MAAM;;mFAmBR,UAAU;;EA4FhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keepSession.d.ts","sourceRoot":"","sources":["../src/keepSession.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAI1B,eAAO,MAAM,mBAAmB,SAAgB,IAAI,
|
|
1
|
+
{"version":3,"file":"keepSession.d.ts","sourceRoot":"","sources":["../src/keepSession.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAI1B,eAAO,MAAM,mBAAmB,SAAgB,IAAI,qBAyGnD,CAAC"}
|
package/dist/login.d.ts
CHANGED
package/dist/login.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAI1B,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,sBAEP,MAAM,iBACV,iBAAiB,gBAClB,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,aACxB,iBAAiB,gBACd,cAAc,qBAGd,MAAM,WACZ,SAAS,oCAEV,MAAM,KACZ,OAAO,CAAC,OAAO,CAoEjB,CAAC;AAEJ,eAAO,MAAM,kBAAkB,SACtB,IAAI
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAI1B,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEjG,eAAO,MAAM,iBAAiB,sBAEP,MAAM,iBACV,iBAAiB,gBAClB,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,aACxB,iBAAiB,gBACd,cAAc,qBAGd,MAAM,WACZ,SAAS,oCAEV,MAAM,KACZ,OAAO,CAAC,OAAO,CAoEjB,CAAC;AAEJ,eAAO,MAAM,kBAAkB,SACtB,IAAI;;;;;;EAqLV,CAAC"}
|
package/dist/oidc.d.ts
CHANGED
|
@@ -22,7 +22,10 @@ export type LoginCallback = {
|
|
|
22
22
|
};
|
|
23
23
|
export type InternalLoginCallback = {
|
|
24
24
|
callbackPath: string;
|
|
25
|
+
state: string;
|
|
25
26
|
parsedTokens: Tokens;
|
|
27
|
+
scope: string;
|
|
28
|
+
extras: StringMap;
|
|
26
29
|
};
|
|
27
30
|
export declare class Oidc {
|
|
28
31
|
configuration: OidcConfiguration;
|
package/dist/oidc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../src/oidc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAW7D,OAAO,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EACL,sBAAsB,EACtB,KAAK,EACL,iBAAiB,EACjB,SAAS,EAEV,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,eAAe,oBAE3B,CAAC;AAEF,MAAM,WAAW,yCAAyC;IACxD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,qCAAqC;IAChD,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,kBAAkB,CAAS;gBAEvB,OAAO,EAAE,GAAG;CASzB;AAYD,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../src/oidc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAW7D,OAAO,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,EACL,sBAAsB,EACtB,KAAK,EACL,iBAAiB,EACjB,SAAS,EAEV,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,eAAe,oBAE3B,CAAC;AAEF,MAAM,WAAW,yCAAyC;IACxD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,qCAAqC;IAChD,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,kBAAkB,CAAS;gBAEvB,OAAO,EAAE,GAAG;CASzB;AAYD,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAYF,qBAAa,IAAI;IACR,aAAa,EAAE,iBAAiB,CAAC;IACjC,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,QAAQ,EAAE,MAAM,KAAK,CAAC;IACtB,QAAQ,EAAE,cAAc,CAAC;gBAE9B,aAAa,EAAE,iBAAiB,EAChC,iBAAiB,QAAY,EAC7B,QAAQ,EAAE,MAAM,KAAK,EACrB,QAAQ,GAAE,cAAmC;IA6D/C,eAAe,CAAC,IAAI,KAAA,GAAG,MAAM;IAM7B,uBAAuB,CAAC,EAAE,KAAA,GAAG,IAAI;IAKjC,YAAY,CAAC,SAAS,KAAA,EAAE,IAAI,KAAA;IAM5B,MAAM,CAAC,WAAW,aACL,MAAM,KAAK,YAAY,cAAc,gDAG9C;IAEJ,MAAM,CAAC,GAAG,CAAC,IAAI,SAAY;IAS3B,MAAM,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAc;IAE/B,8BAA8B;IAW9B,mCAAmC,CAAC,SAAS,MAAO;IAkB9C,wBAAwB;IAU9B,WAAW,MAAQ;IACb,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,sBAAsB,EAAE,sBAAsB;IAoCjF,6BAA6B,MAAQ;IAC/B,2BAA2B,IAAI,OAAO,CAAC,OAAO,CAAC;IAU/C,sBAAsB,CAC1B,qBAAqB,KAAA,EACrB,QAAQ,KAAA,EACR,YAAY,KAAA,EACZ,cAAc,UAAQ;IAUxB,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,CAAQ;IAChC,UAAU,CACd,YAAY,GAAE,MAAkB,EAChC,MAAM,GAAE,SAAgB,EACxB,cAAc,UAAQ,EACtB,KAAK,GAAE,MAAkB,EACzB,eAAe,UAAQ;IA+BzB,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAQ;IACpC,kBAAkB,CAAC,aAAa,UAAQ;IAmCxC,6CAA6C,CACjD,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,SAAc,GACrB,OAAO,CAAC,MAAM,CAAC;IA0BlB,uCAAuC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAQ;IACvE,qCAAqC,IAAI,OAAO,CAAC,aAAa,CAAC;IAU/D,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,CAAQ;IACrC,aAAa,CAAC,OAAO,UAAQ,EAAE,iCAAiC,UAAQ;IAUxE,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAQ;IAElC,gBAAgB,CAAC,MAAM,GAAE,SAAgB,EAAE,KAAK,GAAE,MAAa;IAgB/D,YAAY,CAAC,MAAM,KAAA;IAInB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAe7C,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;IAepD,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,CAAQ;IAC9B,WAAW,CACf,iBAAiB,GAAE,MAAM,GAAG,IAAI,GAAG,SAAqB,EACxD,MAAM,GAAE,SAAgB;CAgB3B;AAED,eAAe,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,eAAO,MAAM,iBAAiB,sBAEP,MAAM,iBACV,iBAAiB,gBAClB,oBAAoB,eAG1B,SAAS,UACV,MAAM,UACN,MAAM,KACZ,OAAO,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,eAAO,MAAM,iBAAiB,sBAEP,MAAM,iBACV,iBAAiB,gBAClB,oBAAoB,eAG1B,SAAS,UACV,MAAM,UACN,MAAM,KACZ,OAAO,CAAC,mBAAmB,CAqG7B,CAAC;AAEJ,eAAO,MAAM,uBAAuB,uDAIjB,iBAAiB,gBAClB,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,QAC7B,GAAG,eAEF,SAAS,UAAgB,MAAM,qBA6CvC,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"wBAAe,QAAQ;AAAvB,wBAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/oidc-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.25.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"url": "https://github.com/AxaFrance/oidc-client.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@axa-fr/oidc-client-service-worker": "7.
|
|
23
|
+
"@axa-fr/oidc-client-service-worker": "7.25.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/dom": "10.4.0",
|
|
27
|
-
"@testing-library/jest-dom": "6.
|
|
28
|
-
"@testing-library/react": "16.0
|
|
29
|
-
"@vitest/coverage-v8": "2.
|
|
27
|
+
"@testing-library/jest-dom": "6.6.3",
|
|
28
|
+
"@testing-library/react": "16.1.0",
|
|
29
|
+
"@vitest/coverage-v8": "2.1.8",
|
|
30
30
|
"cpy": "11.1.0",
|
|
31
31
|
"cpy-cli": "^5.0.0",
|
|
32
32
|
"rimraf": "6.0.1",
|
|
33
|
-
"typescript": "5.
|
|
34
|
-
"vite": "
|
|
35
|
-
"vite-plugin-dts": "4.
|
|
36
|
-
"vitest": "2.
|
|
33
|
+
"typescript": "5.7.3",
|
|
34
|
+
"vite": "6.0.7",
|
|
35
|
+
"vite-plugin-dts": "4.5.0",
|
|
36
|
+
"vitest": "2.1.8"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"oidc",
|
package/src/initWorker.ts
CHANGED
|
@@ -125,6 +125,7 @@ export const initWorkerAsync = async (
|
|
|
125
125
|
if (!navigator.serviceWorker.controller)
|
|
126
126
|
await sendMessageAsync(registration)({ type: 'claim' });
|
|
127
127
|
} catch (err) {
|
|
128
|
+
console.warn(`Failed init ServiceWorker ${err.toString()}`);
|
|
128
129
|
return null;
|
|
129
130
|
}
|
|
130
131
|
|
package/src/keepSession.ts
CHANGED
|
@@ -30,7 +30,12 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
|
|
|
30
30
|
oidc.tokens = tokens;
|
|
31
31
|
const getLoginParams = serviceWorker.getLoginParams(oidc.configurationName);
|
|
32
32
|
// @ts-ignore
|
|
33
|
-
oidc.timeoutId = autoRenewTokens(
|
|
33
|
+
oidc.timeoutId = autoRenewTokens(
|
|
34
|
+
oidc,
|
|
35
|
+
oidc.tokens.expiresAt,
|
|
36
|
+
getLoginParams.extras,
|
|
37
|
+
getLoginParams.scope,
|
|
38
|
+
);
|
|
34
39
|
const sessionState = await serviceWorker.getSessionStateAsync();
|
|
35
40
|
// @ts-ignore
|
|
36
41
|
await oidc.startCheckSessionAsync(
|
|
@@ -64,7 +69,12 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
|
|
|
64
69
|
oidc.tokens = setTokens(tokens, null, configuration.token_renew_mode);
|
|
65
70
|
const getLoginParams = session.getLoginParams();
|
|
66
71
|
// @ts-ignore
|
|
67
|
-
oidc.timeoutId = autoRenewTokens(
|
|
72
|
+
oidc.timeoutId = autoRenewTokens(
|
|
73
|
+
oidc,
|
|
74
|
+
oidc.tokens.expiresAt,
|
|
75
|
+
getLoginParams.extras,
|
|
76
|
+
getLoginParams.scope,
|
|
77
|
+
);
|
|
68
78
|
const sessionState = await session.getSessionStateAsync();
|
|
69
79
|
// @ts-ignore
|
|
70
80
|
await oidc.startCheckSessionAsync(
|
package/src/login.ts
CHANGED
|
@@ -63,14 +63,14 @@ export const defaultLoginAsync =
|
|
|
63
63
|
);
|
|
64
64
|
let storage;
|
|
65
65
|
if (serviceWorker) {
|
|
66
|
-
serviceWorker.setLoginParams({ callbackPath: url, extras: originExtras });
|
|
66
|
+
serviceWorker.setLoginParams({ callbackPath: url, extras: originExtras, scope: scope });
|
|
67
67
|
await serviceWorker.initAsync(oidcServerConfiguration, 'loginAsync', configuration);
|
|
68
68
|
await serviceWorker.setNonceAsync(nonce);
|
|
69
69
|
serviceWorker.startKeepAliveServiceWorker();
|
|
70
70
|
storage = serviceWorker;
|
|
71
71
|
} else {
|
|
72
72
|
const session = initSession(configurationName, configuration.storage ?? sessionStorage);
|
|
73
|
-
session.setLoginParams({ callbackPath: url, extras: originExtras });
|
|
73
|
+
session.setLoginParams({ callbackPath: url, extras: originExtras, scope: scope });
|
|
74
74
|
await session.setNonceAsync(nonce);
|
|
75
75
|
storage = session;
|
|
76
76
|
}
|
|
@@ -139,24 +139,24 @@ export const loginCallbackAsync =
|
|
|
139
139
|
storage = session;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
if (queryParams.error || queryParams.error_description) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Error from OIDC server: ${queryParams.error} - ${queryParams.error_description}`,
|
|
145
|
+
);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
if (
|
|
148
|
+
if (queryParams.iss && queryParams.iss !== oidcServerConfiguration.issuer) {
|
|
149
149
|
console.error();
|
|
150
150
|
throw new Error(
|
|
151
|
-
`Issuer not valid (expected: ${oidcServerConfiguration.issuer}, received: ${
|
|
151
|
+
`Issuer not valid (expected: ${oidcServerConfiguration.issuer}, received: ${queryParams.iss})`,
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
|
-
if (
|
|
155
|
-
throw new Error(`State not valid (expected: ${state}, received: ${
|
|
154
|
+
if (queryParams.state && queryParams.state !== state) {
|
|
155
|
+
throw new Error(`State not valid (expected: ${state}, received: ${queryParams.state})`);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
const data = {
|
|
159
|
-
code:
|
|
159
|
+
code: queryParams.code,
|
|
160
160
|
grant_type: 'authorization_code',
|
|
161
161
|
client_id: configuration.client_id,
|
|
162
162
|
redirect_uri: redirectUri,
|
|
@@ -269,6 +269,8 @@ export const loginCallbackAsync =
|
|
|
269
269
|
tokens: formattedTokens,
|
|
270
270
|
state: 'request.state',
|
|
271
271
|
callbackPath: loginParams.callbackPath,
|
|
272
|
+
scope: queryParams.scope,
|
|
273
|
+
extras: loginParams.extras,
|
|
272
274
|
};
|
|
273
275
|
} catch (exception) {
|
|
274
276
|
console.error(exception);
|
package/src/oidc.ts
CHANGED
|
@@ -73,12 +73,15 @@ export type LoginCallback = {
|
|
|
73
73
|
|
|
74
74
|
export type InternalLoginCallback = {
|
|
75
75
|
callbackPath: string;
|
|
76
|
+
state: string;
|
|
76
77
|
parsedTokens: Tokens;
|
|
78
|
+
scope: string;
|
|
79
|
+
extras: StringMap;
|
|
77
80
|
};
|
|
78
81
|
|
|
79
82
|
const loginCallbackWithAutoTokensRenewAsync = async (oidc): Promise<LoginCallback> => {
|
|
80
|
-
const { parsedTokens, callbackPath } = await oidc.loginCallbackAsync();
|
|
81
|
-
oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.expiresAt);
|
|
83
|
+
const { parsedTokens, callbackPath, extras, scope } = await oidc.loginCallbackAsync();
|
|
84
|
+
oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.expiresAt, extras, scope);
|
|
82
85
|
return { callbackPath };
|
|
83
86
|
};
|
|
84
87
|
|
|
@@ -355,7 +358,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
355
358
|
await this.userInfoAsync();
|
|
356
359
|
}
|
|
357
360
|
// @ts-ignore
|
|
358
|
-
return {
|
|
361
|
+
return {
|
|
362
|
+
parsedTokens,
|
|
363
|
+
state: response.state,
|
|
364
|
+
callbackPath: response.callbackPath,
|
|
365
|
+
scope: response.scope,
|
|
366
|
+
extras: response.extras,
|
|
367
|
+
};
|
|
359
368
|
};
|
|
360
369
|
this.loginCallbackPromise = loginCallbackLocalAsync();
|
|
361
370
|
return this.loginCallbackPromise.finally(() => {
|
|
@@ -427,6 +436,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
427
436
|
}
|
|
428
437
|
timer.clearTimeout(this.timeoutId);
|
|
429
438
|
// @ts-ignore
|
|
439
|
+
|
|
430
440
|
this.renewTokensPromise = renewTokensAndStartTimerAsync(this, true, extras, scope);
|
|
431
441
|
return this.renewTokensPromise.finally(() => {
|
|
432
442
|
this.renewTokensPromise = null;
|
package/src/silentLogin.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.
|
|
1
|
+
export default '7.25.0';
|