@auth0/auth0-vue
Version:
Auth0 SDK for Vue Applications using Authorization Code Grant Flow with PKCE
3 lines (2 loc) • 48.6 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).vueAuth0=t(e.Vue)}(this,(function(e){"use strict";const t="$auth0",i=Symbol(t);function n(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}"function"==typeof SuppressedError&&SuppressedError;var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function s(e,t){return e(t={exports:{}},t.exports),t.exports}var r=s((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){var e=this;this.locked=new Map,this.addToLocked=function(t,i){var n=e.locked.get(t);void 0===n?void 0===i?e.locked.set(t,[]):e.locked.set(t,[i]):void 0!==i&&(n.unshift(i),e.locked.set(t,n))},this.isLocked=function(t){return e.locked.has(t)},this.lock=function(t){return new Promise((function(i,n){e.isLocked(t)?e.addToLocked(t,i):(e.addToLocked(t),i())}))},this.unlock=function(t){var i=e.locked.get(t);if(void 0!==i&&0!==i.length){var n=i.pop();e.locked.set(t,i),void 0!==n&&setTimeout(n,0)}else e.locked.delete(t)}}return e.getInstance=function(){return void 0===e.instance&&(e.instance=new e),e.instance},e}();t.default=function(){return i.getInstance()}}));a(r);var c=a(s((function(e,t){var i=o&&o.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(o,a){function s(e){try{c(n.next(e))}catch(e){a(e)}}function r(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){e.done?o(e.value):new i((function(t){t(e.value)})).then(s,r)}c((n=n.apply(e,t||[])).next())}))},n=o&&o.__generator||function(e,t){var i,n,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function r(a){return function(r){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],n=0}finally{i=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,r])}}},a=o;Object.defineProperty(t,"__esModule",{value:!0});var s="browser-tabs-lock-key",c={key:function(e){return i(a,void 0,void 0,(function(){return n(this,(function(e){throw new Error("Unsupported")}))}))},getItem:function(e){return i(a,void 0,void 0,(function(){return n(this,(function(e){throw new Error("Unsupported")}))}))},clear:function(){return i(a,void 0,void 0,(function(){return n(this,(function(e){return[2,window.localStorage.clear()]}))}))},removeItem:function(e){return i(a,void 0,void 0,(function(){return n(this,(function(e){throw new Error("Unsupported")}))}))},setItem:function(e,t){return i(a,void 0,void 0,(function(){return n(this,(function(e){throw new Error("Unsupported")}))}))},keySync:function(e){return window.localStorage.key(e)},getItemSync:function(e){return window.localStorage.getItem(e)},clearSync:function(){return window.localStorage.clear()},removeItemSync:function(e){return window.localStorage.removeItem(e)},setItemSync:function(e,t){return window.localStorage.setItem(e,t)}};function l(e){return new Promise((function(t){return setTimeout(t,e)}))}function d(e){for(var t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",i="",n=0;n<e;n++)i+=t[Math.floor(Math.random()*t.length)];return i}var u=function(){function e(t){this.acquiredIatSet=new Set,this.storageHandler=void 0,this.id=Date.now().toString()+d(15),this.acquireLock=this.acquireLock.bind(this),this.releaseLock=this.releaseLock.bind(this),this.releaseLock__private__=this.releaseLock__private__.bind(this),this.waitForSomethingToChange=this.waitForSomethingToChange.bind(this),this.refreshLockWhileAcquired=this.refreshLockWhileAcquired.bind(this),this.storageHandler=t,void 0===e.waiters&&(e.waiters=[])}return e.prototype.acquireLock=function(t,o){return void 0===o&&(o=5e3),i(this,void 0,void 0,(function(){var i,a,r,u,h,p,m;return n(this,(function(n){switch(n.label){case 0:i=Date.now()+d(4),a=Date.now()+o,r=s+"-"+t,u=void 0===this.storageHandler?c:this.storageHandler,n.label=1;case 1:return Date.now()<a?[4,l(30)]:[3,8];case 2:return n.sent(),null!==u.getItemSync(r)?[3,5]:(h=this.id+"-"+t+"-"+i,[4,l(Math.floor(25*Math.random()))]);case 3:return n.sent(),u.setItemSync(r,JSON.stringify({id:this.id,iat:i,timeoutKey:h,timeAcquired:Date.now(),timeRefreshed:Date.now()})),[4,l(30)];case 4:return n.sent(),null!==(p=u.getItemSync(r))&&(m=JSON.parse(p)).id===this.id&&m.iat===i?(this.acquiredIatSet.add(i),this.refreshLockWhileAcquired(r,i),[2,!0]):[3,7];case 5:return e.lockCorrector(void 0===this.storageHandler?c:this.storageHandler),[4,this.waitForSomethingToChange(a)];case 6:n.sent(),n.label=7;case 7:return i=Date.now()+d(4),[3,1];case 8:return[2,!1]}}))}))},e.prototype.refreshLockWhileAcquired=function(e,t){return i(this,void 0,void 0,(function(){var o=this;return n(this,(function(a){return setTimeout((function(){return i(o,void 0,void 0,(function(){var i,o,a;return n(this,(function(n){switch(n.label){case 0:return[4,r.default().lock(t)];case 1:return n.sent(),this.acquiredIatSet.has(t)?(i=void 0===this.storageHandler?c:this.storageHandler,null===(o=i.getItemSync(e))?(r.default().unlock(t),[2]):((a=JSON.parse(o)).timeRefreshed=Date.now(),i.setItemSync(e,JSON.stringify(a)),r.default().unlock(t),this.refreshLockWhileAcquired(e,t),[2])):(r.default().unlock(t),[2])}}))}))}),1e3),[2]}))}))},e.prototype.waitForSomethingToChange=function(t){return i(this,void 0,void 0,(function(){return n(this,(function(i){switch(i.label){case 0:return[4,new Promise((function(i){var n=!1,o=Date.now(),a=!1;function s(){if(a||(window.removeEventListener("storage",s),e.removeFromWaiting(s),clearTimeout(r),a=!0),!n){n=!0;var t=50-(Date.now()-o);t>0?setTimeout(i,t):i(null)}}window.addEventListener("storage",s),e.addToWaiting(s);var r=setTimeout(s,Math.max(0,t-Date.now()))}))];case 1:return i.sent(),[2]}}))}))},e.addToWaiting=function(t){this.removeFromWaiting(t),void 0!==e.waiters&&e.waiters.push(t)},e.removeFromWaiting=function(t){void 0!==e.waiters&&(e.waiters=e.waiters.filter((function(e){return e!==t})))},e.notifyWaiters=function(){void 0!==e.waiters&&e.waiters.slice().forEach((function(e){return e()}))},e.prototype.releaseLock=function(e){return i(this,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,this.releaseLock__private__(e)];case 1:return[2,t.sent()]}}))}))},e.prototype.releaseLock__private__=function(t){return i(this,void 0,void 0,(function(){var i,o,a,l;return n(this,(function(n){switch(n.label){case 0:return i=void 0===this.storageHandler?c:this.storageHandler,o=s+"-"+t,null===(a=i.getItemSync(o))?[2]:(l=JSON.parse(a)).id!==this.id?[3,2]:[4,r.default().lock(l.iat)];case 1:n.sent(),this.acquiredIatSet.delete(l.iat),i.removeItemSync(o),r.default().unlock(l.iat),e.notifyWaiters(),n.label=2;case 2:return[2]}}))}))},e.lockCorrector=function(t){for(var i=Date.now()-5e3,n=t,o=[],a=0;;){var r=n.keySync(a);if(null===r)break;o.push(r),a++}for(var c=!1,l=0;l<o.length;l++){var d=o[l];if(d.includes(s)){var u=n.getItemSync(d);if(null!==u){var h=JSON.parse(u);(void 0===h.timeRefreshed&&h.timeAcquired<i||void 0!==h.timeRefreshed&&h.timeRefreshed<i)&&(n.removeItemSync(d),c=!0)}}}c&&e.notifyWaiters()},e.waiters=void 0,e}();t.default=u})));const l={timeoutInSeconds:60},d={name:"auth0-spa-js",version:"2.1.3"},u=()=>Date.now();class h extends Error{constructor(e,t){super(t),this.error=e,this.error_description=t,Object.setPrototypeOf(this,h.prototype)}static fromPayload({error:e,error_description:t}){return new h(e,t)}}class p extends h{constructor(e,t,i,n=null){super(e,t),this.state=i,this.appState=n,Object.setPrototypeOf(this,p.prototype)}}class m extends h{constructor(){super("timeout","Timeout"),Object.setPrototypeOf(this,m.prototype)}}class g extends m{constructor(e){super(),this.popup=e,Object.setPrototypeOf(this,g.prototype)}}class f extends h{constructor(e){super("cancelled","Popup closed"),this.popup=e,Object.setPrototypeOf(this,f.prototype)}}class y extends h{constructor(e,t,i){super(e,t),this.mfa_token=i,Object.setPrototypeOf(this,y.prototype)}}class w extends h{constructor(e,t){super("missing_refresh_token",`Missing Refresh Token (audience: '${b(e,["default"])}', scope: '${b(t)}')`),this.audience=e,this.scope=t,Object.setPrototypeOf(this,w.prototype)}}function b(e,t=[]){return e&&!t.includes(e)?e:""}const v=()=>window.crypto,k=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return Array.from(v().getRandomValues(new Uint8Array(43))).forEach((i=>t+=e[i%e.length])),t},_=e=>btoa(e),I=e=>{var{clientId:t}=e,i=n(e,["clientId"]);return new URLSearchParams((e=>Object.keys(e).filter((t=>void 0!==e[t])).reduce(((t,i)=>Object.assign(Object.assign({},t),{[i]:e[i]})),{}))(Object.assign({client_id:t},i))).toString()},S=e=>(e=>decodeURIComponent(atob(e).split("").map((e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join("")))(e.replace(/_/g,"/").replace(/-/g,"+")),Z=async(e,t)=>{const i=await fetch(e,t);return{ok:i.ok,json:await i.json()}},W=async(e,t,i,n,o,a,s=1e4)=>o?(async(e,t,i,n,o,a,s)=>{return r={auth:{audience:t,scope:i},timeout:o,fetchUrl:e,fetchOptions:n,useFormData:s},c=a,new Promise((function(e,t){const i=new MessageChannel;i.port1.onmessage=function(n){n.data.error?t(new Error(n.data.error)):e(n.data),i.port1.close()},c.postMessage(r,[i.port2])}));var r,c})(e,t,i,n,s,o,a):(async(e,t,i)=>{const n=new AbortController;let o;return t.signal=n.signal,Promise.race([Z(e,t),new Promise(((e,t)=>{o=setTimeout((()=>{n.abort(),t(new Error("Timeout when executing 'fetch'"))}),i)}))]).finally((()=>{clearTimeout(o)}))})(e,n,s);async function C(e,t){var{baseUrl:i,timeout:o,audience:a,scope:s,auth0Client:r,useFormData:c}=e,l=n(e,["baseUrl","timeout","audience","scope","auth0Client","useFormData"]);const u=c?I(l):JSON.stringify(l);return await async function(e,t,i,o,a,s,r){let c,l=null;for(let n=0;n<3;n++)try{c=await W(e,i,o,a,s,r,t),l=null;break}catch(e){l=e}if(l)throw l;const d=c.json,{error:u,error_description:p}=d,m=n(d,["error","error_description"]),{ok:g}=c;if(!g){const t=p||`HTTP error. Unable to fetch ${e}`;if("mfa_required"===u)throw new y(u,t,m.mfa_token);if("missing_refresh_token"===u)throw new w(i,o);throw new h(u||"request_error",t)}return m}(`${i}/oauth/token`,o,a||"default",s,{method:"POST",body:u,headers:{"Content-Type":c?"application/x-www-form-urlencoded":"application/json","Auth0-Client":btoa(JSON.stringify(r||d))}},t,c)}const T=(...e)=>{return(t=e.filter(Boolean).join(" ").trim().split(/\s+/),Array.from(new Set(t))).join(" ");var t};class j{constructor(e,t="@@auth0spajs@@",i){this.prefix=t,this.suffix=i,this.clientId=e.clientId,this.scope=e.scope,this.audience=e.audience}toKey(){return[this.prefix,this.clientId,this.audience,this.scope,this.suffix].filter(Boolean).join("::")}static fromKey(e){const[t,i,n,o]=e.split("::");return new j({clientId:i,scope:o,audience:n},t)}static fromCacheEntry(e){const{scope:t,audience:i,client_id:n}=e;return new j({scope:t,audience:i,clientId:n})}}class O{set(e,t){localStorage.setItem(e,JSON.stringify(t))}get(e){const t=window.localStorage.getItem(e);if(t)try{return JSON.parse(t)}catch(e){return}}remove(e){localStorage.removeItem(e)}allKeys(){return Object.keys(window.localStorage).filter((e=>e.startsWith("@@auth0spajs@@")))}}class P{constructor(){this.enclosedCache=function(){let e={};return{set(t,i){e[t]=i},get(t){const i=e[t];if(i)return i},remove(t){delete e[t]},allKeys:()=>Object.keys(e)}}()}}class z{constructor(e,t,i){this.cache=e,this.keyManifest=t,this.nowProvider=i||u}async setIdToken(e,t,i){var n;const o=this.getIdTokenCacheKey(e);await this.cache.set(o,{id_token:t,decodedToken:i}),await(null===(n=this.keyManifest)||void 0===n?void 0:n.add(o))}async getIdToken(e){const t=await this.cache.get(this.getIdTokenCacheKey(e.clientId));if(!t&&e.scope&&e.audience){const t=await this.get(e);if(!t)return;if(!t.id_token||!t.decodedToken)return;return{id_token:t.id_token,decodedToken:t.decodedToken}}if(t)return{id_token:t.id_token,decodedToken:t.decodedToken}}async get(e,t=0){var i;let n=await this.cache.get(e.toKey());if(!n){const t=await this.getCacheKeys();if(!t)return;const i=this.matchExistingCacheKey(e,t);i&&(n=await this.cache.get(i))}if(!n)return;const o=await this.nowProvider(),a=Math.floor(o/1e3);return n.expiresAt-t<a?n.body.refresh_token?(n.body={refresh_token:n.body.refresh_token},await this.cache.set(e.toKey(),n),n.body):(await this.cache.remove(e.toKey()),void await(null===(i=this.keyManifest)||void 0===i?void 0:i.remove(e.toKey()))):n.body}async set(e){var t;const i=new j({clientId:e.client_id,scope:e.scope,audience:e.audience}),n=await this.wrapCacheEntry(e);await this.cache.set(i.toKey(),n),await(null===(t=this.keyManifest)||void 0===t?void 0:t.add(i.toKey()))}async clear(e){var t;const i=await this.getCacheKeys();i&&(await i.filter((t=>!e||t.includes(e))).reduce((async(e,t)=>{await e,await this.cache.remove(t)}),Promise.resolve()),await(null===(t=this.keyManifest)||void 0===t?void 0:t.clear()))}async wrapCacheEntry(e){const t=await this.nowProvider();return{body:e,expiresAt:Math.floor(t/1e3)+e.expires_in}}async getCacheKeys(){var e;return this.keyManifest?null===(e=await this.keyManifest.get())||void 0===e?void 0:e.keys:this.cache.allKeys?this.cache.allKeys():void 0}getIdTokenCacheKey(e){return new j({clientId:e},"@@auth0spajs@@","@@user@@").toKey()}matchExistingCacheKey(e,t){return t.filter((t=>{var i;const n=j.fromKey(t),o=new Set(n.scope&&n.scope.split(" ")),a=(null===(i=e.scope)||void 0===i?void 0:i.split(" "))||[],s=n.scope&&a.reduce(((e,t)=>e&&o.has(t)),!0);return"@@auth0spajs@@"===n.prefix&&n.clientId===e.clientId&&n.audience===e.audience&&s}))[0]}}class X{constructor(e,t,i){this.storage=e,this.clientId=t,this.cookieDomain=i,this.storageKey=`a0.spajs.txs.${this.clientId}`}create(e){this.storage.save(this.storageKey,e,{daysUntilExpire:1,cookieDomain:this.cookieDomain})}get(){return this.storage.get(this.storageKey)}remove(){this.storage.remove(this.storageKey,{cookieDomain:this.cookieDomain})}}const K=e=>"number"==typeof e,R=["iss","aud","exp","nbf","iat","jti","azp","nonce","auth_time","at_hash","c_hash","acr","amr","sub_jwk","cnf","sip_from_tag","sip_date","sip_callid","sip_cseq_num","sip_via_branch","orig","dest","mky","events","toe","txn","rph","sid","vot","vtm"];var x=s((function(e,t){var i=o&&o.__assign||function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var o in t=arguments[i])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function n(e,t){if(!t)return"";var i="; "+e;return!0===t?i:i+"="+t}function a(e,t,i){return encodeURIComponent(e).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/\(/g,"%28").replace(/\)/g,"%29")+"="+encodeURIComponent(t).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent)+function(e){if("number"==typeof e.expires){var t=new Date;t.setMilliseconds(t.getMilliseconds()+864e5*e.expires),e.expires=t}return n("Expires",e.expires?e.expires.toUTCString():"")+n("Domain",e.domain)+n("Path",e.path)+n("Secure",e.secure)+n("SameSite",e.sameSite)}(i)}function s(e){for(var t={},i=e?e.split("; "):[],n=/(%[\dA-F]{2})+/gi,o=0;o<i.length;o++){var a=i[o].split("="),s=a.slice(1).join("=");'"'===s.charAt(0)&&(s=s.slice(1,-1));try{t[a[0].replace(n,decodeURIComponent)]=s.replace(n,decodeURIComponent)}catch(e){}}return t}function r(){return s(document.cookie)}function c(e,t,n){document.cookie=a(e,t,i({path:"/"},n))}t.__esModule=!0,t.encode=a,t.parse=s,t.getAll=r,t.get=function(e){return r()[e]},t.set=c,t.remove=function(e,t){c(e,"",i(i({},t),{expires:-1}))}}));a(x),x.encode,x.parse,x.getAll;var N=x.get,L=x.set,Y=x.remove;const G={get(e){const t=N(e);if(void 0!==t)return JSON.parse(t)},save(e,t,i){let n={};"https:"===window.location.protocol&&(n={secure:!0,sameSite:"none"}),(null==i?void 0:i.daysUntilExpire)&&(n.expires=i.daysUntilExpire),(null==i?void 0:i.cookieDomain)&&(n.domain=i.cookieDomain),L(e,JSON.stringify(t),n)},remove(e,t){let i={};(null==t?void 0:t.cookieDomain)&&(i.domain=t.cookieDomain),Y(e,i)}},J={get:e=>G.get(e)||G.get(`_legacy_${e}`),save(e,t,i){let n={};"https:"===window.location.protocol&&(n={secure:!0}),(null==i?void 0:i.daysUntilExpire)&&(n.expires=i.daysUntilExpire),(null==i?void 0:i.cookieDomain)&&(n.domain=i.cookieDomain),L(`_legacy_${e}`,JSON.stringify(t),n),G.save(e,t,i)},remove(e,t){let i={};(null==t?void 0:t.cookieDomain)&&(i.domain=t.cookieDomain),Y(e,i),G.remove(e,t),G.remove(`_legacy_${e}`,t)}},V={get(e){if("undefined"==typeof sessionStorage)return;const t=sessionStorage.getItem(e);return null!=t?JSON.parse(t):void 0},save(e,t){sessionStorage.setItem(e,JSON.stringify(t))},remove(e){sessionStorage.removeItem(e)}};var U,E=("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZSBleHRlbmRzIEVycm9ye2NvbnN0cnVjdG9yKHQscil7c3VwZXIociksdGhpcy5lcnJvcj10LHRoaXMuZXJyb3JfZGVzY3JpcHRpb249cixPYmplY3Quc2V0UHJvdG90eXBlT2YodGhpcyxlLnByb3RvdHlwZSl9c3RhdGljIGZyb21QYXlsb2FkKHtlcnJvcjp0LGVycm9yX2Rlc2NyaXB0aW9uOnJ9KXtyZXR1cm4gbmV3IGUodCxyKX19Y2xhc3MgdCBleHRlbmRzIGV7Y29uc3RydWN0b3IoZSxzKXtzdXBlcigibWlzc2luZ19yZWZyZXNoX3Rva2VuIixgTWlzc2luZyBSZWZyZXNoIFRva2VuIChhdWRpZW5jZTogJyR7cihlLFsiZGVmYXVsdCJdKX0nLCBzY29wZTogJyR7cihzKX0nKWApLHRoaXMuYXVkaWVuY2U9ZSx0aGlzLnNjb3BlPXMsT2JqZWN0LnNldFByb3RvdHlwZU9mKHRoaXMsdC5wcm90b3R5cGUpfX1mdW5jdGlvbiByKGUsdD1bXSl7cmV0dXJuIGUmJiF0LmluY2x1ZGVzKGUpP2U6IiJ9ImZ1bmN0aW9uIj09dHlwZW9mIFN1cHByZXNzZWRFcnJvciYmU3VwcHJlc3NlZEVycm9yO2NvbnN0IHM9ZT0+e3ZhcntjbGllbnRJZDp0fT1lLHI9ZnVuY3Rpb24oZSx0KXt2Y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GlvbjplLm1lc3NhZ2V9fSl9dmFyIGR9KSl9KCk7Cgo=",null,!1,function(e){return U=U||function(e,t,i){var n=void 0===t?null:t,o=function(e,t){var i=atob(e);if(t){for(var n=new Uint8Array(i.length),o=0,a=i.length;o<a;++o)n[o]=i.charCodeAt(o);return String.fromCharCode.apply(null,new Uint16Array(n.buffer))}return i}(e,void 0!==i&&i),a=o.indexOf("\n",10)+1,s=o.substring(a)+(n?"//# sourceMappingURL="+n:""),r=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(r)}("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZSBleHRlbmRzIEVycm9ye2NvbnN0cnVjdG9yKHQscil7c3VwZXIociksdGhpcy5lcnJvcj10LHRoaXMuZXJyb3JfZGVzY3JpcHRpb249cixPYmplY3Quc2V0UHJvdG90eXBlT2YodGhpcyxlLnByb3RvdHlwZSl9c3RhdGljIGZyb21QYXlsb2FkKHtlcnJvcjp0LGVycm9yX2Rlc2NyaXB0aW9uOnJ9KXtyZXR1cm4gbmV3IGUodCxyKX19Y2xhc3MgdCBleHRlbmRzIGV7Y29uc3RydWN0b3IoZSxzKXtzdXBlcigibWlzc2luZ19yZWZyZXNoX3Rva2VuIixgTWlzc2luZyBSZWZyZXNoIFRva2VuIChhdWRpZW5jZTogJyR7cihlLFsiZGVmYXVsdCJdKX0nLCBzY29wZTogJyR7cihzKX0nKWApLHRoaXMuYXVkaWVuY2U9ZSx0aGlzLnNjb3BlPXMsT2JqZWN0LnNldFByb3RvdHlwZU9mKHRoaXMsdC5wcm90b3R5cGUpfX1mdW5jdGlvbiByKGUsdD1bXSl7cmV0dXJuIGUmJiF0LmluY2x1ZGVzKGUpP2U6IiJ9ImZ1bmN0aW9uIj09dHlwZW9mIFN1cHByZXNzZWRFcnJvciYmU3VwcHJlc3NlZEVycm9yO2NvbnN0IHM9ZT0+e3ZhcntjbGll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ZXJyb3I6ZS5lcnJvcixlcnJvcl9kZXNjcmlwdGlvbjplLm1lc3NhZ2V9fSl9dmFyIGR9KSl9KCk7Cgo=",null,false),new Worker(U,e)});const H={};class F{constructor(e,t){this.cache=e,this.clientId=t,this.manifestKey=this.createManifestKeyFrom(this.clientId)}async add(e){var t;const i=new Set((null===(t=await this.cache.get(this.manifestKey))||void 0===t?void 0:t.keys)||[]);i.add(e),await this.cache.set(this.manifestKey,{keys:[...i]})}async remove(e){const t=await this.cache.get(this.manifestKey);if(t){const i=new Set(t.keys);return i.delete(e),i.size>0?await this.cache.set(this.manifestKey,{keys:[...i]}):await this.cache.remove(this.manifestKey)}}get(){return this.cache.get(this.manifestKey)}clear(){return this.cache.remove(this.manifestKey)}createManifestKeyFrom(e){return`@@auth0spajs@@::${e}`}}const D={memory:()=>(new P).enclosedCache,localstorage:()=>new O},A=e=>D[e],B=e=>{const{openUrl:t,onRedirect:i}=e,o=n(e,["openUrl","onRedirect"]);return Object.assign(Object.assign({},o),{openUrl:!1===t||t?t:i})},M=new c;class ${constructor(e){let t,i;if(this.userCache=(new P).enclosedCache,this.defaultOptions={authorizationParams:{scope:"openid profile email"},useRefreshTokensFallback:!1,useFormData:!0},this._releaseLockOnPageHide=async()=>{await M.releaseLock("auth0.lock.getTokenSilently"),window.removeEventListener("pagehide",this._releaseLockOnPageHide)},this.options=Object.assign(Object.assign(Object.assign({},this.defaultOptions),e),{authorizationParams:Object.assign(Object.assign({},this.defaultOptions.authorizationParams),e.authorizationParams)}),"undefined"!=typeof window&&(()=>{if(!v())throw new Error("For security reasons, `window.crypto` is required to run `auth0-spa-js`.");if(void 0===v().subtle)throw new Error("\n auth0-spa-js must run on a secure origin. See https://github.com/auth0/auth0-spa-js/blob/main/FAQ.md#why-do-i-get-auth0-spa-js-must-run-on-a-secure-origin for more information.\n ")})(),e.cache&&e.cacheLocation&&console.warn("Both `cache` and `cacheLocation` options have been specified in the Auth0Client configuration; ignoring `cacheLocation` and using `cache`."),e.cache)i=e.cache;else{if(t=e.cacheLocation||"memory",!A(t))throw new Error(`Invalid cache location "${t}"`);i=A(t)()}this.httpTimeoutMs=e.httpTimeoutInSeconds?1e3*e.httpTimeoutInSeconds:1e4,this.cookieStorage=!1===e.legacySameSiteCookie?G:J,this.orgHintCookieName=`auth0.${this.options.clientId}.organization_hint`,this.isAuthenticatedCookieName=(e=>`auth0.${this.options.clientId}.is.authenticated`)(),this.sessionCheckExpiryDays=e.sessionCheckExpiryDays||1;const n=e.useCookiesForTransactions?this.cookieStorage:V;var o;this.scope=T("openid",this.options.authorizationParams.scope,this.options.useRefreshTokens?"offline_access":""),this.transactionManager=new X(n,this.options.clientId,this.options.cookieDomain),this.nowProvider=this.options.nowProvider||u,this.cacheManager=new z(i,i.allKeys?void 0:new F(i,this.options.clientId),this.nowProvider),this.domainUrl=(o=this.options.domain,/^https?:\/\//.test(o)?o:`https://${o}`),this.tokenIssuer=((e,t)=>e?e.startsWith("https://")?e:`https://${e}/`:`${t}/`)(this.options.issuer,this.domainUrl),"undefined"!=typeof window&&window.Worker&&this.options.useRefreshTokens&&"memory"===t&&(this.options.workerUrl?this.worker=new Worker(this.options.workerUrl):this.worker=new E)}_url(e){const t=encodeURIComponent(btoa(JSON.stringify(this.options.auth0Client||d)));return`${this.domainUrl}${e}&auth0Client=${t}`}_authorizeUrl(e){return this._url(`/authorize?${I(e)}`)}async _verifyIdToken(e,t,i){const n=await this.nowProvider();return(e=>{if(!e.id_token)throw new Error("ID token is required but missing");const t=(e=>{const t=e.split("."),[i,n,o]=t;if(3!==t.length||!i||!n||!o)throw new Error("ID token could not be decoded");const a=JSON.parse(S(n)),s={__raw:e},r={};return Object.keys(a).forEach((e=>{s[e]=a[e],R.includes(e)||(r[e]=a[e])})),{encoded:{header:i,payload:n,signature:o},header:JSON.parse(S(i)),claims:s,user:r}})(e.id_token);if(!t.claims.iss)throw new Error("Issuer (iss) claim must be a string present in the ID token");if(t.claims.iss!==e.iss)throw new Error(`Issuer (iss) claim mismatch in the ID token; expected "${e.iss}", found "${t.claims.iss}"`);if(!t.user.sub)throw new Error("Subject (sub) claim must be a string present in the ID token");if("RS256"!==t.header.alg)throw new Error(`Signature algorithm of "${t.header.alg}" is not supported. Expected the ID token to be signed with "RS256".`);if(!t.claims.aud||"string"!=typeof t.claims.aud&&!Array.isArray(t.claims.aud))throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token");if(Array.isArray(t.claims.aud)){if(!t.claims.aud.includes(e.aud))throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${e.aud}" but was not one of "${t.claims.aud.join(", ")}"`);if(t.claims.aud.length>1){if(!t.claims.azp)throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values");if(t.claims.azp!==e.aud)throw new Error(`Authorized Party (azp) claim mismatch in the ID token; expected "${e.aud}", found "${t.claims.azp}"`)}}else if(t.claims.aud!==e.aud)throw new Error(`Audience (aud) claim mismatch in the ID token; expected "${e.aud}" but found "${t.claims.aud}"`);if(e.nonce){if(!t.claims.nonce)throw new Error("Nonce (nonce) claim must be a string present in the ID token");if(t.claims.nonce!==e.nonce)throw new Error(`Nonce (nonce) claim mismatch in the ID token; expected "${e.nonce}", found "${t.claims.nonce}"`)}if(e.max_age&&!K(t.claims.auth_time))throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified");if(null==t.claims.exp||!K(t.claims.exp))throw new Error("Expiration Time (exp) claim must be a number present in the ID token");if(!K(t.claims.iat))throw new Error("Issued At (iat) claim must be a number present in the ID token");const i=e.leeway||60,n=new Date(e.now||Date.now()),o=new Date(0);if(o.setUTCSeconds(t.claims.exp+i),n>o)throw new Error(`Expiration Time (exp) claim error in the ID token; current time (${n}) is after expiration time (${o})`);if(null!=t.claims.nbf&&K(t.claims.nbf)){const e=new Date(0);if(e.setUTCSeconds(t.claims.nbf-i),n<e)throw new Error(`Not Before time (nbf) claim in the ID token indicates that this token can't be used just yet. Current time (${n}) is before ${e}`)}if(null!=t.claims.auth_time&&K(t.claims.auth_time)){const o=new Date(0);if(o.setUTCSeconds(parseInt(t.claims.auth_time)+e.max_age+i),n>o)throw new Error(`Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (${n}) is after last auth at ${o}`)}if(e.organization){const i=e.organization.trim();if(i.startsWith("org_")){const e=i;if(!t.claims.org_id)throw new Error("Organization ID (org_id) claim must be a string present in the ID token");if(e!==t.claims.org_id)throw new Error(`Organization ID (org_id) claim mismatch in the ID token; expected "${e}", found "${t.claims.org_id}"`)}else{const e=i.toLowerCase();if(!t.claims.org_name)throw new Error("Organization Name (org_name) claim must be a string present in the ID token");if(e!==t.claims.org_name)throw new Error(`Organization Name (org_name) claim mismatch in the ID token; expected "${e}", found "${t.claims.org_name}"`)}}return t})({iss:this.tokenIssuer,aud:this.options.clientId,id_token:e,nonce:t,organization:i,leeway:this.options.leeway,max_age:(o=this.options.authorizationParams.max_age,"string"!=typeof o?o:parseInt(o,10)||void 0),now:n});var o}_processOrgHint(e){e?this.cookieStorage.save(this.orgHintCookieName,e,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}):this.cookieStorage.remove(this.orgHintCookieName,{cookieDomain:this.options.cookieDomain})}async _prepareAuthorizeUrl(e,t,i){const n=_(k()),o=_(k()),a=k(),s=(e=>{const t=new Uint8Array(e);return(e=>{const t={"+":"-","/":"_","=":""};return e.replace(/[+/=]/g,(e=>t[e]))})(window.btoa(String.fromCharCode(...Array.from(t))))})(await(async e=>{const t=v().subtle.digest({name:"SHA-256"},(new TextEncoder).encode(e));return await t})(a)),r=((e,t,i,n,o,a,s,r)=>Object.assign(Object.assign(Object.assign({client_id:e.clientId},e.authorizationParams),i),{scope:T(t,i.scope),response_type:"code",response_mode:r||"query",state:n,nonce:o,redirect_uri:s||e.authorizationParams.redirect_uri,code_challenge:a,code_challenge_method:"S256"}))(this.options,this.scope,e,n,o,s,e.redirect_uri||this.options.authorizationParams.redirect_uri||i,null==t?void 0:t.response_mode),c=this._authorizeUrl(r);return{nonce:o,code_verifier:a,scope:r.scope,audience:r.audience||"default",redirect_uri:r.redirect_uri,state:n,url:c}}async loginWithPopup(e,t){var i;if(e=e||{},!(t=t||{}).popup&&(t.popup=(e=>{const t=window.screenX+(window.innerWidth-400)/2,i=window.screenY+(window.innerHeight-600)/2;return window.open("","auth0:authorize:popup",`left=${t},top=${i},width=400,height=600,resizable,scrollbars=yes,status=1`)})(),!t.popup))throw new Error("Unable to open a popup for loginWithPopup - window.open returned `null`");const n=await this._prepareAuthorizeUrl(e.authorizationParams||{},{response_mode:"web_message"},window.location.origin);t.popup.location.href=n.url;const o=await(e=>new Promise(((t,i)=>{let n;const o=setInterval((()=>{e.popup&&e.popup.closed&&(clearInterval(o),clearTimeout(a),window.removeEventListener("message",n,!1),i(new f(e.popup)))}),1e3),a=setTimeout((()=>{clearInterval(o),i(new g(e.popup)),window.removeEventListener("message",n,!1)}),1e3*(e.timeoutInSeconds||60));n=function(s){if(s.data&&"authorization_response"===s.data.type){if(clearTimeout(a),clearInterval(o),window.removeEventListener("message",n,!1),e.popup.close(),s.data.response.error)return i(h.fromPayload(s.data.response));t(s.data.response)}},window.addEventListener("message",n)})))(Object.assign(Object.assign({},t),{timeoutInSeconds:t.timeoutInSeconds||this.options.authorizeTimeoutInSeconds||60}));if(n.state!==o.state)throw new h("state_mismatch","Invalid state");const a=(null===(i=e.authorizationParams)||void 0===i?void 0:i.organization)||this.options.authorizationParams.organization;await this._requestToken({audience:n.audience,scope:n.scope,code_verifier:n.code_verifier,grant_type:"authorization_code",code:o.code,redirect_uri:n.redirect_uri},{nonceIn:n.nonce,organization:a})}async getUser(){var e;const t=await this._getIdTokenFromCache();return null===(e=null==t?void 0:t.decodedToken)||void 0===e?void 0:e.user}async getIdTokenClaims(){var e;const t=await this._getIdTokenFromCache();return null===(e=null==t?void 0:t.decodedToken)||void 0===e?void 0:e.claims}async loginWithRedirect(e={}){var t;const i=B(e),{openUrl:o,fragment:a,appState:s}=i,r=n(i,["openUrl","fragment","appState"]),c=(null===(t=r.authorizationParams)||void 0===t?void 0:t.organization)||this.options.authorizationParams.organization,l=await this._prepareAuthorizeUrl(r.authorizationParams||{}),{url:d}=l,u=n(l,["url"]);this.transactionManager.create(Object.assign(Object.assign(Object.assign({},u),{appState:s}),c&&{organization:c}));const h=a?`${d}#${a}`:d;o?await o(h):window.location.assign(h)}async handleRedirectCallback(e=window.location.href){const t=e.split("?").slice(1);if(0===t.length)throw new Error("There are no query params available for parsing.");const{state:i,code:n,error:o,error_description:a}=(e=>{e.indexOf("#")>-1&&(e=e.substring(0,e.indexOf("#")));const t=new URLSearchParams(e);return{state:t.get("state"),code:t.get("code")||void 0,error:t.get("error")||void 0,error_description:t.get("error_description")||void 0}})(t.join("")),s=this.transactionManager.get();if(!s)throw new h("missing_transaction","Invalid state");if(this.transactionManager.remove(),o)throw new p(o,a||o,i,s.appState);if(!s.code_verifier||s.state&&s.state!==i)throw new h("state_mismatch","Invalid state");const r=s.organization,c=s.nonce,l=s.redirect_uri;return await this._requestToken(Object.assign({audience:s.audience,scope:s.scope,code_verifier:s.code_verifier,grant_type:"authorization_code",code:n},l?{redirect_uri:l}:{}),{nonceIn:c,organization:r}),{appState:s.appState}}async checkSession(e){if(!this.cookieStorage.get(this.isAuthenticatedCookieName)){if(!this.cookieStorage.get("auth0.is.authenticated"))return;this.cookieStorage.save(this.isAuthenticatedCookieName,!0,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}),this.cookieStorage.remove("auth0.is.authenticated")}try{await this.getTokenSilently(e)}catch(e){}}async getTokenSilently(e={}){var t;const i=Object.assign(Object.assign({cacheMode:"on"},e),{authorizationParams:Object.assign(Object.assign(Object.assign({},this.options.authorizationParams),e.authorizationParams),{scope:T(this.scope,null===(t=e.authorizationParams)||void 0===t?void 0:t.scope)})}),n=await((e,t)=>{let i=H[t];return i||(i=e().finally((()=>{delete H[t],i=null})),H[t]=i),i})((()=>this._getTokenSilently(i)),`${this.options.clientId}::${i.authorizationParams.audience}::${i.authorizationParams.scope}`);return e.detailedResponse?n:null==n?void 0:n.access_token}async _getTokenSilently(e){const{cacheMode:t}=e,i=n(e,["cacheMode"]);if("off"!==t){const e=await this._getEntryFromCache({scope:i.authorizationParams.scope,audience:i.authorizationParams.audience||"default",clientId:this.options.clientId});if(e)return e}if("cache-only"!==t){if(!await(async(e,t=3)=>{for(let i=0;i<t;i++)if(await e())return!0;return!1})((()=>M.acquireLock("auth0.lock.getTokenSilently",5e3)),10))throw new m;try{if(window.addEventListener("pagehide",this._releaseLockOnPageHide),"off"!==t){const e=await this._getEntryFromCache({scope:i.authorizationParams.scope,audience:i.authorizationParams.audience||"default",clientId:this.options.clientId});if(e)return e}const e=this.options.useRefreshTokens?await this._getTokenUsingRefreshToken(i):await this._getTokenFromIFrame(i),{id_token:n,access_token:o,oauthTokenScope:a,expires_in:s}=e;return Object.assign(Object.assign({id_token:n,access_token:o},a?{scope:a}:null),{expires_in:s})}finally{await M.releaseLock("auth0.lock.getTokenSilently"),window.removeEventListener("pagehide",this._releaseLockOnPageHide)}}}async getTokenWithPopup(e={},t={}){var i;const n=Object.assign(Object.assign({},e),{authorizationParams:Object.assign(Object.assign(Object.assign({},this.options.authorizationParams),e.authorizationParams),{scope:T(this.scope,null===(i=e.authorizationParams)||void 0===i?void 0:i.scope)})});return t=Object.assign(Object.assign({},l),t),await this.loginWithPopup(n,t),(await this.cacheManager.get(new j({scope:n.authorizationParams.scope,audience:n.authorizationParams.audience||"default",clientId:this.options.clientId}))).access_token}async isAuthenticated(){return!!await this.getUser()}_buildLogoutUrl(e){null!==e.clientId?e.clientId=e.clientId||this.options.clientId:delete e.clientId;const t=e.logoutParams||{},{federated:i}=t,o=n(t,["federated"]),a=i?"&federated":"";return this._url(`/v2/logout?${I(Object.assign({clientId:e.clientId},o))}`)+a}async logout(e={}){const t=B(e),{openUrl:i}=t,o=n(t,["openUrl"]);null===e.clientId?await this.cacheManager.clear():await this.cacheManager.clear(e.clientId||this.options.clientId),this.cookieStorage.remove(this.orgHintCookieName,{cookieDomain:this.options.cookieDomain}),this.cookieStorage.remove(this.isAuthenticatedCookieName,{cookieDomain:this.options.cookieDomain}),this.userCache.remove("@@user@@");const a=this._buildLogoutUrl(o);i?await i(a):!1!==i&&window.location.assign(a)}async _getTokenFromIFrame(e){const t=Object.assign(Object.assign({},e.authorizationParams),{prompt:"none"}),i=this.cookieStorage.get(this.orgHintCookieName);i&&!t.organization&&(t.organization=i);const{url:n,state:o,nonce:a,code_verifier:s,redirect_uri:r,scope:c,audience:l}=await this._prepareAuthorizeUrl(t,{response_mode:"web_message"},window.location.origin);try{if(window.crossOriginIsolated)throw new h("login_required","The application is running in a Cross-Origin Isolated context, silently retrieving a token without refresh token is not possible.");const i=e.timeoutInSeconds||this.options.authorizeTimeoutInSeconds,d=await((e,t,i=60)=>new Promise(((n,o)=>{const a=window.document.createElement("iframe");a.setAttribute("width","0"),a.setAttribute("height","0"),a.style.display="none";const s=()=>{window.document.body.contains(a)&&(window.document.body.removeChild(a),window.removeEventListener("message",r,!1))};let r;const c=setTimeout((()=>{o(new m),s()}),1e3*i);r=function(e){if(e.origin!=t)return;if(!e.data||"authorization_response"!==e.data.type)return;const i=e.source;i&&i.close(),e.data.response.error?o(h.fromPayload(e.data.response)):n(e.data.response),clearTimeout(c),window.removeEventListener("message",r,!1),setTimeout(s,2e3)},window.addEventListener("message",r,!1),window.document.body.appendChild(a),a.setAttribute("src",e)})))(n,this.domainUrl,i);if(o!==d.state)throw new h("state_mismatch","Invalid state");const u=await this._requestToken(Object.assign(Object.assign({},e.authorizationParams),{code_verifier:s,code:d.code,grant_type:"authorization_code",redirect_uri:r,timeout:e.authorizationParams.timeout||this.httpTimeoutMs}),{nonceIn:a,organization:t.organization});return Object.assign(Object.assign({},u),{scope:c,oauthTokenScope:u.scope,audience:l})}catch(e){throw"login_required"===e.error&&this.logout({openUrl:!1}),e}}async _getTokenUsingRefreshToken(e){const t=await this.cacheManager.get(new j({scope:e.authorizationParams.scope,audience:e.authorizationParams.audience||"default",clientId:this.options.clientId}));if(!(t&&t.refresh_token||this.worker)){if(this.options.useRefreshTokensFallback)return await this._getTokenFromIFrame(e);throw new w(e.authorizationParams.audience||"default",e.authorizationParams.scope)}const i=e.authorizationParams.redirect_uri||this.options.authorizationParams.redirect_uri||window.location.origin,n="number"==typeof e.timeoutInSeconds?1e3*e.timeoutInSeconds:null;try{const o=await this._requestToken(Object.assign(Object.assign(Object.assign({},e.authorizationParams),{grant_type:"refresh_token",refresh_token:t&&t.refresh_token,redirect_uri:i}),n&&{timeout:n}));return Object.assign(Object.assign({},o),{scope:e.authorizationParams.scope,oauthTokenScope:o.scope,audience:e.authorizationParams.audience||"default"})}catch(t){if((t.message.indexOf("Missing Refresh Token")>-1||t.message&&t.message.indexOf("invalid refresh token")>-1)&&this.options.useRefreshTokensFallback)return await this._getTokenFromIFrame(e);throw t}}async _saveEntryInCache(e){const{id_token:t,decodedToken:i}=e,o=n(e,["id_token","decodedToken"]);this.userCache.set("@@user@@",{id_token:t,decodedToken:i}),await this.cacheManager.setIdToken(this.options.clientId,e.id_token,e.decodedToken),await this.cacheManager.set(o)}async _getIdTokenFromCache(){const e=this.options.authorizationParams.audience||"default",t=await this.cacheManager.getIdToken(new j({clientId:this.options.clientId,audience:e,scope:this.scope})),i=this.userCache.get("@@user@@");return t&&t.id_token===(null==i?void 0:i.id_token)?i:(this.userCache.set("@@user@@",t),t)}async _getEntryFromCache({scope:e,audience:t,clientId:i}){const n=await this.cacheManager.get(new j({scope:e,audience:t,clientId:i}),60);if(n&&n.access_token){const{access_token:e,oauthTokenScope:t,expires_in:i}=n,o=await this._getIdTokenFromCache();return o&&Object.assign(Object.assign({id_token:o.id_token,access_token:e},t?{scope:t}:null),{expires_in:i})}}async _requestToken(e,t){const{nonceIn:i,organization:n}=t||{},o=await C(Object.assign({baseUrl:this.domainUrl,client_id:this.options.clientId,auth0Client:this.options.auth0Client,useFormData:this.options.useFormData,timeout:this.httpTimeoutMs},e),this.worker),a=await this._verifyIdToken(o.id_token,i,n);return await this._saveEntryInCache(Object.assign(Object.assign(Object.assign(Object.assign({},o),{decodedToken:a,scope:e.scope,audience:e.audience||"default"}),o.scope?{oauthTokenScope:o.scope}:null),{client_id:this.options.clientId})),this.cookieStorage.save(this.isAuthenticatedCookieName,!0,{daysUntilExpire:this.sessionCheckExpiryDays,cookieDomain:this.options.cookieDomain}),this._processOrgHint(n||a.claims.org_id),Object.assign(Object.assign({},o),{decodedToken:a})}}function Q(t){return new Promise((i=>{!function(t,i){const n=e.watchEffect((()=>{t()&&(i(),n())}))}(t,i)}))}function q(e){(null==e?void 0:e.redirect_uri)&&(console.warn("Using `redirect_uri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version"),e.authorizationParams=e.authorizationParams||{},e.authorizationParams.redirect_uri=e.redirect_uri,delete e.redirect_uri)}const ee=()=>{console.error("Please ensure Auth0's Vue plugin is correctly installed.")},te={isLoading:e.ref(!1),isAuthenticated:e.ref(!1),user:e.ref(void 0),idTokenClaims:e.ref(void 0),error:e.ref(null),loginWithPopup:ee,loginWithRedirect:ee,getAccessTokenSilently:ee,getAccessTokenWithPopup:ee,logout:ee,checkSession:ee,handleRedirectCallback:ee},ie=e.ref(te);class ne{constructor(t,i){var n,o;this.clientOptions=t,this.pluginOptions=i,this.isLoading=e.ref(!0),this.isAuthenticated=e.ref(!1),this.user=e.ref({}),this.idTokenClaims=e.ref(),this.error=e.ref(null),n=this,o=["constructor"],Object.getOwnPropertyNames(Object.getPrototypeOf(n)).filter((e=>!o.includes(e))).forEach((e=>n[e]=n[e].bind(n)))}install(e){this._client=new $(Object.assign(Object.assign({},this.clientOptions),{auth0Client:{name:"auth0-vue",version:"2.3.1"}})),this.__checkSession(e.config.globalProperties.$router),e.config.globalProperties.$auth0=this,e.provide(i,this),ie.value=this}async loginWithRedirect(e){return q(e),this._client.loginWithRedirect(e)}async loginWithPopup(e,t){return q(e),this.__proxy((()=>this._client.loginWithPopup(e,t)))}async logout(e){return(null==e?void 0:e.openUrl)||!1===(null==e?void 0:e.openUrl)?this.__proxy((()=>this._client.logout(e))):this._client.logout(e)}async getAccessTokenSilently(e={}){return q(e),this.__proxy((()=>this._client.getTokenSilently(e)))}async getAccessTokenWithPopup(e,t){return q(e),this.__proxy((()=>this._client.getTokenWithPopup(e,t)))}async checkSession(e){return this.__proxy((()=>this._client.checkSession(e)))}async handleRedirectCallback(e){return this.__proxy((()=>this._client.handleRedirectCallback(e)))}async __checkSession(e){var t,i,n;const o=window.location.search;try{if((o.includes("code=")||o.includes("error="))&&o.includes("state=")&&!(null===(t=this.pluginOptions)||void 0===t?void 0:t.skipRedirectCallback)){const t=await this.handleRedirectCallback(),n=null==t?void 0:t.appState,o=null!==(i=null==n?void 0:n.target)&&void 0!==i?i:"/";return window.history.replaceState({},"","/"),e&&e.push(o),t}await this.checkSession()}catch(t){window.history.replaceState({},"","/"),e&&e.push((null===(n=this.pluginOptions)||void 0===n?void 0:n.errorPath)||"/")}}async __refreshState(){this.isAuthenticated.value=await this._client.isAuthenticated(),this.user.value=await this._client.getUser(),this.idTokenClaims.value=await this._client.getIdTokenClaims(),this.isLoading.value=!1}async __proxy(e,t=!0){let i;try{i=await e(),this.error.value=null}catch(e){throw this.error.value=e,e}finally{t&&await this.__refreshState()}return i}}async function oe(t,i,n){const o=async()=>!!e.unref(t.isAuthenticated)||(await t.loginWithRedirect(Object.assign({appState:{target:i.fullPath}},n)),!1);return e.unref(t.isLoading)?(await Q((()=>!e.unref(t.isLoading))),o()):o()}return Object.freeze({__proto__:null,createAuth0:function(e,t){return q(e),new ne(e,t)},useAuth0:function(){return e.inject(i)},AUTH0_INJECTION_KEY:i,Auth0Plugin:ne,User:class{},InMemoryCache:P,LocalStorageCache:O,createAuthGuard:function(t){const{app:i,redirectLoginOptions:n}=!t||"config"in t?{app:t,redirectLoginOptions:void 0}:t;return async t=>oe(i?i.config.globalProperties.$auth0:e.unref(ie),t,n)},authGuard:async function(t){return oe(e.unref(ie),t)}})})),"Auth0Client"in this&&this.console&&this.console.warn&&this.console.warn("Auth0Client already declared on the global namespace"),this&&this.vueAuth0&&(this.Auth0Client=this.Auth0Client||this.vueAuth0.Auth0Client);
//# sourceMappingURL=auth0-vue.production.js.map