Socket
Socket
Sign inDemoInstall

@auth0/auth0-spa-js

Package Overview
Dependencies
20
Maintainers
40
Versions
89
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1-alpha.17 to 0.0.1-alpha.18

dist/typings/src/Auth0Client.d.ts

100

dist/auth0-spa-js.development.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Auth0 = factory());
(global = global || self, global.createAuth0Client = factory());
}(this, function () { 'use strict';

@@ -964,19 +964,17 @@

class ClientStorage {
get(key) {
const value = esCookie_4(key);
if (typeof value === 'undefined') {
return;
}
return JSON.parse(value);
const get = (key) => {
const value = esCookie_4(key);
if (typeof value === 'undefined') {
return;
}
save(key, value, options) {
esCookie_5(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
}
remove(key) {
esCookie_6(key);
}
}
return JSON.parse(value);
};
const save = (key, value, options) => {
esCookie_5(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
};
const remove = (key) => {
esCookie_6(key);
};

@@ -986,8 +984,7 @@ const COOKIE_KEY = 'Auth0.login.transactions';

constructor() {
this.storage = new ClientStorage();
this.transactions = this.storage.get(COOKIE_KEY) || {};
this.transactions = get(COOKIE_KEY) || {};
}
create(transaction) {
this.transactions[transaction.state] = transaction;
this.storage.save(COOKIE_KEY, this.transactions, {
save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -1001,3 +998,3 @@ });

delete this.transactions[state];
this.storage.save(COOKIE_KEY, this.transactions, {
save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -1097,3 +1094,3 @@ });

*/
class Auth0 {
class Auth0Client {
constructor(options) {

@@ -1104,3 +1101,2 @@ this.options = options;

this.transactionManager = new TransactionManager();
this.storage = new ClientStorage();
this.domainUrl = `https://${this.options.domain}`;

@@ -1135,31 +1131,3 @@ }

/**
*
* ```js
* await auth0.init();
* ```
*
* `auth0.init` will detect if the current browser has previously
* logged in using this library by checking a cookie. In case this
* is true, fresh tokens (`id_token` and `access_token`) will be
* available to use.
*/
init() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.storage.get('auth0.is.authenticated')) {
return;
}
try {
yield this.getTokenSilently({
audience: this.options.audience,
scope: this.options.scope,
ignoreCache: true
});
}
catch (error) {
// don't care
}
});
}
/**
* ```js
* await auth0.loginWithPopup(options);

@@ -1200,3 +1168,3 @@ * ```

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
});

@@ -1303,3 +1271,3 @@ }

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return {

@@ -1364,3 +1332,3 @@ appState: transaction.appState

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return authResult.access_token;

@@ -1426,3 +1394,3 @@ });

}
this.storage.remove('auth0.is.authenticated');
remove('auth0.is.authenticated');
const url = this._url(`/v2/logout?${createQueryParams(options)}`);

@@ -1433,5 +1401,25 @@ window.location.assign(url);

return Auth0;
function createAuth0Client(options) {
return __awaiter(this, void 0, void 0, function* () {
const auth0 = new Auth0Client(options);
if (!get('auth0.is.authenticated')) {
return auth0;
}
try {
yield auth0.getTokenSilently({
audience: options.audience,
scope: options.scope,
ignoreCache: true
});
}
catch (error) {
// ignore
}
return auth0;
});
}
return createAuth0Client;
}));
//# sourceMappingURL=auth0-spa-js.development.js.map

@@ -1,2 +0,2 @@

function e(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&(r[i[o]]=e[i[o]])}return r}function t(e,t,r,i){return new(r||(r=Promise))(function(o,n){function a(e){try{c(i.next(e))}catch(e){n(e)}}function s(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){e.done?o(e.value):new r(function(t){t(e.value)}).then(a,s)}c((i=i.apply(e,t||[])).next())})}var r=Object.prototype.hasOwnProperty,i=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),o=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},i=0;i<e.length;++i)void 0!==e[i]&&(r[i]=e[i]);return r},n={arrayToObject:o,assign:function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],i=0;i<t.length;++i)for(var o=t[i],n=o.obj[o.prop],a=Object.keys(n),s=0;s<a.length;++s){var c=a[s],l=n[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:n,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(Array.isArray(r)){for(var i=[],o=0;o<r.length;++o)void 0!==r[o]&&i.push(r[o]);t.obj[t.prop]=i}}}(t),e},decode:function(e,t,r){var i=e.replace(/\+/g," ");if("iso-8859-1"===r)return i.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(i)}catch(e){return i}},encode:function(e,t,r){if(0===e.length)return e;var o="string"==typeof e?e:String(e);if("iso-8859-1"===r)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var n="",a=0;a<o.length;++a){var s=o.charCodeAt(a);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?n+=o.charAt(a):s<128?n+=i[s]:s<2048?n+=i[192|s>>6]+i[128|63&s]:s<55296||s>=57344?n+=i[224|s>>12]+i[128|s>>6&63]+i[128|63&s]:(a+=1,s=65536+((1023&s)<<10|1023&o.charCodeAt(a)),n+=i[240|s>>18]+i[128|s>>12&63]+i[128|s>>6&63]+i[128|63&s])}return n},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,i,n){if(!i)return t;if("object"!=typeof i){if(Array.isArray(t))t.push(i);else{if("object"!=typeof t)return[t,i];(n&&(n.plainObjects||n.allowPrototypes)||!r.call(Object.prototype,i))&&(t[i]=!0)}return t}if("object"!=typeof t)return[t].concat(i);var a=t;return Array.isArray(t)&&!Array.isArray(i)&&(a=o(t,n)),Array.isArray(t)&&Array.isArray(i)?(i.forEach(function(i,o){r.call(t,o)?t[o]&&"object"==typeof t[o]?t[o]=e(t[o],i,n):t.push(i):t[o]=i}),t):Object.keys(i).reduce(function(t,o){var a=i[o];return r.call(t,o)?t[o]=e(t[o],a,n):t[o]=a,t},a)}},a=String.prototype.replace,s=/%20/g,c={default:"RFC3986",formatters:{RFC1738:function(e){return a.call(e,s,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},l={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},d=Array.isArray,u=Array.prototype.push,p=function(e,t){u.apply(e,d(t)?t:[t])},h=Date.prototype.toISOString,f={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,indices:!1,serializeDate:function(e){return h.call(e)},skipNulls:!1,strictNullHandling:!1},y=function e(t,r,i,o,a,s,c,l,d,u,h,y,g){var m=t;if("function"==typeof c?m=c(r,m):m instanceof Date&&(m=u(m)),null===m){if(o)return s&&!y?s(r,f.encoder,g):r;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||n.isBuffer(m))return s?[h(y?r:s(r,f.encoder,g))+"="+h(s(m,f.encoder,g))]:[h(r)+"="+h(String(m))];var v,w=[];if(void 0===m)return w;if(Array.isArray(c))v=c;else{var b=Object.keys(m);v=l?b.sort(l):b}for(var _=0;_<v.length;++_){var O=v[_];a&&null===m[O]||(Array.isArray(m)?p(w,e(m[O],i(r,O),i,o,a,s,c,l,d,u,h,y,g)):p(w,e(m[O],r+(d?"."+O:"["+O+"]"),i,o,a,s,c,l,d,u,h,y,g)))}return w},g=Object.prototype.hasOwnProperty,m={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,decoder:n.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},v=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},w=function(e,t,r){if(e){var i=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/g,n=/(\[[^[\]]*])/.exec(i),a=n?i.slice(0,n.index):i,s=[];if(a){if(!r.plainObjects&&g.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var c=0;null!==(n=o.exec(i))&&c<r.depth;){if(c+=1,!r.plainObjects&&g.call(Object.prototype,n[1].slice(1,-1))&&!r.allowPrototypes)return;s.push(n[1])}return n&&s.push("["+i.slice(n.index)+"]"),function(e,t,r){for(var i=t,o=e.length-1;o>=0;--o){var n,a=e[o];if("[]"===a&&r.parseArrays)n=[].concat(i);else{n=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(s,10);r.parseArrays||""!==s?!isNaN(c)&&a!==s&&String(c)===s&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(n=[])[c]=i:n[s]=i:n={0:i}}i=n}return i}(s,t,r)}},b=function(e,t){var r=t?n.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||n.isRegExp(r.delimiter)?r.delimiter:m.delimiter,r.depth="number"==typeof r.depth?r.depth:m.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:m.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:m.decoder,r.allowDots=void 0===r.allowDots?m.allowDots:!!r.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:m.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:m.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:m.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:m.strictNullHandling,void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===r.charset&&(r.charset=m.charset),""===e||null==e)return r.plainObjects?Object.create(null):{};for(var i="string"==typeof e?function(e,t){var r,i={},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,a),c=-1,l=t.charset;if(t.charsetSentinel)for(r=0;r<s.length;++r)0===s[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===s[r]?l="utf-8":"utf8=%26%2310003%3B"===s[r]&&(l="iso-8859-1"),c=r,r=s.length);for(r=0;r<s.length;++r)if(r!==c){var d,u,p=s[r],h=p.indexOf("]="),f=-1===h?p.indexOf("="):h+1;-1===f?(d=t.decoder(p,m.decoder,l),u=t.strictNullHandling?null:""):(d=t.decoder(p.slice(0,f),m.decoder,l),u=t.decoder(p.slice(f+1),m.decoder,l)),u&&t.interpretNumericEntities&&"iso-8859-1"===l&&(u=v(u)),g.call(i,d)?i[d]=n.combine(i[d],u):i[d]=u}return i}(e,r):e,o=r.plainObjects?Object.create(null):{},a=Object.keys(i),s=0;s<a.length;++s){var c=a[s],l=w(c,i[c],r);o=n.merge(o,l,r)}return n.compact(o)},_=function(e,t){var r=e,i=t?n.assign({},t):{};if(null!==i.encoder&&void 0!==i.encoder&&"function"!=typeof i.encoder)throw new TypeError("Encoder has to be a function.");var o=void 0===i.delimiter?f.delimiter:i.delimiter,a="boolean"==typeof i.strictNullHandling?i.strictNullHandling:f.strictNullHandling,s="boolean"==typeof i.skipNulls?i.skipNulls:f.skipNulls,d="boolean"==typeof i.encode?i.encode:f.encode,u="function"==typeof i.encoder?i.encoder:f.encoder,h="function"==typeof i.sort?i.sort:null,g=void 0===i.allowDots?f.allowDots:!!i.allowDots,m="function"==typeof i.serializeDate?i.serializeDate:f.serializeDate,v="boolean"==typeof i.encodeValuesOnly?i.encodeValuesOnly:f.encodeValuesOnly,w=i.charset||f.charset;if(void 0!==i.charset&&"utf-8"!==i.charset&&"iso-8859-1"!==i.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===i.format)i.format=c.default;else if(!Object.prototype.hasOwnProperty.call(c.formatters,i.format))throw new TypeError("Unknown format option provided.");var b,_,O=c.formatters[i.format];"function"==typeof i.filter?r=(_=i.filter)("",r):Array.isArray(i.filter)&&(b=_=i.filter);var j,E=[];if("object"!=typeof r||null===r)return"";j=i.arrayFormat in l?i.arrayFormat:"indices"in i?i.indices?"indices":"repeat":"indices";var A=l[j];b||(b=Object.keys(r)),h&&b.sort(h);for(var C=0;C<b.length;++C){var S=b[C];s&&null===r[S]||p(E,y(r[S],S,A,a,s,d?u:null,_,h,g,m,O,v,w))}var U=E.join(o),x=!0===i.addQueryPrefix?"?":"";return i.charsetSentinel&&(x+="iso-8859-1"===w?"utf8=%26%2310003%3B&":"utf8=%E2%9C%93&"),U.length>0?x+U:""};const O={error:"timeout",error_description:"Timeout"},j=(...e)=>{const t=e.filter(Boolean).join();return Array.from(new Set(t.replace(/\s/g,",").split(","))).join(" ").trim()},E=e=>{var t=b(e);return Object.assign({},t,{expires_in:parseInt(t.expires_in)})},A=(e,t)=>new Promise((r,i)=>{var o=window.document.createElement("iframe");o.setAttribute("width","0"),o.setAttribute("height","0"),o.style.display="none";const n=setTimeout(()=>{i(O),window.document.body.removeChild(o)},6e4),a=function(e){e.origin==t&&e.data&&"authorization_response"===e.data.type&&(e.source.close(),e.data.response.error?i(e.data.response):r(e.data.response),clearTimeout(n),window.removeEventListener("message",a,!1),window.document.body.removeChild(o))};window.addEventListener("message",a,!1),window.document.body.appendChild(o),o.setAttribute("src",e)}),C=()=>{const e=window.open("","auth0:authorize:popup","left=100,top=100,width=400,height=600,resizable,scrollbars=yes,status=1");if(!e)throw new Error("Could not open popup");return e},S=(e,t)=>(e.location.href=t,new Promise((t,r)=>{const i=setTimeout(()=>{r(O)},6e4);window.addEventListener("message",o=>{if(o.data&&"authorization_response"===o.data.type){if(clearTimeout(i),e.close(),o.data.response.error)return r(o.data.response);t(o.data.response)}})})),U=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return crypto.getRandomValues(new Uint8Array(43)).forEach(r=>t+=e[r%e.length]),t},x=e=>btoa(e),T=e=>_(e),k=e=>window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(e)),P=e=>atob(e.replace(/_/g,"/").replace(/-/g,"+")),D=e=>(e=>{const t={"+":"-","/":"_","=":""};return e.replace(/[\+\/=]/g,e=>t[e])})(window.btoa(String.fromCharCode(...Array.from(new Uint8Array(e))))),L=r=>t(void 0,void 0,void 0,function*(){var{baseUrl:t}=r,i=e(r,["baseUrl"]);return yield fetch(`${t}/oauth/token`,{method:"POST",body:JSON.stringify(Object.assign({grant_type:"authorization_code",redirect_uri:window.location.origin},i)),headers:{"Content-type":"application/json"}}).then(e=>e.json())}),I=e=>`${e.audience}::${e.scope}`,N=(e,t)=>{const r=(new Date(1e3*t).getTime()-(new Date).getTime())/1e3;return 1e3*Math.min(e,r)};class R{constructor(){this.cache={}}save(e){const t=I(e);this.cache[t]=e;const r=N(e.expires_in,e.decodedToken.claims.exp);setTimeout(()=>{delete this.cache[t]},r)}get(e){return this.cache[I(e)]}}var F="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var z,B,H=(function(e,t){var r=F&&F.__assign||Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function i(e,t){if(!t)return"";var r="; "+e;return!0===t?r:r+"="+t}function o(e,t,r){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 i("Expires",e.expires?e.expires.toUTCString():"")+i("Domain",e.domain)+i("Path",e.path)+i("Secure",e.secure)+i("SameSite",e.sameSite)}(r)}function n(e){for(var t={},r=e?e.split("; "):[],i=/(%[0-9A-Z]{2})+/g,o=0;o<r.length;o++){var n=r[o].split("="),a=n.slice(1).join("=");'"'===a.charAt(0)&&(a=a.slice(1,-1));try{t[n[0].replace(i,decodeURIComponent)]=a.replace(i,decodeURIComponent)}catch(e){}}return t}function a(){return n(document.cookie)}function s(e,t,i){document.cookie=o(e,t,r({path:"/"},i))}t.__esModule=!0,t.encode=o,t.parse=n,t.getAll=a,t.get=function(e){return a()[e]},t.set=s,t.remove=function(e,t){s(e,"",r({},t,{expires:-1}))}}(z={exports:{}},z.exports),z.exports);(B=H)&&B.__esModule&&Object.prototype.hasOwnProperty.call(B,"default")&&B.default;H.encode,H.parse,H.getAll;var $=H.get,M=H.set,J=H.remove;class Q{get(e){const t=$(e);if(void 0!==t)return JSON.parse(t)}save(e,t,r){M(e,JSON.stringify(t),{expires:r.daysUntilExpire})}remove(e){J(e)}}const V="Auth0.login.transactions";class q{constructor(){this.storage=new Q,this.transactions=this.storage.get(V)||{}}create(e){this.transactions[e.state]=e,this.storage.save(V,this.transactions,{daysUntilExpire:1})}get(e){return this.transactions[e]}remove(e){delete this.transactions[e],this.storage.save(V,this.transactions,{daysUntilExpire:1})}}const W=["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"],Z=e=>{const t=(e=>{const[t,r,i]=e.split("."),o=JSON.parse(P(r)),n={},a={};return Object.keys(o).forEach(e=>{n[e]=o[e],W.includes(e)||(a[e]=o[e])}),{encoded:{header:t,payload:r,signature:i},header:JSON.parse(P(t)),claims:n,user:a}})(e.id_token);if(t.claims.iss!==e.iss)throw new Error("Invalid issuer");if(t.claims.aud!==e.aud)throw new Error("Invalid audience");if("RS256"!==t.header.alg)throw new Error("Invalid algorithm");if(t.claims.nonce!==e.nonce)throw new Error("Invalid nonce");const r=new Date,i=new Date(0),o=new Date(0),n=new Date(0),a=e.leeway||0;if(i.setUTCSeconds(t.claims.exp+a),o.setUTCSeconds(t.claims.iat-a),n.setUTCSeconds(t.claims.nbf-a),r>i)throw new Error("id_token expired");if(r<o)throw new Error("id_token was issued in the future (invalid iat)");if(void 0!==t.claims.nbf&&r<n)throw new Error("token is not yet valid (invalid notBefore)");return t};var G="0.0.1-alpha.17";export default class{constructor(e){this.options=e,this.DEFAULT_SCOPE="openid profile email",this.cache=new R,this.transactionManager=new q,this.storage=new Q,this.domainUrl=`https://${this.options.domain}`}_url(e){const t=encodeURIComponent(btoa(JSON.stringify({name:"@auth0/auth0-spa-js",version:G})));return`${this.domainUrl}${e}&auth0Client=${t}`}_getParams(t,r,i,o,n){const a=e(this.options,["domain"]);return Object.assign({},a,t,{scope:j(this.DEFAULT_SCOPE,this.options.scope,t.scope),response_type:"code",response_mode:"query",state:r,nonce:i,redirect_uri:n,code_challenge:o,code_challenge_method:"S256"})}_authorizeUrl(e){return this._url(`/authorize?${T(e)}`)}_verifyIdToken(e,t){return Z({iss:`${this.domainUrl}/`,aud:this.options.client_id,id_token:e,nonce:t,leeway:this.options.leeway})}init(){return t(this,void 0,void 0,function*(){if(this.storage.get("auth0.is.authenticated"))try{yield this.getTokenSilently({audience:this.options.audience,scope:this.options.scope,ignoreCache:!0})}catch(e){}})}loginWithPopup(r){return t(this,void 0,void 0,function*(){const t=yield C(),i=e(r,[]),o=x(U()),n=U(),a=U(),s=yield k(a),c=D(s),l=this._getParams(i,o,n,c,window.location.origin),d=this._authorizeUrl(Object.assign({},l,{response_mode:"web_message"})),u=yield S(t,d);if(o!==u.state)throw new Error("Invalid state");const p=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:a,code:u.code}),h=this._verifyIdToken(p.id_token,n),f=Object.assign({},p,{decodedToken:h,scope:l.scope,audience:l.audience||"default"});this.cache.save(f),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1})})}getUser(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.user})}getIdTokenClaims(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.claims})}loginWithRedirect(r){return t(this,void 0,void 0,function*(){const{redirect_uri:t,appState:i}=r,o=e(r,["redirect_uri","appState"]),n=x(U()),a=U(),s=U(),c=yield k(s),l=D(c),d=this._getParams(o,n,a,l,t),u=this._authorizeUrl(d);this.transactionManager.create({state:n,nonce:a,code_verifier:s,code_challenge:l,appState:i,scope:d.scope,audience:d.audience||"default"}),window.location.assign(u)})}handleRedirectCallback(){return t(this,void 0,void 0,function*(){if(!window.location.search)throw new Error("There are no query params available at `window.location.search`.");const e=E(window.location.search.substr(1)),t=this.transactionManager.get(e.state);if(!t)throw new Error("Invalid state");this.transactionManager.remove(e.state);const r=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:t.code_verifier,code:e.code}),i=this._verifyIdToken(r.id_token,t.nonce),o=Object.assign({},r,{decodedToken:i,audience:t.audience,scope:t.scope});return this.cache.save(o),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1}),{appState:t.appState}})}getTokenSilently(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE,ignoreCache:!1}){return t(this,void 0,void 0,function*(){if(e.scope=j(this.DEFAULT_SCOPE,e.scope),!e.ignoreCache){const t=this.cache.get({scope:e.scope,audience:e.audience||"default"});if(t)return t.access_token}const t=x(U()),r=U(),i=U(),o=yield k(i),n=D(o),a={audience:e.audience,scope:e.scope},s=this._getParams(a,t,r,n,window.location.origin),c=this._authorizeUrl(Object.assign({},s,{prompt:"none",response_mode:"web_message"})),l=yield A(c,this.domainUrl);if(t!==l.state)throw new Error("Invalid state");const d=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:i,code:l.code}),u=this._verifyIdToken(d.id_token,r),p=Object.assign({},d,{decodedToken:u,scope:s.scope,audience:s.audience||"default"});return this.cache.save(p),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1}),d.access_token})}getTokenWithPopup(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){return e.scope=j(this.DEFAULT_SCOPE,this.options.scope,e.scope),yield this.loginWithPopup(e),this.cache.get({scope:e.scope,audience:e.audience||"default"}).access_token})}isAuthenticated(){return t(this,void 0,void 0,function*(){return!!(yield this.getUser())})}logout(e={}){null!==e.client_id?e.client_id=e.client_id||this.options.client_id:delete e.client_id,this.storage.remove("auth0.is.authenticated");const t=this._url(`/v2/logout?${T(e)}`);window.location.assign(t)}}
function e(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[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&&(r[n[o]]=e[n[o]])}return r}function t(e,t,r,n){return new(r||(r=Promise))(function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){e.done?o(e.value):new r(function(t){t(e.value)}).then(a,s)}c((n=n.apply(e,t||[])).next())})}var r=Object.prototype.hasOwnProperty,n=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),o=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(r[n]=e[n]);return r},i={arrayToObject:o,assign:function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var o=t[n],i=o.obj[o.prop],a=Object.keys(i),s=0;s<a.length;++s){var c=a[s],l=i[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:i,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}}(t),e},decode:function(e,t,r){var n=e.replace(/\+/g," ");if("iso-8859-1"===r)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch(e){return n}},encode:function(e,t,r){if(0===e.length)return e;var o="string"==typeof e?e:String(e);if("iso-8859-1"===r)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var i="",a=0;a<o.length;++a){var s=o.charCodeAt(a);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?i+=o.charAt(a):s<128?i+=n[s]:s<2048?i+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?i+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(a+=1,s=65536+((1023&s)<<10|1023&o.charCodeAt(a)),i+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return i},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,n,i){if(!n)return t;if("object"!=typeof n){if(Array.isArray(t))t.push(n);else{if("object"!=typeof t)return[t,n];(i&&(i.plainObjects||i.allowPrototypes)||!r.call(Object.prototype,n))&&(t[n]=!0)}return t}if("object"!=typeof t)return[t].concat(n);var a=t;return Array.isArray(t)&&!Array.isArray(n)&&(a=o(t,i)),Array.isArray(t)&&Array.isArray(n)?(n.forEach(function(n,o){r.call(t,o)?t[o]&&"object"==typeof t[o]?t[o]=e(t[o],n,i):t.push(n):t[o]=n}),t):Object.keys(n).reduce(function(t,o){var a=n[o];return r.call(t,o)?t[o]=e(t[o],a,i):t[o]=a,t},a)}},a=String.prototype.replace,s=/%20/g,c={default:"RFC3986",formatters:{RFC1738:function(e){return a.call(e,s,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},l={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},d=Array.isArray,u=Array.prototype.push,p=function(e,t){u.apply(e,d(t)?t:[t])},f=Date.prototype.toISOString,h={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:i.encode,encodeValuesOnly:!1,indices:!1,serializeDate:function(e){return f.call(e)},skipNulls:!1,strictNullHandling:!1},y=function e(t,r,n,o,a,s,c,l,d,u,f,y,g){var m=t;if("function"==typeof c?m=c(r,m):m instanceof Date&&(m=u(m)),null===m){if(o)return s&&!y?s(r,h.encoder,g):r;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||i.isBuffer(m))return s?[f(y?r:s(r,h.encoder,g))+"="+f(s(m,h.encoder,g))]:[f(r)+"="+f(String(m))];var v,w=[];if(void 0===m)return w;if(Array.isArray(c))v=c;else{var b=Object.keys(m);v=l?b.sort(l):b}for(var _=0;_<v.length;++_){var O=v[_];a&&null===m[O]||(Array.isArray(m)?p(w,e(m[O],n(r,O),n,o,a,s,c,l,d,u,f,y,g)):p(w,e(m[O],r+(d?"."+O:"["+O+"]"),n,o,a,s,c,l,d,u,f,y,g)))}return w},g=Object.prototype.hasOwnProperty,m={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,decoder:i.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},v=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},w=function(e,t,r){if(e){var n=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(n),a=i?n.slice(0,i.index):n,s=[];if(a){if(!r.plainObjects&&g.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var c=0;null!==(i=o.exec(n))&&c<r.depth;){if(c+=1,!r.plainObjects&&g.call(Object.prototype,i[1].slice(1,-1))&&!r.allowPrototypes)return;s.push(i[1])}return i&&s.push("["+n.slice(i.index)+"]"),function(e,t,r){for(var n=t,o=e.length-1;o>=0;--o){var i,a=e[o];if("[]"===a&&r.parseArrays)i=[].concat(n);else{i=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(s,10);r.parseArrays||""!==s?!isNaN(c)&&a!==s&&String(c)===s&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(i=[])[c]=n:i[s]=n:i={0:n}}n=i}return n}(s,t,r)}},b=function(e,t){var r=t?i.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||i.isRegExp(r.delimiter)?r.delimiter:m.delimiter,r.depth="number"==typeof r.depth?r.depth:m.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:m.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:m.decoder,r.allowDots=void 0===r.allowDots?m.allowDots:!!r.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:m.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:m.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:m.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:m.strictNullHandling,void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===r.charset&&(r.charset=m.charset),""===e||null==e)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof e?function(e,t){var r,n={},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,a),c=-1,l=t.charset;if(t.charsetSentinel)for(r=0;r<s.length;++r)0===s[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===s[r]?l="utf-8":"utf8=%26%2310003%3B"===s[r]&&(l="iso-8859-1"),c=r,r=s.length);for(r=0;r<s.length;++r)if(r!==c){var d,u,p=s[r],f=p.indexOf("]="),h=-1===f?p.indexOf("="):f+1;-1===h?(d=t.decoder(p,m.decoder,l),u=t.strictNullHandling?null:""):(d=t.decoder(p.slice(0,h),m.decoder,l),u=t.decoder(p.slice(h+1),m.decoder,l)),u&&t.interpretNumericEntities&&"iso-8859-1"===l&&(u=v(u)),g.call(n,d)?n[d]=i.combine(n[d],u):n[d]=u}return n}(e,r):e,o=r.plainObjects?Object.create(null):{},a=Object.keys(n),s=0;s<a.length;++s){var c=a[s],l=w(c,n[c],r);o=i.merge(o,l,r)}return i.compact(o)},_=function(e,t){var r=e,n=t?i.assign({},t):{};if(null!==n.encoder&&void 0!==n.encoder&&"function"!=typeof n.encoder)throw new TypeError("Encoder has to be a function.");var o=void 0===n.delimiter?h.delimiter:n.delimiter,a="boolean"==typeof n.strictNullHandling?n.strictNullHandling:h.strictNullHandling,s="boolean"==typeof n.skipNulls?n.skipNulls:h.skipNulls,d="boolean"==typeof n.encode?n.encode:h.encode,u="function"==typeof n.encoder?n.encoder:h.encoder,f="function"==typeof n.sort?n.sort:null,g=void 0===n.allowDots?h.allowDots:!!n.allowDots,m="function"==typeof n.serializeDate?n.serializeDate:h.serializeDate,v="boolean"==typeof n.encodeValuesOnly?n.encodeValuesOnly:h.encodeValuesOnly,w=n.charset||h.charset;if(void 0!==n.charset&&"utf-8"!==n.charset&&"iso-8859-1"!==n.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===n.format)n.format=c.default;else if(!Object.prototype.hasOwnProperty.call(c.formatters,n.format))throw new TypeError("Unknown format option provided.");var b,_,O=c.formatters[n.format];"function"==typeof n.filter?r=(_=n.filter)("",r):Array.isArray(n.filter)&&(b=_=n.filter);var j,E=[];if("object"!=typeof r||null===r)return"";j=n.arrayFormat in l?n.arrayFormat:"indices"in n?n.indices?"indices":"repeat":"indices";var A=l[j];b||(b=Object.keys(r)),f&&b.sort(f);for(var C=0;C<b.length;++C){var S=b[C];s&&null===r[S]||p(E,y(r[S],S,A,a,s,d?u:null,_,f,g,m,O,v,w))}var U=E.join(o),x=!0===n.addQueryPrefix?"?":"";return n.charsetSentinel&&(x+="iso-8859-1"===w?"utf8=%26%2310003%3B&":"utf8=%E2%9C%93&"),U.length>0?x+U:""};const O={error:"timeout",error_description:"Timeout"},j=(...e)=>{const t=e.filter(Boolean).join();return Array.from(new Set(t.replace(/\s/g,",").split(","))).join(" ").trim()},E=e=>{var t=b(e);return Object.assign({},t,{expires_in:parseInt(t.expires_in)})},A=(e,t)=>new Promise((r,n)=>{var o=window.document.createElement("iframe");o.setAttribute("width","0"),o.setAttribute("height","0"),o.style.display="none";const i=setTimeout(()=>{n(O),window.document.body.removeChild(o)},6e4),a=function(e){e.origin==t&&e.data&&"authorization_response"===e.data.type&&(e.source.close(),e.data.response.error?n(e.data.response):r(e.data.response),clearTimeout(i),window.removeEventListener("message",a,!1),window.document.body.removeChild(o))};window.addEventListener("message",a,!1),window.document.body.appendChild(o),o.setAttribute("src",e)}),C=()=>{const e=window.open("","auth0:authorize:popup","left=100,top=100,width=400,height=600,resizable,scrollbars=yes,status=1");if(!e)throw new Error("Could not open popup");return e},S=(e,t)=>(e.location.href=t,new Promise((t,r)=>{const n=setTimeout(()=>{r(O)},6e4);window.addEventListener("message",o=>{if(o.data&&"authorization_response"===o.data.type){if(clearTimeout(n),e.close(),o.data.response.error)return r(o.data.response);t(o.data.response)}})})),U=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return crypto.getRandomValues(new Uint8Array(43)).forEach(r=>t+=e[r%e.length]),t},x=e=>btoa(e),T=e=>_(e),k=e=>window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(e)),P=e=>atob(e.replace(/_/g,"/").replace(/-/g,"+")),D=e=>(e=>{const t={"+":"-","/":"_","=":""};return e.replace(/[\+\/=]/g,e=>t[e])})(window.btoa(String.fromCharCode(...Array.from(new Uint8Array(e))))),L=r=>t(void 0,void 0,void 0,function*(){var{baseUrl:t}=r,n=e(r,["baseUrl"]);return yield fetch(`${t}/oauth/token`,{method:"POST",body:JSON.stringify(Object.assign({grant_type:"authorization_code",redirect_uri:window.location.origin},n)),headers:{"Content-type":"application/json"}}).then(e=>e.json())}),I=e=>`${e.audience}::${e.scope}`,N=(e,t)=>{const r=(new Date(1e3*t).getTime()-(new Date).getTime())/1e3;return 1e3*Math.min(e,r)};class R{constructor(){this.cache={}}save(e){const t=I(e);this.cache[t]=e;const r=N(e.expires_in,e.decodedToken.claims.exp);setTimeout(()=>{delete this.cache[t]},r)}get(e){return this.cache[I(e)]}}var F="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var z,B,H=(function(e,t){var r=F&&F.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function n(e,t){if(!t)return"";var r="; "+e;return!0===t?r:r+"="+t}function o(e,t,r){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)}(r)}function i(e){for(var t={},r=e?e.split("; "):[],n=/(%[0-9A-Z]{2})+/g,o=0;o<r.length;o++){var i=r[o].split("="),a=i.slice(1).join("=");'"'===a.charAt(0)&&(a=a.slice(1,-1));try{t[i[0].replace(n,decodeURIComponent)]=a.replace(n,decodeURIComponent)}catch(e){}}return t}function a(){return i(document.cookie)}function s(e,t,n){document.cookie=o(e,t,r({path:"/"},n))}t.__esModule=!0,t.encode=o,t.parse=i,t.getAll=a,t.get=function(e){return a()[e]},t.set=s,t.remove=function(e,t){s(e,"",r({},t,{expires:-1}))}}(z={exports:{}},z.exports),z.exports);(B=H)&&B.__esModule&&Object.prototype.hasOwnProperty.call(B,"default")&&B.default;H.encode,H.parse,H.getAll;var $=H.get,M=H.set,J=H.remove;const Q=e=>{const t=$(e);if(void 0!==t)return JSON.parse(t)},V=(e,t,r)=>{M(e,JSON.stringify(t),{expires:r.daysUntilExpire})},q=e=>{J(e)},W="Auth0.login.transactions";class Z{constructor(){this.transactions=Q(W)||{}}create(e){this.transactions[e.state]=e,V(W,this.transactions,{daysUntilExpire:1})}get(e){return this.transactions[e]}remove(e){delete this.transactions[e],V(W,this.transactions,{daysUntilExpire:1})}}const G=["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"],K=e=>{const t=(e=>{const[t,r,n]=e.split("."),o=JSON.parse(P(r)),i={},a={};return Object.keys(o).forEach(e=>{i[e]=o[e],G.includes(e)||(a[e]=o[e])}),{encoded:{header:t,payload:r,signature:n},header:JSON.parse(P(t)),claims:i,user:a}})(e.id_token);if(t.claims.iss!==e.iss)throw new Error("Invalid issuer");if(t.claims.aud!==e.aud)throw new Error("Invalid audience");if("RS256"!==t.header.alg)throw new Error("Invalid algorithm");if(t.claims.nonce!==e.nonce)throw new Error("Invalid nonce");const r=new Date,n=new Date(0),o=new Date(0),i=new Date(0),a=e.leeway||0;if(n.setUTCSeconds(t.claims.exp+a),o.setUTCSeconds(t.claims.iat-a),i.setUTCSeconds(t.claims.nbf-a),r>n)throw new Error("id_token expired");if(r<o)throw new Error("id_token was issued in the future (invalid iat)");if(void 0!==t.claims.nbf&&r<i)throw new Error("token is not yet valid (invalid notBefore)");return t};var X="0.0.1-alpha.17";class Y{constructor(e){this.options=e,this.DEFAULT_SCOPE="openid profile email",this.cache=new R,this.transactionManager=new Z,this.domainUrl=`https://${this.options.domain}`}_url(e){const t=encodeURIComponent(btoa(JSON.stringify({name:"@auth0/auth0-spa-js",version:X})));return`${this.domainUrl}${e}&auth0Client=${t}`}_getParams(t,r,n,o,i){const a=e(this.options,["domain"]);return Object.assign({},a,t,{scope:j(this.DEFAULT_SCOPE,this.options.scope,t.scope),response_type:"code",response_mode:"query",state:r,nonce:n,redirect_uri:i,code_challenge:o,code_challenge_method:"S256"})}_authorizeUrl(e){return this._url(`/authorize?${T(e)}`)}_verifyIdToken(e,t){return K({iss:`${this.domainUrl}/`,aud:this.options.client_id,id_token:e,nonce:t,leeway:this.options.leeway})}loginWithPopup(r){return t(this,void 0,void 0,function*(){const t=yield C(),n=e(r,[]),o=x(U()),i=U(),a=U(),s=yield k(a),c=D(s),l=this._getParams(n,o,i,c,window.location.origin),d=this._authorizeUrl(Object.assign({},l,{response_mode:"web_message"})),u=yield S(t,d);if(o!==u.state)throw new Error("Invalid state");const p=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:a,code:u.code}),f=this._verifyIdToken(p.id_token,i),h=Object.assign({},p,{decodedToken:f,scope:l.scope,audience:l.audience||"default"});this.cache.save(h),V("auth0.is.authenticated",!0,{daysUntilExpire:1})})}getUser(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.user})}getIdTokenClaims(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.claims})}loginWithRedirect(r){return t(this,void 0,void 0,function*(){const{redirect_uri:t,appState:n}=r,o=e(r,["redirect_uri","appState"]),i=x(U()),a=U(),s=U(),c=yield k(s),l=D(c),d=this._getParams(o,i,a,l,t),u=this._authorizeUrl(d);this.transactionManager.create({state:i,nonce:a,code_verifier:s,code_challenge:l,appState:n,scope:d.scope,audience:d.audience||"default"}),window.location.assign(u)})}handleRedirectCallback(){return t(this,void 0,void 0,function*(){if(!window.location.search)throw new Error("There are no query params available at `window.location.search`.");const e=E(window.location.search.substr(1)),t=this.transactionManager.get(e.state);if(!t)throw new Error("Invalid state");this.transactionManager.remove(e.state);const r=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:t.code_verifier,code:e.code}),n=this._verifyIdToken(r.id_token,t.nonce),o=Object.assign({},r,{decodedToken:n,audience:t.audience,scope:t.scope});return this.cache.save(o),V("auth0.is.authenticated",!0,{daysUntilExpire:1}),{appState:t.appState}})}getTokenSilently(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE,ignoreCache:!1}){return t(this,void 0,void 0,function*(){if(e.scope=j(this.DEFAULT_SCOPE,e.scope),!e.ignoreCache){const t=this.cache.get({scope:e.scope,audience:e.audience||"default"});if(t)return t.access_token}const t=x(U()),r=U(),n=U(),o=yield k(n),i=D(o),a={audience:e.audience,scope:e.scope},s=this._getParams(a,t,r,i,window.location.origin),c=this._authorizeUrl(Object.assign({},s,{prompt:"none",response_mode:"web_message"})),l=yield A(c,this.domainUrl);if(t!==l.state)throw new Error("Invalid state");const d=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:n,code:l.code}),u=this._verifyIdToken(d.id_token,r),p=Object.assign({},d,{decodedToken:u,scope:s.scope,audience:s.audience||"default"});return this.cache.save(p),V("auth0.is.authenticated",!0,{daysUntilExpire:1}),d.access_token})}getTokenWithPopup(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){return e.scope=j(this.DEFAULT_SCOPE,this.options.scope,e.scope),yield this.loginWithPopup(e),this.cache.get({scope:e.scope,audience:e.audience||"default"}).access_token})}isAuthenticated(){return t(this,void 0,void 0,function*(){return!!(yield this.getUser())})}logout(e={}){null!==e.client_id?e.client_id=e.client_id||this.options.client_id:delete e.client_id,q("auth0.is.authenticated");const t=this._url(`/v2/logout?${T(e)}`);window.location.assign(t)}}export default function(e){return t(this,void 0,void 0,function*(){const t=new Y(e);if(!Q("auth0.is.authenticated"))return t;try{yield t.getTokenSilently({audience:e.audience,scope:e.scope,ignoreCache:!0})}catch(e){}return t})}
//# sourceMappingURL=auth0-spa-js.production.esm.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Auth0=t()}(this,function(){"use strict";function e(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&(r[o[i]]=e[o[i]])}return r}function t(e,t,r,o){return new(r||(r=Promise))(function(i,n){function a(e){try{c(o.next(e))}catch(e){n(e)}}function s(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){e.done?i(e.value):new r(function(t){t(e.value)}).then(a,s)}c((o=o.apply(e,t||[])).next())})}var r=Object.prototype.hasOwnProperty,o=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),i=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},o=0;o<e.length;++o)void 0!==e[o]&&(r[o]=e[o]);return r},n={arrayToObject:i,assign:function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],o=0;o<t.length;++o)for(var i=t[o],n=i.obj[i.prop],a=Object.keys(n),s=0;s<a.length;++s){var c=a[s],d=n[c];"object"==typeof d&&null!==d&&-1===r.indexOf(d)&&(t.push({obj:n,prop:c}),r.push(d))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(Array.isArray(r)){for(var o=[],i=0;i<r.length;++i)void 0!==r[i]&&o.push(r[i]);t.obj[t.prop]=o}}}(t),e},decode:function(e,t,r){var o=e.replace(/\+/g," ");if("iso-8859-1"===r)return o.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(o)}catch(e){return o}},encode:function(e,t,r){if(0===e.length)return e;var i="string"==typeof e?e:String(e);if("iso-8859-1"===r)return escape(i).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var n="",a=0;a<i.length;++a){var s=i.charCodeAt(a);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?n+=i.charAt(a):s<128?n+=o[s]:s<2048?n+=o[192|s>>6]+o[128|63&s]:s<55296||s>=57344?n+=o[224|s>>12]+o[128|s>>6&63]+o[128|63&s]:(a+=1,s=65536+((1023&s)<<10|1023&i.charCodeAt(a)),n+=o[240|s>>18]+o[128|s>>12&63]+o[128|s>>6&63]+o[128|63&s])}return n},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,o,n){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if("object"!=typeof t)return[t,o];(n&&(n.plainObjects||n.allowPrototypes)||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if("object"!=typeof t)return[t].concat(o);var a=t;return Array.isArray(t)&&!Array.isArray(o)&&(a=i(t,n)),Array.isArray(t)&&Array.isArray(o)?(o.forEach(function(o,i){r.call(t,i)?t[i]&&"object"==typeof t[i]?t[i]=e(t[i],o,n):t.push(o):t[i]=o}),t):Object.keys(o).reduce(function(t,i){var a=o[i];return r.call(t,i)?t[i]=e(t[i],a,n):t[i]=a,t},a)}},a=String.prototype.replace,s=/%20/g,c={default:"RFC3986",formatters:{RFC1738:function(e){return a.call(e,s,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},d={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},l=Array.isArray,u=Array.prototype.push,p=function(e,t){u.apply(e,l(t)?t:[t])},h=Date.prototype.toISOString,f={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,indices:!1,serializeDate:function(e){return h.call(e)},skipNulls:!1,strictNullHandling:!1},y=function e(t,r,o,i,a,s,c,d,l,u,h,y,g){var m=t;if("function"==typeof c?m=c(r,m):m instanceof Date&&(m=u(m)),null===m){if(i)return s&&!y?s(r,f.encoder,g):r;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||n.isBuffer(m))return s?[h(y?r:s(r,f.encoder,g))+"="+h(s(m,f.encoder,g))]:[h(r)+"="+h(String(m))];var v,w=[];if(void 0===m)return w;if(Array.isArray(c))v=c;else{var b=Object.keys(m);v=d?b.sort(d):b}for(var _=0;_<v.length;++_){var O=v[_];a&&null===m[O]||(Array.isArray(m)?p(w,e(m[O],o(r,O),o,i,a,s,c,d,l,u,h,y,g)):p(w,e(m[O],r+(l?"."+O:"["+O+"]"),o,i,a,s,c,d,l,u,h,y,g)))}return w},g=Object.prototype.hasOwnProperty,m={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,decoder:n.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},v=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},w=function(e,t,r){if(e){var o=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,n=/(\[[^[\]]*])/.exec(o),a=n?o.slice(0,n.index):o,s=[];if(a){if(!r.plainObjects&&g.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var c=0;null!==(n=i.exec(o))&&c<r.depth;){if(c+=1,!r.plainObjects&&g.call(Object.prototype,n[1].slice(1,-1))&&!r.allowPrototypes)return;s.push(n[1])}return n&&s.push("["+o.slice(n.index)+"]"),function(e,t,r){for(var o=t,i=e.length-1;i>=0;--i){var n,a=e[i];if("[]"===a&&r.parseArrays)n=[].concat(o);else{n=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(s,10);r.parseArrays||""!==s?!isNaN(c)&&a!==s&&String(c)===s&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(n=[])[c]=o:n[s]=o:n={0:o}}o=n}return o}(s,t,r)}},b=function(e,t){var r=t?n.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||n.isRegExp(r.delimiter)?r.delimiter:m.delimiter,r.depth="number"==typeof r.depth?r.depth:m.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:m.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:m.decoder,r.allowDots=void 0===r.allowDots?m.allowDots:!!r.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:m.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:m.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:m.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:m.strictNullHandling,void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===r.charset&&(r.charset=m.charset),""===e||null==e)return r.plainObjects?Object.create(null):{};for(var o="string"==typeof e?function(e,t){var r,o={},i=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=t.parameterLimit===1/0?void 0:t.parameterLimit,s=i.split(t.delimiter,a),c=-1,d=t.charset;if(t.charsetSentinel)for(r=0;r<s.length;++r)0===s[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===s[r]?d="utf-8":"utf8=%26%2310003%3B"===s[r]&&(d="iso-8859-1"),c=r,r=s.length);for(r=0;r<s.length;++r)if(r!==c){var l,u,p=s[r],h=p.indexOf("]="),f=-1===h?p.indexOf("="):h+1;-1===f?(l=t.decoder(p,m.decoder,d),u=t.strictNullHandling?null:""):(l=t.decoder(p.slice(0,f),m.decoder,d),u=t.decoder(p.slice(f+1),m.decoder,d)),u&&t.interpretNumericEntities&&"iso-8859-1"===d&&(u=v(u)),g.call(o,l)?o[l]=n.combine(o[l],u):o[l]=u}return o}(e,r):e,i=r.plainObjects?Object.create(null):{},a=Object.keys(o),s=0;s<a.length;++s){var c=a[s],d=w(c,o[c],r);i=n.merge(i,d,r)}return n.compact(i)},_=function(e,t){var r=e,o=t?n.assign({},t):{};if(null!==o.encoder&&void 0!==o.encoder&&"function"!=typeof o.encoder)throw new TypeError("Encoder has to be a function.");var i=void 0===o.delimiter?f.delimiter:o.delimiter,a="boolean"==typeof o.strictNullHandling?o.strictNullHandling:f.strictNullHandling,s="boolean"==typeof o.skipNulls?o.skipNulls:f.skipNulls,l="boolean"==typeof o.encode?o.encode:f.encode,u="function"==typeof o.encoder?o.encoder:f.encoder,h="function"==typeof o.sort?o.sort:null,g=void 0===o.allowDots?f.allowDots:!!o.allowDots,m="function"==typeof o.serializeDate?o.serializeDate:f.serializeDate,v="boolean"==typeof o.encodeValuesOnly?o.encodeValuesOnly:f.encodeValuesOnly,w=o.charset||f.charset;if(void 0!==o.charset&&"utf-8"!==o.charset&&"iso-8859-1"!==o.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===o.format)o.format=c.default;else if(!Object.prototype.hasOwnProperty.call(c.formatters,o.format))throw new TypeError("Unknown format option provided.");var b,_,O=c.formatters[o.format];"function"==typeof o.filter?r=(_=o.filter)("",r):Array.isArray(o.filter)&&(b=_=o.filter);var j,E=[];if("object"!=typeof r||null===r)return"";j=o.arrayFormat in d?o.arrayFormat:"indices"in o?o.indices?"indices":"repeat":"indices";var A=d[j];b||(b=Object.keys(r)),h&&b.sort(h);for(var C=0;C<b.length;++C){var S=b[C];s&&null===r[S]||p(E,y(r[S],S,A,a,s,l?u:null,_,h,g,m,O,v,w))}var U=E.join(i),x=!0===o.addQueryPrefix?"?":"";return o.charsetSentinel&&(x+="iso-8859-1"===w?"utf8=%26%2310003%3B&":"utf8=%E2%9C%93&"),U.length>0?x+U:""};const O={error:"timeout",error_description:"Timeout"},j=(...e)=>{const t=e.filter(Boolean).join();return Array.from(new Set(t.replace(/\s/g,",").split(","))).join(" ").trim()},E=e=>{var t=b(e);return Object.assign({},t,{expires_in:parseInt(t.expires_in)})},A=(e,t)=>new Promise((r,o)=>{var i=window.document.createElement("iframe");i.setAttribute("width","0"),i.setAttribute("height","0"),i.style.display="none";const n=setTimeout(()=>{o(O),window.document.body.removeChild(i)},6e4),a=function(e){e.origin==t&&e.data&&"authorization_response"===e.data.type&&(e.source.close(),e.data.response.error?o(e.data.response):r(e.data.response),clearTimeout(n),window.removeEventListener("message",a,!1),window.document.body.removeChild(i))};window.addEventListener("message",a,!1),window.document.body.appendChild(i),i.setAttribute("src",e)}),C=()=>{const e=window.open("","auth0:authorize:popup","left=100,top=100,width=400,height=600,resizable,scrollbars=yes,status=1");if(!e)throw new Error("Could not open popup");return e},S=(e,t)=>(e.location.href=t,new Promise((t,r)=>{const o=setTimeout(()=>{r(O)},6e4);window.addEventListener("message",i=>{if(i.data&&"authorization_response"===i.data.type){if(clearTimeout(o),e.close(),i.data.response.error)return r(i.data.response);t(i.data.response)}})})),U=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return crypto.getRandomValues(new Uint8Array(43)).forEach(r=>t+=e[r%e.length]),t},x=e=>btoa(e),T=e=>_(e),k=e=>window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(e)),P=e=>atob(e.replace(/_/g,"/").replace(/-/g,"+")),D=e=>(e=>{const t={"+":"-","/":"_","=":""};return e.replace(/[\+\/=]/g,e=>t[e])})(window.btoa(String.fromCharCode(...Array.from(new Uint8Array(e))))),L=r=>t(void 0,void 0,void 0,function*(){var{baseUrl:t}=r,o=e(r,["baseUrl"]);return yield fetch(`${t}/oauth/token`,{method:"POST",body:JSON.stringify(Object.assign({grant_type:"authorization_code",redirect_uri:window.location.origin},o)),headers:{"Content-type":"application/json"}}).then(e=>e.json())}),I=e=>`${e.audience}::${e.scope}`,N=(e,t)=>{const r=(new Date(1e3*t).getTime()-(new Date).getTime())/1e3;return 1e3*Math.min(e,r)};class R{constructor(){this.cache={}}save(e){const t=I(e);this.cache[t]=e;const r=N(e.expires_in,e.decodedToken.claims.exp);setTimeout(()=>{delete this.cache[t]},r)}get(e){return this.cache[I(e)]}}var F="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var z,B,H=(function(e,t){var r=F&&F.__assign||Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e};function o(e,t){if(!t)return"";var r="; "+e;return!0===t?r:r+"="+t}function i(e,t,r){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 o("Expires",e.expires?e.expires.toUTCString():"")+o("Domain",e.domain)+o("Path",e.path)+o("Secure",e.secure)+o("SameSite",e.sameSite)}(r)}function n(e){for(var t={},r=e?e.split("; "):[],o=/(%[0-9A-Z]{2})+/g,i=0;i<r.length;i++){var n=r[i].split("="),a=n.slice(1).join("=");'"'===a.charAt(0)&&(a=a.slice(1,-1));try{t[n[0].replace(o,decodeURIComponent)]=a.replace(o,decodeURIComponent)}catch(e){}}return t}function a(){return n(document.cookie)}function s(e,t,o){document.cookie=i(e,t,r({path:"/"},o))}t.__esModule=!0,t.encode=i,t.parse=n,t.getAll=a,t.get=function(e){return a()[e]},t.set=s,t.remove=function(e,t){s(e,"",r({},t,{expires:-1}))}}(z={exports:{}},z.exports),z.exports);(B=H)&&B.__esModule&&Object.prototype.hasOwnProperty.call(B,"default")&&B.default;H.encode,H.parse,H.getAll;var $=H.get,M=H.set,J=H.remove;class Q{get(e){const t=$(e);if(void 0!==t)return JSON.parse(t)}save(e,t,r){M(e,JSON.stringify(t),{expires:r.daysUntilExpire})}remove(e){J(e)}}const V="Auth0.login.transactions";class q{constructor(){this.storage=new Q,this.transactions=this.storage.get(V)||{}}create(e){this.transactions[e.state]=e,this.storage.save(V,this.transactions,{daysUntilExpire:1})}get(e){return this.transactions[e]}remove(e){delete this.transactions[e],this.storage.save(V,this.transactions,{daysUntilExpire:1})}}const W=["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"],Z=e=>{const t=(e=>{const[t,r,o]=e.split("."),i=JSON.parse(P(r)),n={},a={};return Object.keys(i).forEach(e=>{n[e]=i[e],W.includes(e)||(a[e]=i[e])}),{encoded:{header:t,payload:r,signature:o},header:JSON.parse(P(t)),claims:n,user:a}})(e.id_token);if(t.claims.iss!==e.iss)throw new Error("Invalid issuer");if(t.claims.aud!==e.aud)throw new Error("Invalid audience");if("RS256"!==t.header.alg)throw new Error("Invalid algorithm");if(t.claims.nonce!==e.nonce)throw new Error("Invalid nonce");const r=new Date,o=new Date(0),i=new Date(0),n=new Date(0),a=e.leeway||0;if(o.setUTCSeconds(t.claims.exp+a),i.setUTCSeconds(t.claims.iat-a),n.setUTCSeconds(t.claims.nbf-a),r>o)throw new Error("id_token expired");if(r<i)throw new Error("id_token was issued in the future (invalid iat)");if(void 0!==t.claims.nbf&&r<n)throw new Error("token is not yet valid (invalid notBefore)");return t};var G="0.0.1-alpha.17";return class{constructor(e){this.options=e,this.DEFAULT_SCOPE="openid profile email",this.cache=new R,this.transactionManager=new q,this.storage=new Q,this.domainUrl=`https://${this.options.domain}`}_url(e){const t=encodeURIComponent(btoa(JSON.stringify({name:"@auth0/auth0-spa-js",version:G})));return`${this.domainUrl}${e}&auth0Client=${t}`}_getParams(t,r,o,i,n){const a=e(this.options,["domain"]);return Object.assign({},a,t,{scope:j(this.DEFAULT_SCOPE,this.options.scope,t.scope),response_type:"code",response_mode:"query",state:r,nonce:o,redirect_uri:n,code_challenge:i,code_challenge_method:"S256"})}_authorizeUrl(e){return this._url(`/authorize?${T(e)}`)}_verifyIdToken(e,t){return Z({iss:`${this.domainUrl}/`,aud:this.options.client_id,id_token:e,nonce:t,leeway:this.options.leeway})}init(){return t(this,void 0,void 0,function*(){if(this.storage.get("auth0.is.authenticated"))try{yield this.getTokenSilently({audience:this.options.audience,scope:this.options.scope,ignoreCache:!0})}catch(e){}})}loginWithPopup(r){return t(this,void 0,void 0,function*(){const t=yield C(),o=e(r,[]),i=x(U()),n=U(),a=U(),s=yield k(a),c=D(s),d=this._getParams(o,i,n,c,window.location.origin),l=this._authorizeUrl(Object.assign({},d,{response_mode:"web_message"})),u=yield S(t,l);if(i!==u.state)throw new Error("Invalid state");const p=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:a,code:u.code}),h=this._verifyIdToken(p.id_token,n),f=Object.assign({},p,{decodedToken:h,scope:d.scope,audience:d.audience||"default"});this.cache.save(f),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1})})}getUser(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.user})}getIdTokenClaims(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.claims})}loginWithRedirect(r){return t(this,void 0,void 0,function*(){const{redirect_uri:t,appState:o}=r,i=e(r,["redirect_uri","appState"]),n=x(U()),a=U(),s=U(),c=yield k(s),d=D(c),l=this._getParams(i,n,a,d,t),u=this._authorizeUrl(l);this.transactionManager.create({state:n,nonce:a,code_verifier:s,code_challenge:d,appState:o,scope:l.scope,audience:l.audience||"default"}),window.location.assign(u)})}handleRedirectCallback(){return t(this,void 0,void 0,function*(){if(!window.location.search)throw new Error("There are no query params available at `window.location.search`.");const e=E(window.location.search.substr(1)),t=this.transactionManager.get(e.state);if(!t)throw new Error("Invalid state");this.transactionManager.remove(e.state);const r=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:t.code_verifier,code:e.code}),o=this._verifyIdToken(r.id_token,t.nonce),i=Object.assign({},r,{decodedToken:o,audience:t.audience,scope:t.scope});return this.cache.save(i),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1}),{appState:t.appState}})}getTokenSilently(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE,ignoreCache:!1}){return t(this,void 0,void 0,function*(){if(e.scope=j(this.DEFAULT_SCOPE,e.scope),!e.ignoreCache){const t=this.cache.get({scope:e.scope,audience:e.audience||"default"});if(t)return t.access_token}const t=x(U()),r=U(),o=U(),i=yield k(o),n=D(i),a={audience:e.audience,scope:e.scope},s=this._getParams(a,t,r,n,window.location.origin),c=this._authorizeUrl(Object.assign({},s,{prompt:"none",response_mode:"web_message"})),d=yield A(c,this.domainUrl);if(t!==d.state)throw new Error("Invalid state");const l=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:o,code:d.code}),u=this._verifyIdToken(l.id_token,r),p=Object.assign({},l,{decodedToken:u,scope:s.scope,audience:s.audience||"default"});return this.cache.save(p),this.storage.save("auth0.is.authenticated",!0,{daysUntilExpire:1}),l.access_token})}getTokenWithPopup(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){return e.scope=j(this.DEFAULT_SCOPE,this.options.scope,e.scope),yield this.loginWithPopup(e),this.cache.get({scope:e.scope,audience:e.audience||"default"}).access_token})}isAuthenticated(){return t(this,void 0,void 0,function*(){return!!(yield this.getUser())})}logout(e={}){null!==e.client_id?e.client_id=e.client_id||this.options.client_id:delete e.client_id,this.storage.remove("auth0.is.authenticated");const t=this._url(`/v2/logout?${T(e)}`);window.location.assign(t)}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).createAuth0Client=t()}(this,function(){"use strict";function e(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[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&&(r[n[o]]=e[n[o]])}return r}function t(e,t,r,n){return new(r||(r=Promise))(function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){e.done?o(e.value):new r(function(t){t(e.value)}).then(a,s)}c((n=n.apply(e,t||[])).next())})}var r=Object.prototype.hasOwnProperty,n=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),o=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(r[n]=e[n]);return r},i={arrayToObject:o,assign:function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],n=0;n<t.length;++n)for(var o=t[n],i=o.obj[o.prop],a=Object.keys(i),s=0;s<a.length;++s){var c=a[s],d=i[c];"object"==typeof d&&null!==d&&-1===r.indexOf(d)&&(t.push({obj:i,prop:c}),r.push(d))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}}(t),e},decode:function(e,t,r){var n=e.replace(/\+/g," ");if("iso-8859-1"===r)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch(e){return n}},encode:function(e,t,r){if(0===e.length)return e;var o="string"==typeof e?e:String(e);if("iso-8859-1"===r)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var i="",a=0;a<o.length;++a){var s=o.charCodeAt(a);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?i+=o.charAt(a):s<128?i+=n[s]:s<2048?i+=n[192|s>>6]+n[128|63&s]:s<55296||s>=57344?i+=n[224|s>>12]+n[128|s>>6&63]+n[128|63&s]:(a+=1,s=65536+((1023&s)<<10|1023&o.charCodeAt(a)),i+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|63&s])}return i},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,n,i){if(!n)return t;if("object"!=typeof n){if(Array.isArray(t))t.push(n);else{if("object"!=typeof t)return[t,n];(i&&(i.plainObjects||i.allowPrototypes)||!r.call(Object.prototype,n))&&(t[n]=!0)}return t}if("object"!=typeof t)return[t].concat(n);var a=t;return Array.isArray(t)&&!Array.isArray(n)&&(a=o(t,i)),Array.isArray(t)&&Array.isArray(n)?(n.forEach(function(n,o){r.call(t,o)?t[o]&&"object"==typeof t[o]?t[o]=e(t[o],n,i):t.push(n):t[o]=n}),t):Object.keys(n).reduce(function(t,o){var a=n[o];return r.call(t,o)?t[o]=e(t[o],a,i):t[o]=a,t},a)}},a=String.prototype.replace,s=/%20/g,c={default:"RFC3986",formatters:{RFC1738:function(e){return a.call(e,s,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},d={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},l=Array.isArray,u=Array.prototype.push,p=function(e,t){u.apply(e,l(t)?t:[t])},f=Date.prototype.toISOString,h={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:i.encode,encodeValuesOnly:!1,indices:!1,serializeDate:function(e){return f.call(e)},skipNulls:!1,strictNullHandling:!1},y=function e(t,r,n,o,a,s,c,d,l,u,f,y,m){var g=t;if("function"==typeof c?g=c(r,g):g instanceof Date&&(g=u(g)),null===g){if(o)return s&&!y?s(r,h.encoder,m):r;g=""}if("string"==typeof g||"number"==typeof g||"boolean"==typeof g||i.isBuffer(g))return s?[f(y?r:s(r,h.encoder,m))+"="+f(s(g,h.encoder,m))]:[f(r)+"="+f(String(g))];var v,w=[];if(void 0===g)return w;if(Array.isArray(c))v=c;else{var b=Object.keys(g);v=d?b.sort(d):b}for(var _=0;_<v.length;++_){var O=v[_];a&&null===g[O]||(Array.isArray(g)?p(w,e(g[O],n(r,O),n,o,a,s,c,d,l,u,f,y,m)):p(w,e(g[O],r+(l?"."+O:"["+O+"]"),n,o,a,s,c,d,l,u,f,y,m)))}return w},m=Object.prototype.hasOwnProperty,g={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,decoder:i.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},v=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},w=function(e,t,r){if(e){var n=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(n),a=i?n.slice(0,i.index):n,s=[];if(a){if(!r.plainObjects&&m.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var c=0;null!==(i=o.exec(n))&&c<r.depth;){if(c+=1,!r.plainObjects&&m.call(Object.prototype,i[1].slice(1,-1))&&!r.allowPrototypes)return;s.push(i[1])}return i&&s.push("["+n.slice(i.index)+"]"),function(e,t,r){for(var n=t,o=e.length-1;o>=0;--o){var i,a=e[o];if("[]"===a&&r.parseArrays)i=[].concat(n);else{i=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(s,10);r.parseArrays||""!==s?!isNaN(c)&&a!==s&&String(c)===s&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(i=[])[c]=n:i[s]=n:i={0:n}}n=i}return n}(s,t,r)}},b=function(e,t){var r=t?i.assign({},t):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||i.isRegExp(r.delimiter)?r.delimiter:g.delimiter,r.depth="number"==typeof r.depth?r.depth:g.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:g.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:g.decoder,r.allowDots=void 0===r.allowDots?g.allowDots:!!r.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:g.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:g.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:g.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:g.strictNullHandling,void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===r.charset&&(r.charset=g.charset),""===e||null==e)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof e?function(e,t){var r,n={},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,a),c=-1,d=t.charset;if(t.charsetSentinel)for(r=0;r<s.length;++r)0===s[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===s[r]?d="utf-8":"utf8=%26%2310003%3B"===s[r]&&(d="iso-8859-1"),c=r,r=s.length);for(r=0;r<s.length;++r)if(r!==c){var l,u,p=s[r],f=p.indexOf("]="),h=-1===f?p.indexOf("="):f+1;-1===h?(l=t.decoder(p,g.decoder,d),u=t.strictNullHandling?null:""):(l=t.decoder(p.slice(0,h),g.decoder,d),u=t.decoder(p.slice(h+1),g.decoder,d)),u&&t.interpretNumericEntities&&"iso-8859-1"===d&&(u=v(u)),m.call(n,l)?n[l]=i.combine(n[l],u):n[l]=u}return n}(e,r):e,o=r.plainObjects?Object.create(null):{},a=Object.keys(n),s=0;s<a.length;++s){var c=a[s],d=w(c,n[c],r);o=i.merge(o,d,r)}return i.compact(o)},_=function(e,t){var r=e,n=t?i.assign({},t):{};if(null!==n.encoder&&void 0!==n.encoder&&"function"!=typeof n.encoder)throw new TypeError("Encoder has to be a function.");var o=void 0===n.delimiter?h.delimiter:n.delimiter,a="boolean"==typeof n.strictNullHandling?n.strictNullHandling:h.strictNullHandling,s="boolean"==typeof n.skipNulls?n.skipNulls:h.skipNulls,l="boolean"==typeof n.encode?n.encode:h.encode,u="function"==typeof n.encoder?n.encoder:h.encoder,f="function"==typeof n.sort?n.sort:null,m=void 0===n.allowDots?h.allowDots:!!n.allowDots,g="function"==typeof n.serializeDate?n.serializeDate:h.serializeDate,v="boolean"==typeof n.encodeValuesOnly?n.encodeValuesOnly:h.encodeValuesOnly,w=n.charset||h.charset;if(void 0!==n.charset&&"utf-8"!==n.charset&&"iso-8859-1"!==n.charset)throw new Error("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0===n.format)n.format=c.default;else if(!Object.prototype.hasOwnProperty.call(c.formatters,n.format))throw new TypeError("Unknown format option provided.");var b,_,O=c.formatters[n.format];"function"==typeof n.filter?r=(_=n.filter)("",r):Array.isArray(n.filter)&&(b=_=n.filter);var j,E=[];if("object"!=typeof r||null===r)return"";j=n.arrayFormat in d?n.arrayFormat:"indices"in n?n.indices?"indices":"repeat":"indices";var A=d[j];b||(b=Object.keys(r)),f&&b.sort(f);for(var C=0;C<b.length;++C){var S=b[C];s&&null===r[S]||p(E,y(r[S],S,A,a,s,l?u:null,_,f,m,g,O,v,w))}var U=E.join(o),x=!0===n.addQueryPrefix?"?":"";return n.charsetSentinel&&(x+="iso-8859-1"===w?"utf8=%26%2310003%3B&":"utf8=%E2%9C%93&"),U.length>0?x+U:""};const O={error:"timeout",error_description:"Timeout"},j=(...e)=>{const t=e.filter(Boolean).join();return Array.from(new Set(t.replace(/\s/g,",").split(","))).join(" ").trim()},E=e=>{var t=b(e);return Object.assign({},t,{expires_in:parseInt(t.expires_in)})},A=(e,t)=>new Promise((r,n)=>{var o=window.document.createElement("iframe");o.setAttribute("width","0"),o.setAttribute("height","0"),o.style.display="none";const i=setTimeout(()=>{n(O),window.document.body.removeChild(o)},6e4),a=function(e){e.origin==t&&e.data&&"authorization_response"===e.data.type&&(e.source.close(),e.data.response.error?n(e.data.response):r(e.data.response),clearTimeout(i),window.removeEventListener("message",a,!1),window.document.body.removeChild(o))};window.addEventListener("message",a,!1),window.document.body.appendChild(o),o.setAttribute("src",e)}),C=()=>{const e=window.open("","auth0:authorize:popup","left=100,top=100,width=400,height=600,resizable,scrollbars=yes,status=1");if(!e)throw new Error("Could not open popup");return e},S=(e,t)=>(e.location.href=t,new Promise((t,r)=>{const n=setTimeout(()=>{r(O)},6e4);window.addEventListener("message",o=>{if(o.data&&"authorization_response"===o.data.type){if(clearTimeout(n),e.close(),o.data.response.error)return r(o.data.response);t(o.data.response)}})})),U=()=>{const e="0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-_~.";let t="";return crypto.getRandomValues(new Uint8Array(43)).forEach(r=>t+=e[r%e.length]),t},x=e=>btoa(e),T=e=>_(e),k=e=>window.crypto.subtle.digest({name:"SHA-256"},(new TextEncoder).encode(e)),P=e=>atob(e.replace(/_/g,"/").replace(/-/g,"+")),D=e=>(e=>{const t={"+":"-","/":"_","=":""};return e.replace(/[\+\/=]/g,e=>t[e])})(window.btoa(String.fromCharCode(...Array.from(new Uint8Array(e))))),L=r=>t(void 0,void 0,void 0,function*(){var{baseUrl:t}=r,n=e(r,["baseUrl"]);return yield fetch(`${t}/oauth/token`,{method:"POST",body:JSON.stringify(Object.assign({grant_type:"authorization_code",redirect_uri:window.location.origin},n)),headers:{"Content-type":"application/json"}}).then(e=>e.json())}),I=e=>`${e.audience}::${e.scope}`,N=(e,t)=>{const r=(new Date(1e3*t).getTime()-(new Date).getTime())/1e3;return 1e3*Math.min(e,r)};class R{constructor(){this.cache={}}save(e){const t=I(e);this.cache[t]=e;const r=N(e.expires_in,e.decodedToken.claims.exp);setTimeout(()=>{delete this.cache[t]},r)}get(e){return this.cache[I(e)]}}var F="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var z,B,H=(function(e,t){var r=F&&F.__assign||Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e};function n(e,t){if(!t)return"";var r="; "+e;return!0===t?r:r+"="+t}function o(e,t,r){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)}(r)}function i(e){for(var t={},r=e?e.split("; "):[],n=/(%[0-9A-Z]{2})+/g,o=0;o<r.length;o++){var i=r[o].split("="),a=i.slice(1).join("=");'"'===a.charAt(0)&&(a=a.slice(1,-1));try{t[i[0].replace(n,decodeURIComponent)]=a.replace(n,decodeURIComponent)}catch(e){}}return t}function a(){return i(document.cookie)}function s(e,t,n){document.cookie=o(e,t,r({path:"/"},n))}t.__esModule=!0,t.encode=o,t.parse=i,t.getAll=a,t.get=function(e){return a()[e]},t.set=s,t.remove=function(e,t){s(e,"",r({},t,{expires:-1}))}}(z={exports:{}},z.exports),z.exports);(B=H)&&B.__esModule&&Object.prototype.hasOwnProperty.call(B,"default")&&B.default;H.encode,H.parse,H.getAll;var $=H.get,M=H.set,J=H.remove;const Q=e=>{const t=$(e);if(void 0!==t)return JSON.parse(t)},V=(e,t,r)=>{M(e,JSON.stringify(t),{expires:r.daysUntilExpire})},q=e=>{J(e)},W="Auth0.login.transactions";class Z{constructor(){this.transactions=Q(W)||{}}create(e){this.transactions[e.state]=e,V(W,this.transactions,{daysUntilExpire:1})}get(e){return this.transactions[e]}remove(e){delete this.transactions[e],V(W,this.transactions,{daysUntilExpire:1})}}const G=["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"],K=e=>{const t=(e=>{const[t,r,n]=e.split("."),o=JSON.parse(P(r)),i={},a={};return Object.keys(o).forEach(e=>{i[e]=o[e],G.includes(e)||(a[e]=o[e])}),{encoded:{header:t,payload:r,signature:n},header:JSON.parse(P(t)),claims:i,user:a}})(e.id_token);if(t.claims.iss!==e.iss)throw new Error("Invalid issuer");if(t.claims.aud!==e.aud)throw new Error("Invalid audience");if("RS256"!==t.header.alg)throw new Error("Invalid algorithm");if(t.claims.nonce!==e.nonce)throw new Error("Invalid nonce");const r=new Date,n=new Date(0),o=new Date(0),i=new Date(0),a=e.leeway||0;if(n.setUTCSeconds(t.claims.exp+a),o.setUTCSeconds(t.claims.iat-a),i.setUTCSeconds(t.claims.nbf-a),r>n)throw new Error("id_token expired");if(r<o)throw new Error("id_token was issued in the future (invalid iat)");if(void 0!==t.claims.nbf&&r<i)throw new Error("token is not yet valid (invalid notBefore)");return t};var X="0.0.1-alpha.17";class Y{constructor(e){this.options=e,this.DEFAULT_SCOPE="openid profile email",this.cache=new R,this.transactionManager=new Z,this.domainUrl=`https://${this.options.domain}`}_url(e){const t=encodeURIComponent(btoa(JSON.stringify({name:"@auth0/auth0-spa-js",version:X})));return`${this.domainUrl}${e}&auth0Client=${t}`}_getParams(t,r,n,o,i){const a=e(this.options,["domain"]);return Object.assign({},a,t,{scope:j(this.DEFAULT_SCOPE,this.options.scope,t.scope),response_type:"code",response_mode:"query",state:r,nonce:n,redirect_uri:i,code_challenge:o,code_challenge_method:"S256"})}_authorizeUrl(e){return this._url(`/authorize?${T(e)}`)}_verifyIdToken(e,t){return K({iss:`${this.domainUrl}/`,aud:this.options.client_id,id_token:e,nonce:t,leeway:this.options.leeway})}loginWithPopup(r){return t(this,void 0,void 0,function*(){const t=yield C(),n=e(r,[]),o=x(U()),i=U(),a=U(),s=yield k(a),c=D(s),d=this._getParams(n,o,i,c,window.location.origin),l=this._authorizeUrl(Object.assign({},d,{response_mode:"web_message"})),u=yield S(t,l);if(o!==u.state)throw new Error("Invalid state");const p=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:a,code:u.code}),f=this._verifyIdToken(p.id_token,i),h=Object.assign({},p,{decodedToken:f,scope:d.scope,audience:d.audience||"default"});this.cache.save(h),V("auth0.is.authenticated",!0,{daysUntilExpire:1})})}getUser(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.user})}getIdTokenClaims(e={audience:this.options.audience||"default",scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){e.scope=j(this.DEFAULT_SCOPE,e.scope);const t=this.cache.get(e);return t&&t.decodedToken.claims})}loginWithRedirect(r){return t(this,void 0,void 0,function*(){const{redirect_uri:t,appState:n}=r,o=e(r,["redirect_uri","appState"]),i=x(U()),a=U(),s=U(),c=yield k(s),d=D(c),l=this._getParams(o,i,a,d,t),u=this._authorizeUrl(l);this.transactionManager.create({state:i,nonce:a,code_verifier:s,code_challenge:d,appState:n,scope:l.scope,audience:l.audience||"default"}),window.location.assign(u)})}handleRedirectCallback(){return t(this,void 0,void 0,function*(){if(!window.location.search)throw new Error("There are no query params available at `window.location.search`.");const e=E(window.location.search.substr(1)),t=this.transactionManager.get(e.state);if(!t)throw new Error("Invalid state");this.transactionManager.remove(e.state);const r=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:t.code_verifier,code:e.code}),n=this._verifyIdToken(r.id_token,t.nonce),o=Object.assign({},r,{decodedToken:n,audience:t.audience,scope:t.scope});return this.cache.save(o),V("auth0.is.authenticated",!0,{daysUntilExpire:1}),{appState:t.appState}})}getTokenSilently(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE,ignoreCache:!1}){return t(this,void 0,void 0,function*(){if(e.scope=j(this.DEFAULT_SCOPE,e.scope),!e.ignoreCache){const t=this.cache.get({scope:e.scope,audience:e.audience||"default"});if(t)return t.access_token}const t=x(U()),r=U(),n=U(),o=yield k(n),i=D(o),a={audience:e.audience,scope:e.scope},s=this._getParams(a,t,r,i,window.location.origin),c=this._authorizeUrl(Object.assign({},s,{prompt:"none",response_mode:"web_message"})),d=yield A(c,this.domainUrl);if(t!==d.state)throw new Error("Invalid state");const l=yield L({baseUrl:this.domainUrl,audience:this.options.audience,client_id:this.options.client_id,code_verifier:n,code:d.code}),u=this._verifyIdToken(l.id_token,r),p=Object.assign({},l,{decodedToken:u,scope:s.scope,audience:s.audience||"default"});return this.cache.save(p),V("auth0.is.authenticated",!0,{daysUntilExpire:1}),l.access_token})}getTokenWithPopup(e={audience:this.options.audience,scope:this.options.scope||this.DEFAULT_SCOPE}){return t(this,void 0,void 0,function*(){return e.scope=j(this.DEFAULT_SCOPE,this.options.scope,e.scope),yield this.loginWithPopup(e),this.cache.get({scope:e.scope,audience:e.audience||"default"}).access_token})}isAuthenticated(){return t(this,void 0,void 0,function*(){return!!(yield this.getUser())})}logout(e={}){null!==e.client_id?e.client_id=e.client_id||this.options.client_id:delete e.client_id,q("auth0.is.authenticated");const t=this._url(`/v2/logout?${T(e)}`);window.location.assign(t)}}return function(e){return t(this,void 0,void 0,function*(){const t=new Y(e);if(!Q("auth0.is.authenticated"))return t;try{yield t.getTokenSilently({audience:e.audience,scope:e.scope,ignoreCache:!0})}catch(e){}return t})}});
//# sourceMappingURL=auth0-spa-js.production.js.map

@@ -152,19 +152,17 @@ 'use strict';

class ClientStorage {
get(key) {
const value = Cookies.get(key);
if (typeof value === 'undefined') {
return;
}
return JSON.parse(value);
const get = (key) => {
const value = Cookies.get(key);
if (typeof value === 'undefined') {
return;
}
save(key, value, options) {
Cookies.set(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
}
remove(key) {
Cookies.remove(key);
}
}
return JSON.parse(value);
};
const save = (key, value, options) => {
Cookies.set(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
};
const remove = (key) => {
Cookies.remove(key);
};

@@ -174,8 +172,7 @@ const COOKIE_KEY = 'Auth0.login.transactions';

constructor() {
this.storage = new ClientStorage();
this.transactions = this.storage.get(COOKIE_KEY) || {};
this.transactions = get(COOKIE_KEY) || {};
}
create(transaction) {
this.transactions[transaction.state] = transaction;
this.storage.save(COOKIE_KEY, this.transactions, {
save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -189,3 +186,3 @@ });

delete this.transactions[state];
this.storage.save(COOKIE_KEY, this.transactions, {
save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -285,3 +282,3 @@ });

*/
class Auth0 {
class Auth0Client {
constructor(options) {

@@ -292,3 +289,2 @@ this.options = options;

this.transactionManager = new TransactionManager();
this.storage = new ClientStorage();
this.domainUrl = `https://${this.options.domain}`;

@@ -323,31 +319,3 @@ }

/**
*
* ```js
* await auth0.init();
* ```
*
* `auth0.init` will detect if the current browser has previously
* logged in using this library by checking a cookie. In case this
* is true, fresh tokens (`id_token` and `access_token`) will be
* available to use.
*/
init() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.storage.get('auth0.is.authenticated')) {
return;
}
try {
yield this.getTokenSilently({
audience: this.options.audience,
scope: this.options.scope,
ignoreCache: true
});
}
catch (error) {
// don't care
}
});
}
/**
* ```js
* await auth0.loginWithPopup(options);

@@ -388,3 +356,3 @@ * ```

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
});

@@ -491,3 +459,3 @@ }

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return {

@@ -552,3 +520,3 @@ appState: transaction.appState

this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return authResult.access_token;

@@ -614,3 +582,3 @@ });

}
this.storage.remove('auth0.is.authenticated');
remove('auth0.is.authenticated');
const url = this._url(`/v2/logout?${createQueryParams(options)}`);

@@ -621,3 +589,23 @@ window.location.assign(url);

module.exports = Auth0;
function createAuth0Client(options) {
return __awaiter(this, void 0, void 0, function* () {
const auth0 = new Auth0Client(options);
if (!get('auth0.is.authenticated')) {
return auth0;
}
try {
yield auth0.getTokenSilently({
audience: options.audience,
scope: options.scope,
ignoreCache: true
});
}
catch (error) {
// ignore
}
return auth0;
});
}
module.exports = createAuth0Client;
//# sourceMappingURL=auth0-spa-js.cjs.js.map

@@ -21,3 +21,3 @@ /**

}
interface Auth0Options extends BaseLoginOptions {
interface Auth0ClientOptions extends BaseLoginOptions {
/**

@@ -24,0 +24,0 @@ * Your Auth0 account domain such as `'example.auth0.com'`,

@@ -0,129 +1,3 @@

import Auth0Client from './Auth0Client';
import './global';
/**
* Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
*/
export default class Auth0 {
private options;
private cache;
private transactionManager;
private storage;
private domainUrl;
private readonly DEFAULT_SCOPE;
constructor(options: Auth0Options);
private _url;
private _getParams;
private _authorizeUrl;
private _verifyIdToken;
/**
*
* ```js
* await auth0.init();
* ```
*
* `auth0.init` will detect if the current browser has previously
* logged in using this library by checking a cookie. In case this
* is true, fresh tokens (`id_token` and `access_token`) will be
* available to use.
*/
init(): Promise<void>;
/**
* ```js
* await auth0.loginWithPopup(options);
* ```
*
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* @param options
*/
loginWithPopup(options: PopupLoginOptions): Promise<void>;
/**
* ```js
* const user = await auth0.getUser();
* ```
*
* Returns the user information if available (decoded
* from the `id_token`).
*
* @param options
*/
getUser(options?: GetUserOptions): Promise<any>;
/**
* ```js
* const claims = await auth0.getIdTokenClaims();
* ```
*
* Returns all claims from the id_token if available.
*
* @param options
*/
getIdTokenClaims(options?: getIdTokenClaimsOptions): Promise<IdToken>;
/**
* ```js
* await auth0.loginWithRedirect(options);
* ```
*
* Performs a redirect to `/authorize` using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated.
*
* @param options
*/
loginWithRedirect(options: RedirectLoginOptions): Promise<void>;
/**
* After the browser redirects back to the callback page,
* call `handleRedirectCallback` to handle success and error
* responses from Auth0. If the response is successful, results
* will be valid according to their expiration times.
*/
handleRedirectCallback(): Promise<RedirectLoginResult>;
/**
* ```js
* const token = await auth0.getTokenSilently(options);
* ```
*
* If there's a valid token stored, return it. Otherwise, opens an
* iframe with the `/authorize` URL using the parameters provided
* as arguments. Random and secure `state` and `nonce` parameters
* will be auto-generated. If the response is successful, results
* will be valid according to their expiration times.
*
* @param options
*/
getTokenSilently(options?: GetTokenSilentlyOptions): Promise<any>;
/**
* ```js
* const token = await auth0.getTokenWithPopup(options);
* ```
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* @param options
*/
getTokenWithPopup(options?: GetTokenWithPopupOptions): Promise<string>;
/**
* ```js
* const isAuthenticated = await auth0.isAuthenticated();
* ```
*
* Returns `true` if there's valid information stored,
* otherwise returns `false`.
*
*/
isAuthenticated(): Promise<boolean>;
/**
* ```js
* auth0.logout();
* ```
*
* Performs a redirect to `/v2/logout` using the parameters provided
* as arguments. [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
*
* @param options
*/
logout(options?: LogoutOptions): void;
}
export default function createAuth0Client(options: Auth0ClientOptions): Promise<Auth0Client>;
import 'ts-polyfill';
import 'fast-text-encoding';
import 'unfetch/polyfill/index';
import Auth0 from './index';
export default Auth0;
export * from './index';
interface ClientStorageOptions {
daysUntilExpire: number;
}
export default class ClientStorage {
get<T extends Object>(key: string): T;
save(key: string, value: any, options: ClientStorageOptions): void;
remove(key: string): void;
}
export declare const get: <T extends Object>(key: string) => T;
export declare const save: (key: string, value: any, options: ClientStorageOptions) => void;
export declare const remove: (key: string) => void;
export {};

@@ -11,3 +11,2 @@ interface Transaction {

export default class TransactionManager {
private storage;
private transactions;

@@ -14,0 +13,0 @@ constructor();

@@ -1,2 +0,2 @@

declare const _default: "0.0.1-alpha.17";
declare const _default: "0.0.1-alpha.18";
export default _default;

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "0.0.1-alpha.17",
"version": "0.0.1-alpha.18",
"main": "dist/lib/auth0-spa-js.cjs.js",

@@ -9,0 +9,0 @@ "types": "dist/typings/index.d.ts",

@@ -5,3 +5,3 @@ # @auth0/auth0-spa-js

[![CircleCI](https://circleci.com/gh/auth0/auth0-login.svg?style=svg)](https://circleci.com/gh/auth0/auth0-login)
[![CircleCI](https://circleci.com/gh/auth0/auth0-spa-js.svg?style=svg)](https://circleci.com/gh/auth0/auth0-spa-js)
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)

@@ -24,3 +24,3 @@

- See the [API reference](https://auth0.github.io/auth0-login/)
- See the [API reference](https://auth0.github.io/auth0-spa-js/)

@@ -50,9 +50,8 @@ ## Installation

```js
import Auth0 from '@auth0/auth0-spa-js';
import createAuth0Client from '@auth0/auth0-spa-js';
const auth0 = new Auth0({
domain: 'YOUR_AUTH0_DOMAIN',
client_id: 'YOUR_AUTH0_CLIENT_ID'
const auth0 = await createAuth0Client({
domain: 'auth.brucke.club',
client_id: 'wLSIP47wM39wKdDmOj6Zb5eSEw3JVhVp'
});
await auth0.init();
await auth0.loginWithPopup();

@@ -73,3 +72,3 @@ const user = await auth0.getUser();

- Use [Issues](https://github.com/auth0/auth0-login/issues) for code-level support
- Use [Issues](https://github.com/auth0/auth0-spa-js/issues) for code-level support
- Use [Community](https://community.auth0.com/) for usage, questions, specific cases

@@ -76,0 +75,0 @@

@@ -22,3 +22,3 @@ /**

interface Auth0Options extends BaseLoginOptions {
interface Auth0ClientOptions extends BaseLoginOptions {
/**

@@ -25,0 +25,0 @@ * Your Auth0 account domain such as `'example.auth0.com'`,

@@ -1,430 +0,23 @@

import {
getUniqueScopes,
createQueryParams,
runPopup,
parseQueryResult,
encodeState,
createRandomString,
runIframe,
sha256,
bufferToBase64UrlEncoded,
oauthToken,
openPopup
} from './utils';
import Auth0Client from './Auth0Client';
import * as ClientStorage from './storage';
import Cache from './cache';
import TransactionManager from './transaction-manager';
import { verify as verifyIdToken } from './jwt';
import ClientStorage from './storage';
import version from './version';
//this is necessary to export the type definitions used in this file
import './global';
/**
* Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce).
*/
export default class Auth0 {
private cache: Cache;
private transactionManager: TransactionManager;
private storage: ClientStorage;
private domainUrl: string;
private readonly DEFAULT_SCOPE = 'openid profile email';
export default async function createAuth0Client(options: Auth0ClientOptions) {
const auth0 = new Auth0Client(options);
constructor(private options: Auth0Options) {
this.cache = new Cache();
this.transactionManager = new TransactionManager();
this.storage = new ClientStorage();
this.domainUrl = `https://${this.options.domain}`;
if (!ClientStorage.get('auth0.is.authenticated')) {
return auth0;
}
private _url(path) {
const telemetry = encodeURIComponent(
btoa(
JSON.stringify({
name: '@auth0/auth0-spa-js',
version: version
})
)
);
return `${this.domainUrl}${path}&auth0Client=${telemetry}`;
}
private _getParams(
authorizeOptions: BaseLoginOptions,
state: string,
nonce: string,
code_challenge: string,
redirect_uri: string
): AuthorizeOptions {
const { domain, ...withoutDomain } = this.options;
return {
...withoutDomain,
...authorizeOptions,
scope: getUniqueScopes(
this.DEFAULT_SCOPE,
this.options.scope,
authorizeOptions.scope
),
response_type: 'code',
response_mode: 'query',
state,
nonce,
redirect_uri,
code_challenge,
code_challenge_method: 'S256'
};
}
private _authorizeUrl(authorizeOptions: AuthorizeOptions) {
return this._url(`/authorize?${createQueryParams(authorizeOptions)}`);
}
private _verifyIdToken(id_token: string, nonce?: string) {
return verifyIdToken({
iss: `${this.domainUrl}/`,
aud: this.options.client_id,
id_token,
nonce,
leeway: this.options.leeway
});
}
/**
*
* ```js
* await auth0.init();
* ```
*
* `auth0.init` will detect if the current browser has previously
* logged in using this library by checking a cookie. In case this
* is true, fresh tokens (`id_token` and `access_token`) will be
* available to use.
*/
public async init() {
if (!this.storage.get('auth0.is.authenticated')) {
return;
}
try {
await this.getTokenSilently({
audience: this.options.audience,
scope: this.options.scope,
ignoreCache: true
});
} catch (error) {
// don't care
}
}
/**
* ```js
* await auth0.loginWithPopup(options);
* ```
*
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* @param options
*/
public async loginWithPopup(options: PopupLoginOptions) {
const popup = await openPopup();
const { ...authorizeOptions } = options;
const stateIn = encodeState(createRandomString());
const nonceIn = createRandomString();
const code_verifier = createRandomString();
const code_challengeBuffer = await sha256(code_verifier);
const code_challenge = bufferToBase64UrlEncoded(code_challengeBuffer);
const params = this._getParams(
authorizeOptions,
stateIn,
nonceIn,
code_challenge,
window.location.origin
);
const url = this._authorizeUrl({
...params,
response_mode: 'web_message'
});
const codeResult = await runPopup(popup, url);
if (stateIn !== codeResult.state) {
throw new Error('Invalid state');
}
const authResult = await oauthToken({
baseUrl: this.domainUrl,
audience: this.options.audience,
client_id: this.options.client_id,
code_verifier,
code: codeResult.code
});
const decodedToken = this._verifyIdToken(authResult.id_token, nonceIn);
const cacheEntry = {
...authResult,
decodedToken,
scope: params.scope,
audience: params.audience || 'default'
};
this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
}
/**
* ```js
* const user = await auth0.getUser();
* ```
*
* Returns the user information if available (decoded
* from the `id_token`).
*
* @param options
*/
public async getUser(
options: GetUserOptions = {
audience: this.options.audience || 'default',
scope: this.options.scope || this.DEFAULT_SCOPE
}
) {
options.scope = getUniqueScopes(this.DEFAULT_SCOPE, options.scope);
const cache = this.cache.get(options);
return cache && cache.decodedToken.user;
}
/**
* ```js
* const claims = await auth0.getIdTokenClaims();
* ```
*
* Returns all claims from the id_token if available.
*
* @param options
*/
public async getIdTokenClaims(
options: getIdTokenClaimsOptions = {
audience: this.options.audience || 'default',
scope: this.options.scope || this.DEFAULT_SCOPE
}
) {
options.scope = getUniqueScopes(this.DEFAULT_SCOPE, options.scope);
const cache = this.cache.get(options);
return cache && cache.decodedToken.claims;
}
/**
* ```js
* await auth0.loginWithRedirect(options);
* ```
*
* Performs a redirect to `/authorize` using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated.
*
* @param options
*/
public async loginWithRedirect(options: RedirectLoginOptions) {
const { redirect_uri, appState, ...authorizeOptions } = options;
const stateIn = encodeState(createRandomString());
const nonceIn = createRandomString();
const code_verifier = createRandomString();
const code_challengeBuffer = await sha256(code_verifier);
const code_challenge = bufferToBase64UrlEncoded(code_challengeBuffer);
const params = this._getParams(
authorizeOptions,
stateIn,
nonceIn,
code_challenge,
redirect_uri
);
const url = this._authorizeUrl(params);
this.transactionManager.create({
state: stateIn,
nonce: nonceIn,
code_verifier,
code_challenge: code_challenge,
appState,
scope: params.scope,
audience: params.audience || 'default'
});
window.location.assign(url);
}
/**
* After the browser redirects back to the callback page,
* call `handleRedirectCallback` to handle success and error
* responses from Auth0. If the response is successful, results
* will be valid according to their expiration times.
*/
public async handleRedirectCallback(): Promise<RedirectLoginResult> {
if (!window.location.search) {
throw new Error(
'There are no query params available at `window.location.search`.'
);
}
const codeResult = parseQueryResult(window.location.search.substr(1));
const transaction = this.transactionManager.get(codeResult.state);
if (!transaction) {
throw new Error('Invalid state');
}
this.transactionManager.remove(codeResult.state);
const authResult = await oauthToken({
baseUrl: this.domainUrl,
audience: this.options.audience,
client_id: this.options.client_id,
code_verifier: transaction.code_verifier,
code: codeResult.code
});
const decodedToken = this._verifyIdToken(
authResult.id_token,
transaction.nonce
);
const cacheEntry = {
...authResult,
decodedToken,
audience: transaction.audience,
scope: transaction.scope
};
this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return {
appState: transaction.appState
};
}
/**
* ```js
* const token = await auth0.getTokenSilently(options);
* ```
*
* If there's a valid token stored, return it. Otherwise, opens an
* iframe with the `/authorize` URL using the parameters provided
* as arguments. Random and secure `state` and `nonce` parameters
* will be auto-generated. If the response is successful, results
* will be valid according to their expiration times.
*
* @param options
*/
public async getTokenSilently(
options: GetTokenSilentlyOptions = {
audience: this.options.audience,
scope: this.options.scope || this.DEFAULT_SCOPE,
ignoreCache: false
}
) {
options.scope = getUniqueScopes(this.DEFAULT_SCOPE, options.scope);
if (!options.ignoreCache) {
const cache = this.cache.get({
scope: options.scope,
audience: options.audience || 'default'
});
if (cache) {
return cache.access_token;
}
}
const stateIn = encodeState(createRandomString());
const nonceIn = createRandomString();
const code_verifier = createRandomString();
const code_challengeBuffer = await sha256(code_verifier);
const code_challenge = bufferToBase64UrlEncoded(code_challengeBuffer);
const authorizeOptions = {
try {
await auth0.getTokenSilently({
audience: options.audience,
scope: options.scope
};
const params = this._getParams(
authorizeOptions,
stateIn,
nonceIn,
code_challenge,
window.location.origin
);
const url = this._authorizeUrl({
...params,
prompt: 'none',
response_mode: 'web_message'
});
const codeResult = await runIframe(url, this.domainUrl);
if (stateIn !== codeResult.state) {
throw new Error('Invalid state');
}
const authResult = await oauthToken({
baseUrl: this.domainUrl,
audience: this.options.audience,
client_id: this.options.client_id,
code_verifier,
code: codeResult.code
});
const decodedToken = this._verifyIdToken(authResult.id_token, nonceIn);
const cacheEntry = {
...authResult,
decodedToken,
scope: params.scope,
audience: params.audience || 'default'
};
this.cache.save(cacheEntry);
this.storage.save('auth0.is.authenticated', true, { daysUntilExpire: 1 });
return authResult.access_token;
}
/**
* ```js
* const token = await auth0.getTokenWithPopup(options);
* ```
* Opens a popup with the `/authorize` URL using the parameters
* provided as arguments. Random and secure `state` and `nonce`
* parameters will be auto-generated. If the response is successful,
* results will be valid according to their expiration times.
*
* @param options
*/
public async getTokenWithPopup(
options: GetTokenWithPopupOptions = {
audience: this.options.audience,
scope: this.options.scope || this.DEFAULT_SCOPE
}
) {
options.scope = getUniqueScopes(
this.DEFAULT_SCOPE,
this.options.scope,
options.scope
);
await this.loginWithPopup(options);
const cache = this.cache.get({
scope: options.scope,
audience: options.audience || 'default'
ignoreCache: true
});
return cache.access_token;
} catch (error) {
// ignore
}
/**
* ```js
* const isAuthenticated = await auth0.isAuthenticated();
* ```
*
* Returns `true` if there's valid information stored,
* otherwise returns `false`.
*
*/
public async isAuthenticated() {
const user = await this.getUser();
return !!user;
}
/**
* ```js
* auth0.logout();
* ```
*
* Performs a redirect to `/v2/logout` using the parameters provided
* as arguments. [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
*
* @param options
*/
public logout(options: LogoutOptions = {}) {
if (options.client_id !== null) {
options.client_id = options.client_id || this.options.client_id;
} else {
delete options.client_id;
}
this.storage.remove('auth0.is.authenticated');
const url = this._url(`/v2/logout?${createQueryParams(options)}`);
window.location.assign(url);
}
return auth0;
}

@@ -8,5 +8,6 @@ import 'ts-polyfill';

if (!window.crypto) {
throw new Error('For security reasons, `window.crypto` is required to run this `auth0-spa-js`.');
throw new Error(
'For security reasons, `window.crypto` is required to run `auth0-spa-js`.'
);
}
import Auth0 from './index';
export default Auth0;
export * from './index';

@@ -7,18 +7,20 @@ import * as Cookies from 'es-cookie';

export default class ClientStorage {
public get<T extends Object>(key: string) {
const value = Cookies.get(key);
if (typeof value === 'undefined') {
return;
}
return <T>JSON.parse(value);
export const get = <T extends Object>(key: string) => {
const value = Cookies.get(key);
if (typeof value === 'undefined') {
return;
}
public save(key: string, value: any, options: ClientStorageOptions) {
Cookies.set(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
}
public remove(key: string) {
Cookies.remove(key);
}
}
return <T>JSON.parse(value);
};
export const save = (
key: string,
value: any,
options: ClientStorageOptions
) => {
Cookies.set(key, JSON.stringify(value), {
expires: options.daysUntilExpire
});
};
export const remove = (key: string) => {
Cookies.remove(key);
};

@@ -1,2 +0,2 @@

import ClientStorage from './storage';
import * as ClientStorage from './storage';

@@ -18,11 +18,9 @@ const COOKIE_KEY = 'Auth0.login.transactions';

export default class TransactionManager {
private storage: ClientStorage;
private transactions: Transactions;
constructor() {
this.storage = new ClientStorage();
this.transactions = this.storage.get<Transactions>(COOKIE_KEY) || {};
this.transactions = ClientStorage.get<Transactions>(COOKIE_KEY) || {};
}
public create(transaction: Transaction) {
this.transactions[transaction.state] = transaction;
this.storage.save(COOKIE_KEY, this.transactions, {
ClientStorage.save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -36,3 +34,3 @@ });

delete this.transactions[state];
this.storage.save(COOKIE_KEY, this.transactions, {
ClientStorage.save(COOKIE_KEY, this.transactions, {
daysUntilExpire: 1

@@ -39,0 +37,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc