UNPKG

@auth0/auth0-spa-js

Version:

Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE

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