amazon-cognito-auth-js
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -17,3 +17,3 @@ /*! | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AmazonCognitoIdentity=e():t.AmazonCognitoIdentity=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}Object.defineProperty(e,"__esModule",{value:!0});var o=n(10);Object.keys(o).forEach(function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return o[t]}})});r(o);/*! | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AmazonCognitoIdentity=t():e.AmazonCognitoIdentity=t()}(this,function(){return function(e){function t(s){if(n[s])return n[s].exports;var o=n[s]={exports:{},id:s,loaded:!1};return e[s].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function s(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}Object.defineProperty(t,"__esModule",{value:!0});var o=n(9);Object.keys(o).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(t,e,{enumerable:!0,get:function(){return o[e]}})});s(o);/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
@@ -34,10 +34,3 @@ * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
*/ | ||
"undefined"!=typeof window&&!window.crypto&&window.msCrypto&&(window.crypto=window.msCrypto)},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),i=n(7),s=function(){function t(e){r(this,t),this.jwtToken=e||"",this.payload=this.decodePayload()}return o(t,[{key:"getJwtToken",value:function(){return this.jwtToken}},{key:"setJwtToken",value:function(t){this.jwtToken=t}},{key:"getExpiration",value:function(){return this.payload.exp}},{key:"getUsername",value:function(){if(null!==this.jwtToken)return this.payload.username}},{key:"decodePayload",value:function(){var t=this.jwtToken.split(".")[1];try{return JSON.parse(i.Buffer.from(t,"base64").toString("utf8"))}catch(t){return{}}}}]),t}();e.default=s},function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),i=n(7),s=function(){function t(e){r(this,t),this.jwtToken=e||"",this.payload=this.decodePayload()}return o(t,[{key:"getJwtToken",value:function(){return this.jwtToken}},{key:"setJwtToken",value:function(t){this.jwtToken=t}},{key:"getExpiration",value:function(){return this.payload.exp}},{key:"decodePayload",value:function(){var t=this.jwtToken.split(".")[1];try{return JSON.parse(i.Buffer.from(t,"base64").toString("utf8"))}catch(t){return{}}}}]),t}();e.default=s},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e){n(this,t),this.refreshToken=e||""}return r(t,[{key:"getToken",value:function(){return this.refreshToken}},{key:"setToken",value:function(t){this.refreshToken=t}}]),t}();e.default=o},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=function(){function t(e){n(this,t),this.tokenScopes=e||[]}return r(t,[{key:"getScopes",value:function(){return this.tokenScopes}},{key:"setTokenScopes",value:function(t){this.tokenScopes=t}}]),t}();e.default=o},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(4),a=r(s),u=n(1),h=r(u),f=n(2),c=r(f),g=n(3),l=r(g),p=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.IdToken,r=e.RefreshToken,i=e.AccessToken,s=e.TokenScopes,u=e.State;o(this,t),n?this.idToken=n:this.idToken=new c.default,r?this.refreshToken=r:this.refreshToken=new l.default,i?this.accessToken=i:this.accessToken=new h.default,s?this.tokenScopes=s:this.tokenScopes=new a.default,u?this.state=u:this.state=null}return i(t,[{key:"getIdToken",value:function(){return this.idToken}},{key:"setIdToken",value:function(t){this.idToken=t}},{key:"getRefreshToken",value:function(){return this.refreshToken}},{key:"setRefreshToken",value:function(t){this.refreshToken=t}},{key:"getAccessToken",value:function(){return this.accessToken}},{key:"setAccessToken",value:function(t){this.accessToken=t}},{key:"getTokenScopes",value:function(){return this.tokenScopes}},{key:"setTokenScopes",value:function(t){this.tokenScopes=t}},{key:"getState",value:function(){return this.state}},{key:"setState",value:function(t){this.state=t}},{key:"isValid",value:function(){var t=Math.floor(new Date/1e3);try{return null!=this.accessToken?t<this.accessToken.getExpiration():null!=this.idToken&&t<this.idToken.getExpiration()}catch(t){return!1}}}]),t}();e.default=p},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o={},i=function(){function t(){n(this,t)}return r(t,null,[{key:"setItem",value:function(t,e){return o[t]=e,o[t]}},{key:"getItem",value:function(t){return Object.prototype.hasOwnProperty.call(o,t)?o[t]:void 0}},{key:"removeItem",value:function(t){return delete o[t]}},{key:"clear",value:function(){return o={}}}]),t}(),s=function(){function t(){n(this,t);try{this.storageWindow=window.localStorage,this.storageWindow.setItem("aws.cognito.test-ls",1),this.storageWindow.removeItem("aws.cognito.test-ls")}catch(t){this.storageWindow=i}}return r(t,[{key:"getStorage",value:function(){return this.storageWindow}}]),t}();e.default=s},function(t,e,n){(function(t){/*! | ||
* The buffer module from node.js, for the browser. | ||
* | ||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
* @license MIT | ||
*/ | ||
"use strict";function r(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}function o(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function i(t,e){if(o()<e)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=s.prototype):(null===t&&(t=new s(e)),t.length=e),t}function s(t,e,n){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return f(this,t)}return a(this,t,e,n)}function a(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?l(t,e,n,r):"string"==typeof e?c(t,e,n):p(t,e)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e,n,r){return u(e),e<=0?i(t,e):void 0!==n?"string"==typeof r?i(t,e).fill(n,r):i(t,e).fill(n):i(t,e)}function f(t,e){if(u(e),t=i(t,e<0?0:0|d(e)),!s.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function c(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!s.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|S(e,n);t=i(t,r);var o=t.write(e,n);return o!==r&&(t=t.slice(0,o)),t}function g(t,e){var n=e.length<0?0:0|d(e.length);t=i(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function l(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),s.TYPED_ARRAY_SUPPORT?(t=e,t.__proto__=s.prototype):t=g(t,e),t}function p(t,e){if(s.isBuffer(e)){var n=0|d(e.length);return t=i(t,n),0===t.length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||q(e.length)?i(t,0):g(t,e);if("Buffer"===e.type&&$(e.data))return g(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function d(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function y(t){return+t!=t&&(t=0),s.alloc(+t)}function S(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return K(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return K(t).length;e=(""+e).toLowerCase(),r=!0}}function C(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return N(this,e,n);case"utf8":case"utf-8":return U(this,e,n);case"ascii":return _(this,e,n);case"latin1":case"binary":return P(this,e,n);case"base64":return O(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function v(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function T(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=s.from(e,r)),s.isBuffer(e))return 0===e.length?-1:E(t,e,n,r,o);if("number"==typeof e)return e&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):E(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function E(t,e,n,r,o){function i(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,u=e.length;if(void 0!==r&&(r=String(r).toLowerCase(),"ucs2"===r||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,n/=2}var h;if(o){var f=-1;for(h=n;h<a;h++)if(i(t,h)===i(e,f===-1?0:h-f)){if(f===-1&&(f=h),h-f+1===u)return f*s}else f!==-1&&(h-=h-f),f=-1}else for(n+u>a&&(n=a-u),h=n;h>=0;h--){for(var c=!0,g=0;g<u;g++)if(i(t,h+g)!==i(e,g)){c=!1;break}if(c)return h}return-1}function A(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r),r>o&&(r=o)):r=o;var i=e.length;if(i%2!==0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[n+s]=a}return s}function w(t,e,n,r){return X(K(e,t.length-n),t,n,r)}function I(t,e,n,r){return X(W(e),t,n,r)}function R(t,e,n,r){return I(t,e,n,r)}function k(t,e,n,r){return X(J(e),t,n,r)}function m(t,e,n,r){return X(z(e,t.length-n),t,n,r)}function O(t,e,n){return 0===e&&n===t.length?V.fromByteArray(t):V.fromByteArray(t.slice(e,n))}function U(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i=t[o],s=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=n){var u,h,f,c;switch(a){case 1:i<128&&(s=i);break;case 2:u=t[o+1],128===(192&u)&&(c=(31&i)<<6|63&u,c>127&&(s=c));break;case 3:u=t[o+1],h=t[o+2],128===(192&u)&&128===(192&h)&&(c=(15&i)<<12|(63&u)<<6|63&h,c>2047&&(c<55296||c>57343)&&(s=c));break;case 4:u=t[o+1],h=t[o+2],f=t[o+3],128===(192&u)&&128===(192&h)&&128===(192&f)&&(c=(15&i)<<18|(63&u)<<12|(63&h)<<6|63&f,c>65535&&c<1114112&&(s=c))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),o+=a}return b(r)}function b(t){var e=t.length;if(e<=tt)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=tt));return n}function _(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function P(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function N(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=e;i<n;++i)o+=G(t[i]);return o}function D(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function M(t,e,n){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function L(t,e,n,r,o,i){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function B(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function Y(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function j(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function x(t,e,n,r,o){return o||j(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),Z.write(t,e,n,r,23,4),n+4}function H(t,e,n,r,o){return o||j(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),Z.write(t,e,n,r,52,8),n+8}function Q(t){if(t=F(t).replace(et,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function F(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function G(t){return t<16?"0"+t.toString(16):t.toString(16)}function K(t,e){e=e||1/0;for(var n,r=t.length,o=null,i=[],s=0;s<r;++s){if(n=t.charCodeAt(s),n>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function W(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}function z(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,o=n%256,i.push(o),i.push(r);return i}function J(t){return V.toByteArray(Q(t))}function X(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function q(t){return t!==t}var V=n(11),Z=n(12),$=n(13);e.Buffer=s,e.SlowBuffer=y,e.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:r(),e.kMaxLength=o(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,n){return a(null,t,e,n)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,n){return h(null,t,e,n)},s.allocUnsafe=function(t){return f(null,t)},s.allocUnsafeSlow=function(t){return f(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!$(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=s.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var i=t[n];if(!s.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},s.byteLength=S,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)v(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)v(this,e,e+3),v(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)v(this,e,e+7),v(this,e+1,e+6),v(this,e+2,e+5),v(this,e+3,e+4);return this},s.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?U(this,0,t):C.apply(this,arguments)},s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"},s.prototype.compare=function(t,e,n,r,o){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;for(var i=o-r,a=n-e,u=Math.min(i,a),h=this.slice(r,o),f=t.slice(e,n),c=0;c<u;++c)if(h[c]!==f[c]){i=h[c],a=f[c];break}return i<a?-1:a<i?1:0},s.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1},s.prototype.indexOf=function(t,e,n){return T(this,t,e,n,!0)},s.prototype.lastIndexOf=function(t,e,n){return T(this,t,e,n,!1)},s.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return A(this,t,e,n);case"utf8":case"utf-8":return w(this,t,e,n);case"ascii":return I(this,t,e,n);case"latin1":case"binary":return R(this,t,e,n);case"base64":return k(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return m(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var tt=4096;s.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);var r;if(s.TYPED_ARRAY_SUPPORT)r=this.subarray(t,e),r.__proto__=s.prototype;else{var o=e-t;r=new s(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},s.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||M(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},s.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||M(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},s.prototype.readUInt8=function(t,e){return e||M(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||M(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||M(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||M(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||M(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||M(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return o*=128,r>=o&&(r-=Math.pow(2,8*e)),r},s.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||M(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},s.prototype.readInt8=function(t,e){return e||M(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},s.prototype.readInt16LE=function(t,e){e||M(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},s.prototype.readInt16BE=function(t,e){e||M(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},s.prototype.readInt32LE=function(t,e){return e||M(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||M(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||M(t,4,this.length),Z.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||M(t,4,this.length),Z.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||M(t,8,this.length),Z.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||M(t,8,this.length),Z.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){var o=Math.pow(2,8*n)-1;L(this,t,e,n,o,0)}var i=1,s=0;for(this[e]=255&t;++s<n&&(i*=256);)this[e+s]=t/i&255;return e+n},s.prototype.writeUIntBE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){var o=Math.pow(2,8*n)-1;L(this,t,e,n,o,0)}var i=n-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+n},s.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):Y(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Y(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);L(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},s.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);L(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},s.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):B(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):B(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):Y(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||L(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Y(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,n){return x(this,t,e,!0,n)},s.prototype.writeFloatBE=function(t,e,n){return x(this,t,e,!1,n)},s.prototype.writeDoubleLE=function(t,e,n){return H(this,t,e,!0,n)},s.prototype.writeDoubleBE=function(t,e,n){return H(this,t,e,!1,n)},s.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,i=r-n;if(this===t&&n<e&&e<r)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(i<1e3||!s.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},s.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!s.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var i;if("number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{var a=s.isBuffer(t)?t:K(new s(t,r).toString()),u=a.length;for(i=0;i<n-e;++i)this[i+e]=a[i%u]}return this};var et=/[^+\/0-9A-Za-z-_]/g}).call(e,function(){return this}())},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),a=n(4),u=r(a),h=n(1),f=r(h),c=n(2),g=r(c),l=n(3),p=r(l),d=n(5),y=r(d),S=n(6),C=r(S),v=function(){function t(e){o(this,t);var n=e||{},r=n.ClientId,i=n.AppWebDomain,s=n.TokenScopesArray,a=n.RedirectUriSignIn,h=n.RedirectUriSignOut,f=n.IdentityProvider,c=n.UserPoolId,g=n.AdvancedSecurityDataCollectionFlag;if(!(null!=e&&r&&i&&a&&h))throw new Error(this.getCognitoConstants().PARAMETERERROR);if(this.clientId=r,this.appWebDomain=i,this.TokenScopesArray=s||[],!Array.isArray(s))throw new Error(this.getCognitoConstants().SCOPETYPEERROR);var l=new u.default(this.TokenScopesArray);this.RedirectUriSignIn=a,this.RedirectUriSignOut=h,this.IdentityProvider=f,this.signInUserSession=new y.default,this.responseType=this.getCognitoConstants().TOKEN,this.storage=(new C.default).getStorage(),this.signInUserSession.setTokenScopes(l),this.username=this.getLastUser(),this.userPoolId=c,this.advancedSecurityDataCollectionFlag=!0,g&&(this.advancedSecurityDataCollectionFlag=g)}return s(t,[{key:"getCognitoConstants",value:function(){var t={DOMAIN_SCHEME:"https",DOMAIN_PATH_SIGNIN:"oauth2/authorize",DOMAIN_PATH_TOKEN:"oauth2/token",DOMAIN_PATH_SIGNOUT:"logout",DOMAIN_QUERY_PARAM_REDIRECT_URI:"redirect_uri",DOMAIN_QUERY_PARAM_SIGNOUT_URI:"logout_uri",DOMAIN_QUERY_PARAM_RESPONSE_TYPE:"response_type",DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER:"identity_provider",DOMAIN_QUERY_PARAM_USERCONTEXTDATA:"userContextData",CLIENT_ID:"client_id",STATE:"state",SCOPE:"scope",TOKEN:"token",CODE:"code",POST:"POST",PARAMETERERROR:"The parameters: App client Id, App web domain, the redirect URL when you are signed in and the redirect URL when you are signed out are required.",SCOPETYPEERROR:"Scopes have to be array type. ",QUESTIONMARK:"?",POUNDSIGN:"#",COLONDOUBLESLASH:"://",SLASH:"/",AMPERSAND:"&",EQUALSIGN:"=",SPACE:" ",CONTENTTYPE:"Content-Type",CONTENTTYPEVALUE:"application/x-www-form-urlencoded",AUTHORIZATIONCODE:"authorization_code",IDTOKEN:"id_token",ACCESSTOKEN:"access_token",REFRESHTOKEN:"refresh_token",ERROR:"error",STRINGTYPE:"string",STATELENGTH:32,STATEORIGINSTRING:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",WITHCREDENTIALS:"withCredentials",UNDEFINED:"undefined",SELF:"_self",HOSTNAMEREGEX:/:\/\/([0-9]?\.)?(.[^\/:]+)/i,QUERYPARAMETERREGEX1:/#(.+)/,QUERYPARAMETERREGEX2:/=(.+)/,HEADER:{"Content-Type":"application/x-www-form-urlencoded"}};return t}},{key:"getClientId",value:function(){return this.clientId}},{key:"getAppWebDomain",value:function(){return this.appWebDomain}},{key:"getCurrentUser",value:function(){var t="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",e=this.storage.getItem(t);return e}},{key:"setUser",value:function(t){this.username=t}},{key:"useCodeGrantFlow",value:function(){this.responseType=this.getCognitoConstants().CODE}},{key:"useImplicitFlow",value:function(){this.responseType=this.getCognitoConstants().TOKEN}},{key:"getSignInUserSession",value:function(){return this.signInUserSession}},{key:"getUsername",value:function(){return this.username}},{key:"setUsername",value:function(t){this.username=t}},{key:"getState",value:function(){return this.state}},{key:"setState",value:function(t){this.state=t}},{key:"getSession",value:function(){var t=new Set(this.TokenScopesArray),e=new Set(this.signInUserSession.tokenScopes.getScopes()),n=this.getFQDNSignIn();if(null!=this.signInUserSession&&this.signInUserSession.isValid())return this.userhandler.onSuccess(this.signInUserSession);if(this.signInUserSession=this.getCachedSession(),this.compareSets(t,e)){if(this.signInUserSession.isValid())return this.userhandler.onSuccess(this.signInUserSession);this.signInUserSession.getRefreshToken()&&this.signInUserSession.getRefreshToken().getToken()?this.refreshSession(this.signInUserSession.getRefreshToken().getToken()):this.launchUri(n)}else{var r=new u.default(this.TokenScopesArray),o=new g.default,i=new f.default,s=new p.default;this.signInUserSession.setTokenScopes(r),this.signInUserSession.setIdToken(o),this.signInUserSession.setAccessToken(i),this.signInUserSession.setRefreshToken(s),this.launchUri(n)}}},{key:"parseCognitoWebResponse",value:function(t){t.indexOf(this.getCognitoConstants().QUESTIONMARK)>-1?this.getCodeQueryParameter(t):t.indexOf(this.getCognitoConstants().POUNDSIGN)>-1&&this.getTokenQueryParameter(t)}},{key:"getCodeQueryParameter",value:function(t){var e=this.getQueryParameters(t,this.getCognitoConstants().QUESTIONMARK),n=null;if(e.has(this.getCognitoConstants().STATE)?this.signInUserSession.setState(e.get(this.getCognitoConstants().STATE)):this.signInUserSession.setState(n),e.has(this.getCognitoConstants().CODE)){var r=e.get(this.getCognitoConstants().CODE),o=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_TOKEN),i=this.getCognitoConstants().HEADER,s={grant_type:this.getCognitoConstants().AUTHORIZATIONCODE,client_id:this.getClientId(),redirect_uri:this.RedirectUriSignIn,code:r},a=this.onSuccessExchangeForToken.bind(this),u=this.onFailure.bind(this);this.makePOSTRequest(i,s,o,a,u)}}},{key:"getTokenQueryParameter",value:function(t){var e=this.getQueryParameters(t,this.getCognitoConstants().QUERYPARAMETERREGEX1),n=new g.default,r=new f.default,o=new p.default,i=null;return e.has(this.getCognitoConstants().IDTOKEN)?(n.setJwtToken(e.get(this.getCognitoConstants().IDTOKEN)),this.signInUserSession.setIdToken(n)):this.signInUserSession.setIdToken(n),e.has(this.getCognitoConstants().ACCESSTOKEN)?(r.setJwtToken(e.get(this.getCognitoConstants().ACCESSTOKEN)),this.signInUserSession.setAccessToken(r)):this.signInUserSession.setAccessToken(r),e.has(this.getCognitoConstants().REFRESHTOKEN)?(o.setToken(e.get(this.getCognitoConstants().REFRESHTOKEN)),this.signInUserSession.setRefreshToken(o)):this.signInUserSession.setRefreshToken(o),e.has(this.getCognitoConstants().STATE)?this.signInUserSession.setState(e.get(this.getCognitoConstants().STATE)):this.signInUserSession.setState(i),this.cacheTokensScopes(),this.userhandler.onSuccess(this.signInUserSession)}},{key:"getCachedSession",value:function(){if(!this.username)return new y.default;var t="CognitoIdentityServiceProvider."+this.getClientId()+"."+this.username,e=t+".idToken",n=t+".accessToken",r=t+".refreshToken",o=t+".tokenScopesString",i=this.storage.getItem(o),s=[];i&&(s=i.split(" "));var a=new u.default(s),h=new g.default(this.storage.getItem(e)),c=new f.default(this.storage.getItem(n)),l=new p.default(this.storage.getItem(r)),d={IdToken:h,AccessToken:c,RefreshToken:l,TokenScopes:a},S=new y.default(d);return S}},{key:"getLastUser",value:function(){var t="CognitoIdentityServiceProvider."+this.getClientId(),e=t+".LastAuthUser",n=this.storage.getItem(e);if(n)return n}},{key:"cacheTokensScopes",value:function(){var t="CognitoIdentityServiceProvider."+this.getClientId(),e=this.signInUserSession.getAccessToken().getUsername();this.username=e;var n=t+"."+e+".idToken",r=t+"."+e+".accessToken",o=t+"."+e+".refreshToken",i=t+".LastAuthUser",s=t+"."+e+".tokenScopesString",a=this.signInUserSession.getTokenScopes().getScopes(),u=a.join(" ");this.storage.setItem(n,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(r,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(o,this.signInUserSession.getRefreshToken().getToken()),this.storage.setItem(i,e),this.storage.setItem(s,u)}},{key:"compareSets",value:function(t,e){if(t.size!==e.size)return!1;var n=!0,r=!1,o=void 0;try{for(var i,s=t[Symbol.iterator]();!(n=(i=s.next()).done);n=!0){var a=i.value;if(!e.has(a))return!1}}catch(t){r=!0,o=t}finally{try{!n&&s.return&&s.return()}finally{if(r)throw o}}return!0}},{key:"getHostName",value:function(t){var e=t.match(this.getCognitoConstants().HOSTNAMEREGEX);if(null!=e&&e.length>2&&i(e[2])===this.getCognitoConstants().STRINGTYPE&&e[2].length>0)return e[2]}},{key:"getQueryParameters",value:function(t,e){var n=String(t).split(e),r=n[1],o=String(r).split(this.getCognitoConstants().AMPERSAND),i=o.length,s=new Map,a=void 0;for(a=0;a<i;a++)o[a]=String(o[a]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2),s.set(o[a][0],o[a][1]);return s}},{key:"generateRandomString",value:function(t,e){for(var n="",r=t;r>0;--r)n+=e[Math.round(Math.random()*(e.length-1))];return n}},{key:"clearCachedTokensScopes",value:function(){var t="CognitoIdentityServiceProvider."+this.getClientId(),e=t+"."+this.username+".idToken",n=t+"."+this.username+".accessToken",r=t+"."+this.username+".refreshToken",o=t+".LastAuthUser",i=t+"."+this.username+".tokenScopesString";this.storage.removeItem(e),this.storage.removeItem(n),this.storage.removeItem(r),this.storage.removeItem(o),this.storage.removeItem(i)}},{key:"refreshSession",value:function(t){var e=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_TOKEN),n=this.getCognitoConstants().HEADER,r={grant_type:this.getCognitoConstants().REFRESHTOKEN,client_id:this.getClientId(),redirect_uri:this.RedirectUriSignIn,refresh_token:t},o=this.onSuccessRefreshToken.bind(this),i=this.onFailure.bind(this);this.makePOSTRequest(n,r,e,o,i)}},{key:"makePOSTRequest",value:function(t,e,n,r,o){var i=this.createCORSRequest(this.getCognitoConstants().POST,n),s="";if(i){for(var a in t)i.setRequestHeader(a,t[a]);for(var u in e)s=s.concat(u,this.getCognitoConstants().EQUALSIGN,e[u],this.getCognitoConstants().AMPERSAND);s=s.substring(0,s.length-1),i.send(s),i.onreadystatechange=function(){4===i.readyState&&(200===i.status?r(i.responseText):o(i.responseText))}}}},{key:"createCORSRequest",value:function(t,e){var n=new XMLHttpRequest;return n.open(t,e,!0),this.getCognitoConstants().WITHCREDENTIALS in n?n.open(t,e,!0):("undefined"==typeof XDomainRequest?"undefined":i(XDomainRequest))!==this.getCognitoConstants().UNDEFINED?(n=new XDomainRequest,n.open(t,e)):n=null,n}},{key:"onFailure",value:function(t){this.userhandler.onFailure(t)}},{key:"onSuccessRefreshToken",value:function(t){var e=JSON.parse(t);if(Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().ERROR)){var n=this.getFQDNSignIn();this.launchUri(n)}else Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().IDTOKEN)&&this.signInUserSession.setIdToken(new g.default(e.id_token)),Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().ACCESSTOKEN)&&this.signInUserSession.setAccessToken(new f.default(e.access_token)),this.cacheTokensScopes(),this.userhandler.onSuccess(this.signInUserSession)}},{key:"onSuccessExchangeForToken",value:function(t){var e=JSON.parse(t),n=new p.default,r=new f.default,o=new g.default;return Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().ERROR)?this.userhandler.onFailure(t):(Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().IDTOKEN)?this.signInUserSession.setIdToken(new g.default(e.id_token)):this.signInUserSession.setIdToken(o),Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().ACCESSTOKEN)?this.signInUserSession.setAccessToken(new f.default(e.access_token)):this.signInUserSession.setAccessToken(r),Object.prototype.hasOwnProperty.call(e,this.getCognitoConstants().REFRESHTOKEN)?this.signInUserSession.setRefreshToken(new p.default(e.refresh_token)):this.signInUserSession.setRefreshToken(n),this.cacheTokensScopes(),void this.userhandler.onSuccess(this.signInUserSession)); | ||
}},{key:"launchUri",value:function(t){window.open(t,this.getCognitoConstants().SELF)}},{key:"getSpaceSeperatedScopeString",value:function(){var t=this.signInUserSession.getTokenScopes().getScopes();return t=t.join(this.getCognitoConstants().SPACE),encodeURIComponent(t)}},{key:"getFQDNSignIn",value:function(){null==this.state&&(this.state=this.generateRandomString(this.getCognitoConstants().STATELENGTH,this.getCognitoConstants().STATEORIGINSTRING));var t=this.IdentityProvider?this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER,this.getCognitoConstants().EQUALSIGN,this.IdentityProvider):"",e=this.getSpaceSeperatedScopeString(),n="",r=this.getUserContextData();r&&(n=this.getCognitoConstants().AMPERSAND+this.getCognitoConstants().DOMAIN_QUERY_PARAM_USERCONTEXTDATA+this.getCognitoConstants().EQUALSIGN+this.getUserContextData());var o=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_SIGNIN,this.getCognitoConstants().QUESTIONMARK,this.getCognitoConstants().DOMAIN_QUERY_PARAM_REDIRECT_URI,this.getCognitoConstants().EQUALSIGN,encodeURIComponent(this.RedirectUriSignIn),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().DOMAIN_QUERY_PARAM_RESPONSE_TYPE,this.getCognitoConstants().EQUALSIGN,this.responseType,this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().CLIENT_ID,this.getCognitoConstants().EQUALSIGN,this.getClientId(),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().STATE,this.getCognitoConstants().EQUALSIGN,this.state,this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().SCOPE,this.getCognitoConstants().EQUALSIGN,e,t,n);return o}},{key:"signOut",value:function(){var t=this.getFQDNSignOut();this.signInUserSession=null,this.clearCachedTokensScopes(),this.launchUri(t)}},{key:"getFQDNSignOut",value:function(){var t=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_SIGNOUT,this.getCognitoConstants().QUESTIONMARK,this.getCognitoConstants().DOMAIN_QUERY_PARAM_SIGNOUT_URI,this.getCognitoConstants().EQUALSIGN,encodeURIComponent(this.RedirectUriSignOut),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().CLIENT_ID,this.getCognitoConstants().EQUALSIGN,this.getClientId());return t}},{key:"getUserContextData",value:function(){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var t="";this.username&&(t=this.username);var e="";return this.userpoolId&&(e=this.userpoolId),this.advancedSecurityDataCollectionFlag?AmazonCognitoAdvancedSecurityData.getData(t,e,this.clientId):void 0}}},{key:"isUserSignedIn",value:function(){return null!=this.getCachedSession()&&this.getCachedSession().isValid()||null!=this.signInUserSession&&this.signInUserSession.isValid()}}]),t}();e.default=v},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],s=function(){function t(){n(this,t)}return r(t,[{key:"getNowString",value:function(){var t=new Date,e=i[t.getUTCDay()],n=o[t.getUTCMonth()],r=t.getUTCDate(),s=t.getUTCHours();s<10&&(s="0"+s);var a=t.getUTCMinutes();a<10&&(a="0"+a);var u=t.getUTCSeconds();u<10&&(u="0"+u);var h=t.getUTCFullYear(),f=e+" "+n+" "+r+" "+s+":"+a+":"+u+" UTC "+h;return f}}]),t}();e.default=s},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var o=n(1);Object.defineProperty(e,"CognitoAccessToken",{enumerable:!0,get:function(){return r(o).default}});var i=n(2);Object.defineProperty(e,"CognitoIdToken",{enumerable:!0,get:function(){return r(i).default}});var s=n(3);Object.defineProperty(e,"CognitoRefreshToken",{enumerable:!0,get:function(){return r(s).default}});var a=n(4);Object.defineProperty(e,"CognitoTokenScopes",{enumerable:!0,get:function(){return r(a).default}});var u=n(8);Object.defineProperty(e,"CognitoAuth",{enumerable:!0,get:function(){return r(u).default}});var h=n(5);Object.defineProperty(e,"CognitoAuthSession",{enumerable:!0,get:function(){return r(h).default}});var f=n(9);Object.defineProperty(e,"DateHelper",{enumerable:!0,get:function(){return r(f).default}});var c=n(6);Object.defineProperty(e,"StorageHelper",{enumerable:!0,get:function(){return r(c).default}})},function(t,e){"use strict";function n(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function r(t){return 3*t.length/4-n(t)}function o(t){var e,r,o,i,s,a,u=t.length;s=n(t),a=new f(3*u/4-s),o=s>0?u-4:u;var c=0;for(e=0,r=0;e<o;e+=4,r+=3)i=h[t.charCodeAt(e)]<<18|h[t.charCodeAt(e+1)]<<12|h[t.charCodeAt(e+2)]<<6|h[t.charCodeAt(e+3)],a[c++]=i>>16&255,a[c++]=i>>8&255,a[c++]=255&i;return 2===s?(i=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,a[c++]=255&i):1===s&&(i=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,a[c++]=i>>8&255,a[c++]=255&i),a}function i(t){return u[t>>18&63]+u[t>>12&63]+u[t>>6&63]+u[63&t]}function s(t,e,n){for(var r,o=[],s=e;s<n;s+=3)r=(t[s]<<16)+(t[s+1]<<8)+t[s+2],o.push(i(r));return o.join("")}function a(t){for(var e,n=t.length,r=n%3,o="",i=[],a=16383,h=0,f=n-r;h<f;h+=a)i.push(s(t,h,h+a>f?f:h+a));return 1===r?(e=t[n-1],o+=u[e>>2],o+=u[e<<4&63],o+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],o+=u[e>>10],o+=u[e>>4&63],o+=u[e<<2&63],o+="="),i.push(o),i.join("")}e.byteLength=r,e.toByteArray=o,e.fromByteArray=a;for(var u=[],h=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",g=0,l=c.length;g<l;++g)u[g]=c[g],h[c.charCodeAt(g)]=g;h["-".charCodeAt(0)]=62,h["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,n,r,o){var i,s,a=8*o-r-1,u=(1<<a)-1,h=u>>1,f=-7,c=n?o-1:0,g=n?-1:1,l=t[e+c];for(c+=g,i=l&(1<<-f)-1,l>>=-f,f+=a;f>0;i=256*i+t[e+c],c+=g,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+t[e+c],c+=g,f-=8);if(0===i)i=1-h;else{if(i===u)return s?NaN:(l?-1:1)*(1/0);s+=Math.pow(2,r),i-=h}return(l?-1:1)*s*Math.pow(2,i-r)},e.write=function(t,e,n,r,o,i){var s,a,u,h=8*i-o-1,f=(1<<h)-1,c=f>>1,g=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,l=r?0:i-1,p=r?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+c>=1?g/u:g*Math.pow(2,1-c),e*u>=2&&(s++,u/=2),s+c>=f?(a=0,s=f):s+c>=1?(a=(e*u-1)*Math.pow(2,o),s+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,o),s=0));o>=8;t[n+l]=255&a,l+=p,a/=256,o-=8);for(s=s<<o|a,h+=o;h>0;t[n+l]=255&s,l+=p,s/=256,h-=8);t[n+l-p]|=128*d}},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}}])}); | ||
"undefined"!=typeof window&&!window.crypto&&window.msCrypto&&(window.crypto=window.msCrypto)},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o=function(){function e(t){n(this,e),this.jwtToken=t||"",this.payload=this.decodePayload()}return s(e,[{key:"getJwtToken",value:function(){return this.jwtToken}},{key:"setJwtToken",value:function(e){this.jwtToken=e}},{key:"getExpiration",value:function(){if(null!==this.jwtToken){var e=this.jwtToken.split(".")[1];return JSON.parse(atob(e)).exp}}},{key:"getUsername",value:function(){if(null!==this.jwtToken){var e=this.jwtToken.split(".")[1];return JSON.parse(atob(e)).username}}},{key:"decodePayload",value:function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse(atob(e))}catch(e){return{}}}}]),e}();t.default=o},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o=function(){function e(t){n(this,e),this.jwtToken=t||"",this.payload=this.decodePayload()}return s(e,[{key:"getJwtToken",value:function(){return this.jwtToken}},{key:"setJwtToken",value:function(e){this.jwtToken=e}},{key:"getExpiration",value:function(){if(null!==this.jwtToken){var e=this.jwtToken.split(".")[1];return JSON.parse(atob(e)).exp}}},{key:"decodePayload",value:function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse(atob(e))}catch(e){return{}}}}]),e}();t.default=o},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o=function(){function e(t){n(this,e),this.refreshToken=t||""}return s(e,[{key:"getToken",value:function(){return this.refreshToken}},{key:"setToken",value:function(e){this.refreshToken=e}}]),e}();t.default=o},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o=function(){function e(t){n(this,e),this.tokenScopes=t||[]}return s(e,[{key:"getScopes",value:function(){return this.tokenScopes}},{key:"setTokenScopes",value:function(e){this.tokenScopes=e}}]),e}();t.default=o},function(e,t,n){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),r=n(4),a=s(r),u=n(1),c=s(u),g=n(2),h=s(g),l=n(3),f=s(l),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.IdToken,s=t.RefreshToken,i=t.AccessToken,r=t.TokenScopes,u=t.State;o(this,e),n?this.idToken=n:this.idToken=new h.default,s?this.refreshToken=s:this.refreshToken=new f.default,i?this.accessToken=i:this.accessToken=new c.default,r?this.tokenScopes=r:this.tokenScopes=new a.default,u?this.state=u:this.state=null}return i(e,[{key:"getIdToken",value:function(){return this.idToken}},{key:"setIdToken",value:function(e){this.idToken=e}},{key:"getRefreshToken",value:function(){return this.refreshToken}},{key:"setRefreshToken",value:function(e){this.refreshToken=e}},{key:"getAccessToken",value:function(){return this.accessToken}},{key:"setAccessToken",value:function(e){this.accessToken=e}},{key:"getTokenScopes",value:function(){return this.tokenScopes}},{key:"setTokenScopes",value:function(e){this.tokenScopes=e}},{key:"getState",value:function(){return this.state}},{key:"setState",value:function(e){this.state=e}},{key:"isValid",value:function(){var e=Math.floor(new Date/1e3);try{return null!=this.accessToken?e<this.accessToken.getExpiration():null!=this.idToken&&e<this.idToken.getExpiration()}catch(e){return!1}}}]),e}();t.default=d},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o={},i=function(){function e(){n(this,e)}return s(e,null,[{key:"setItem",value:function(e,t){return o[e]=t,o[e]}},{key:"getItem",value:function(e){return Object.prototype.hasOwnProperty.call(o,e)?o[e]:void 0}},{key:"removeItem",value:function(e){return delete o[e]}},{key:"clear",value:function(){return o={}}}]),e}(),r=function(){function e(){n(this,e);try{this.storageWindow=window.localStorage,this.storageWindow.setItem("aws.cognito.test-ls",1),this.storageWindow.removeItem("aws.cognito.test-ls")}catch(e){this.storageWindow=i}}return s(e,[{key:"getStorage",value:function(){return this.storageWindow}}]),e}();t.default=r},function(e,t,n){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),a=n(4),u=s(a),c=n(1),g=s(c),h=n(2),l=s(h),f=n(3),d=s(f),C=n(5),S=s(C),T=n(6),p=s(T),y=function(){function e(t){o(this,e);var n=t||{},s=n.ClientId,i=n.AppWebDomain,r=n.TokenScopesArray,a=n.RedirectUriSignIn,c=n.RedirectUriSignOut,g=n.IdentityProvider,h=n.UserPoolId,l=n.AdvancedSecurityDataCollectionFlag;if(!(null!=t&&s&&i&&a&&c))throw new Error(this.getCognitoConstants().PARAMETERERROR);if(this.clientId=s,this.appWebDomain=i,this.TokenScopesArray=r||[],!Array.isArray(r))throw new Error(this.getCognitoConstants().SCOPETYPEERROR);var f=new u.default(this.TokenScopesArray);this.RedirectUriSignIn=a,this.RedirectUriSignOut=c,this.IdentityProvider=g,this.signInUserSession=new S.default,this.responseType=this.getCognitoConstants().TOKEN,this.storage=(new p.default).getStorage(),this.signInUserSession.setTokenScopes(f),this.username=this.getLastUser(),this.userPoolId=h,this.advancedSecurityDataCollectionFlag=!0,l&&(this.advancedSecurityDataCollectionFlag=l)}return r(e,[{key:"getCognitoConstants",value:function(){var e={DOMAIN_SCHEME:"https",DOMAIN_PATH_SIGNIN:"oauth2/authorize",DOMAIN_PATH_TOKEN:"oauth2/token",DOMAIN_PATH_SIGNOUT:"logout",DOMAIN_QUERY_PARAM_REDIRECT_URI:"redirect_uri",DOMAIN_QUERY_PARAM_SIGNOUT_URI:"logout_uri",DOMAIN_QUERY_PARAM_RESPONSE_TYPE:"response_type",DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER:"identity_provider",DOMAIN_QUERY_PARAM_USERCONTEXTDATA:"userContextData",CLIENT_ID:"client_id",STATE:"state",SCOPE:"scope",TOKEN:"token",CODE:"code",POST:"POST",PARAMETERERROR:"The parameters: App client Id, App web domain, the redirect URL when you are signed in and the redirect URL when you are signed out are required.",SCOPETYPEERROR:"Scopes have to be array type. ",QUESTIONMARK:"?",POUNDSIGN:"#",COLONDOUBLESLASH:"://",SLASH:"/",AMPERSAND:"&",EQUALSIGN:"=",SPACE:" ",CONTENTTYPE:"Content-Type",CONTENTTYPEVALUE:"application/x-www-form-urlencoded",AUTHORIZATIONCODE:"authorization_code",IDTOKEN:"id_token",ACCESSTOKEN:"access_token",REFRESHTOKEN:"refresh_token",ERROR:"error",ERROR_DESCRIPTION:"error_description",STRINGTYPE:"string",STATELENGTH:32,STATEORIGINSTRING:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",WITHCREDENTIALS:"withCredentials",UNDEFINED:"undefined",SELF:"_self",HOSTNAMEREGEX:/:\/\/([0-9]?\.)?(.[^\/:]+)/i,QUERYPARAMETERREGEX1:/#(.+)/,QUERYPARAMETERREGEX2:/=(.+)/,HEADER:{"Content-Type":"application/x-www-form-urlencoded"}};return e}},{key:"getClientId",value:function(){return this.clientId}},{key:"getAppWebDomain",value:function(){return this.appWebDomain}},{key:"getCurrentUser",value:function(){var e="CognitoIdentityServiceProvider."+this.clientId+".LastAuthUser",t=this.storage.getItem(e);return t}},{key:"setUser",value:function(e){this.username=e}},{key:"getFlag",value:function(){return this.AdvancedSecurityDataCollectionFlag}},{key:"useCodeGrantFlow",value:function(){this.responseType=this.getCognitoConstants().CODE}},{key:"useImplicitFlow",value:function(){this.responseType=this.getCognitoConstants().TOKEN}},{key:"getSignInUserSession",value:function(){return this.signInUserSession}},{key:"getUsername",value:function(){return this.username}},{key:"setUsername",value:function(e){this.username=e}},{key:"getState",value:function(){return this.state}},{key:"setState",value:function(e){this.state=e}},{key:"getSession",value:function(){var e=new Set(this.TokenScopesArray),t=new Set(this.signInUserSession.tokenScopes.getScopes()),n=this.getFQDNSignIn();if(null!=this.signInUserSession&&this.signInUserSession.isValid())return this.userhandler.onSuccess(this.signInUserSession);if(this.signInUserSession=this.getCachedSession(),this.compareSets(e,t)){if(this.signInUserSession.isValid())return this.userhandler.onSuccess(this.signInUserSession);this.signInUserSession.getRefreshToken()&&this.signInUserSession.getRefreshToken().getToken()?this.refreshSession(this.signInUserSession.getRefreshToken().getToken()):this.launchUri(n)}else{var s=new u.default(this.TokenScopesArray),o=new l.default,i=new g.default,r=new d.default;this.signInUserSession.setTokenScopes(s),this.signInUserSession.setIdToken(o),this.signInUserSession.setAccessToken(i),this.signInUserSession.setRefreshToken(r),this.launchUri(n)}}},{key:"parseCognitoWebResponse",value:function(e){var t=void 0;if(e.indexOf(this.getCognitoConstants().QUESTIONMARK)>-1)t=this.getQueryParameters(e,this.getCognitoConstants().QUESTIONMARK),this.getCodeQueryParameter(t);else if(e.indexOf(this.getCognitoConstants().POUNDSIGN)>-1){if(t=this.getQueryParameters(e,this.getCognitoConstants().QUERYPARAMETERREGEX1),t.has(this.getCognitoConstants().ERROR))return this.userhandler.onFailure(t.get(this.getCognitoConstants().ERROR_DESCRIPTION));this.getTokenQueryParameter(t)}}},{key:"getCodeQueryParameter",value:function(e){var t=null;if(e.has(this.getCognitoConstants().STATE)?this.signInUserSession.setState(e.get(this.getCognitoConstants().STATE)):this.signInUserSession.setState(t),e.has(this.getCognitoConstants().CODE)){var n=e.get(this.getCognitoConstants().CODE),s=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_TOKEN),o=this.getCognitoConstants().HEADER,i={grant_type:this.getCognitoConstants().AUTHORIZATIONCODE,client_id:this.getClientId(),redirect_uri:this.RedirectUriSignIn,code:n},r=this.onSuccessExchangeForToken.bind(this),a=this.onFailure.bind(this);this.makePOSTRequest(o,i,s,r,a)}}},{key:"getTokenQueryParameter",value:function(e){var t=new l.default,n=new g.default,s=(new d.default,null);e.has(this.getCognitoConstants().IDTOKEN)?(t.setJwtToken(e.get(this.getCognitoConstants().IDTOKEN)),this.signInUserSession.setIdToken(t)):this.signInUserSession.setIdToken(t),e.has(this.getCognitoConstants().ACCESSTOKEN)?(n.setJwtToken(e.get(this.getCognitoConstants().ACCESSTOKEN)),this.signInUserSession.setAccessToken(n)):this.signInUserSession.setAccessToken(n),e.has(this.getCognitoConstants().STATE)?this.signInUserSession.setState(e.get(this.getCognitoConstants().STATE)):this.signInUserSession.setState(s),this.cacheTokensScopes(),this.userhandler.onSuccess(this.signInUserSession)}},{key:"getCachedSession",value:function(){if(!this.username)return new S.default;var e="CognitoIdentityServiceProvider."+this.getClientId()+"."+this.username,t=e+".idToken",n=e+".accessToken",s=e+".refreshToken",o=e+".tokenScopesString",i=this.storage.getItem(o),r=[];i&&(r=i.split(" "));var a=new u.default(r),c=new l.default(this.storage.getItem(t)),h=new g.default(this.storage.getItem(n)),f=new d.default(this.storage.getItem(s)),C={IdToken:c,AccessToken:h,RefreshToken:f,TokenScopes:a},T=new S.default(C);return T}},{key:"getLastUser",value:function(){var e="CognitoIdentityServiceProvider."+this.getClientId(),t=e+".LastAuthUser",n=this.storage.getItem(t);if(n)return n}},{key:"cacheTokensScopes",value:function(){var e="CognitoIdentityServiceProvider."+this.getClientId(),t=this.signInUserSession.getAccessToken().getUsername();this.username=t;var n=e+"."+t+".idToken",s=e+"."+t+".accessToken",o=e+"."+t+".refreshToken",i=e+".LastAuthUser",r=e+"."+t+".tokenScopesString",a=this.signInUserSession.getTokenScopes().getScopes(),u=a.join(" ");this.storage.setItem(n,this.signInUserSession.getIdToken().getJwtToken()),this.storage.setItem(s,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(o,this.signInUserSession.getRefreshToken().getToken()),this.storage.setItem(i,t),this.storage.setItem(r,u)}},{key:"compareSets",value:function(e,t){if(e.size!==t.size)return!1;var n=!0,s=!1,o=void 0;try{for(var i,r=e[Symbol.iterator]();!(n=(i=r.next()).done);n=!0){var a=i.value;if(!t.has(a))return!1}}catch(e){s=!0,o=e}finally{try{!n&&r.return&&r.return()}finally{if(s)throw o}}return!0}},{key:"getHostName",value:function(e){var t=e.match(this.getCognitoConstants().HOSTNAMEREGEX);if(null!=t&&t.length>2&&i(t[2])===this.getCognitoConstants().STRINGTYPE&&t[2].length>0)return t[2]}},{key:"getQueryParameters",value:function(e,t){var n=String(e).split(t),s=n[1],o=String(s).split(this.getCognitoConstants().AMPERSAND),i=o.length,r=new Map,a=void 0;for(a=0;a<i;a++)o[a]=String(o[a]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2),r.set(o[a][0],o[a][1]);return r}},{key:"generateRandomString",value:function(e,t){for(var n="",s=e;s>0;--s)n+=t[Math.round(Math.random()*(t.length-1))];return n}},{key:"clearCachedTokensScopes",value:function(){var e="CognitoIdentityServiceProvider."+this.getClientId(),t=e+"."+this.username+".idToken",n=e+"."+this.username+".accessToken",s=e+"."+this.username+".refreshToken",o=e+".LastAuthUser",i=e+"."+this.username+".tokenScopesString";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(s),this.storage.removeItem(o),this.storage.removeItem(i)}},{key:"refreshSession",value:function(e){var t=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_TOKEN),n=this.getCognitoConstants().HEADER,s={grant_type:this.getCognitoConstants().REFRESHTOKEN,client_id:this.getClientId(),redirect_uri:this.RedirectUriSignIn,refresh_token:e},o=this.onSuccessRefreshToken.bind(this),i=this.onFailure.bind(this);this.makePOSTRequest(n,s,t,o,i)}},{key:"makePOSTRequest",value:function(e,t,n,s,o){var i=this.createCORSRequest(this.getCognitoConstants().POST,n),r="";if(i){for(var a in e)i.setRequestHeader(a,e[a]);for(var u in t)r=r.concat(u,this.getCognitoConstants().EQUALSIGN,t[u],this.getCognitoConstants().AMPERSAND);r=r.substring(0,r.length-1),i.send(r),i.onreadystatechange=function(){4===i.readyState&&(200===i.status?s(i.responseText):o(i.responseText))}}}},{key:"createCORSRequest",value:function(e,t){var n=new XMLHttpRequest;return n.open(e,t,!0),this.getCognitoConstants().WITHCREDENTIALS in n?n.open(e,t,!0):("undefined"==typeof XDomainRequest?"undefined":i(XDomainRequest))!==this.getCognitoConstants().UNDEFINED?(n=new XDomainRequest,n.open(e,t)):n=null,n}},{key:"onFailure",value:function(e){this.userhandler.onFailure(e)}},{key:"onSuccessRefreshToken",value:function(e){var t=JSON.parse(e);if(Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().ERROR)){var n=this.getFQDNSignIn();this.launchUri(n)}else Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().IDTOKEN)&&this.signInUserSession.setIdToken(new l.default(t.id_token)),Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().ACCESSTOKEN)&&this.signInUserSession.setAccessToken(new g.default(t.access_token)),this.cacheTokensScopes(),this.userhandler.onSuccess(this.signInUserSession)}},{key:"onSuccessExchangeForToken",value:function(e){var t=JSON.parse(e),n=new d.default,s=new g.default,o=new l.default;return Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().ERROR)?this.userhandler.onFailure(e):(Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().IDTOKEN)?this.signInUserSession.setIdToken(new l.default(t.id_token)):this.signInUserSession.setIdToken(o),Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().ACCESSTOKEN)?this.signInUserSession.setAccessToken(new g.default(t.access_token)):this.signInUserSession.setAccessToken(s),Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().REFRESHTOKEN)?this.signInUserSession.setRefreshToken(new d.default(t.refresh_token)):this.signInUserSession.setRefreshToken(n),this.cacheTokensScopes(),void this.userhandler.onSuccess(this.signInUserSession))}},{key:"launchUri",value:function(e){window.open(e,this.getCognitoConstants().SELF)}},{key:"getSpaceSeperatedScopeString",value:function(){var e=this.signInUserSession.getTokenScopes().getScopes();return e=e.join(this.getCognitoConstants().SPACE),encodeURIComponent(e)}},{key:"getFQDNSignIn",value:function(){null==this.state&&(this.state=this.generateRandomString(this.getCognitoConstants().STATELENGTH,this.getCognitoConstants().STATEORIGINSTRING));var e=this.IdentityProvider?this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER,this.getCognitoConstants().EQUALSIGN,this.IdentityProvider):"",t=this.getSpaceSeperatedScopeString(),n="",s=this.getUserContextData();s&&(n=this.getCognitoConstants().AMPERSAND+this.getCognitoConstants().DOMAIN_QUERY_PARAM_USERCONTEXTDATA+this.getCognitoConstants().EQUALSIGN+this.getUserContextData());var o=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_SIGNIN,this.getCognitoConstants().QUESTIONMARK,this.getCognitoConstants().DOMAIN_QUERY_PARAM_REDIRECT_URI,this.getCognitoConstants().EQUALSIGN,encodeURIComponent(this.RedirectUriSignIn),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().DOMAIN_QUERY_PARAM_RESPONSE_TYPE,this.getCognitoConstants().EQUALSIGN,this.responseType,this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().CLIENT_ID,this.getCognitoConstants().EQUALSIGN,this.getClientId(),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().STATE,this.getCognitoConstants().EQUALSIGN,this.state,this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().SCOPE,this.getCognitoConstants().EQUALSIGN,t,e,n);return o}},{key:"signOut",value:function(){var e=this.getFQDNSignOut();this.signInUserSession=null,this.clearCachedTokensScopes(),this.launchUri(e)}},{key:"getFQDNSignOut",value:function(){var e=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_SIGNOUT,this.getCognitoConstants().QUESTIONMARK,this.getCognitoConstants().DOMAIN_QUERY_PARAM_SIGNOUT_URI,this.getCognitoConstants().EQUALSIGN,encodeURIComponent(this.RedirectUriSignOut),this.getCognitoConstants().AMPERSAND,this.getCognitoConstants().CLIENT_ID,this.getCognitoConstants().EQUALSIGN,this.getClientId());return e}},{key:"getUserContextData",value:function(){if("undefined"!=typeof AmazonCognitoAdvancedSecurityData){var e="";this.username&&(e=this.username);var t="";return this.userpoolId&&(t=this.userpoolId),this.advancedSecurityDataCollectionFlag?AmazonCognitoAdvancedSecurityData.getData(e,t,this.clientId):void 0}}},{key:"isUserSignedIn",value:function(){return null!=this.getCachedSession()&&this.getCachedSession().isValid()||null!=this.signInUserSession&&this.signInUserSession.isValid()}}]),e}();t.default=y},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=function(){function e(){n(this,e)}return s(e,[{key:"getNowString",value:function(){var e=new Date,t=i[e.getUTCDay()],n=o[e.getUTCMonth()],s=e.getUTCDate(),r=e.getUTCHours();r<10&&(r="0"+r);var a=e.getUTCMinutes();a<10&&(a="0"+a);var u=e.getUTCSeconds();u<10&&(u="0"+u);var c=e.getUTCFullYear(),g=t+" "+n+" "+s+" "+r+":"+a+":"+u+" UTC "+c;return g}}]),e}();t.default=r},function(e,t,n){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(1);Object.defineProperty(t,"CognitoAccessToken",{enumerable:!0,get:function(){return s(o).default}});var i=n(2);Object.defineProperty(t,"CognitoIdToken",{enumerable:!0,get:function(){return s(i).default}});var r=n(3);Object.defineProperty(t,"CognitoRefreshToken",{enumerable:!0,get:function(){return s(r).default}});var a=n(4);Object.defineProperty(t,"CognitoTokenScopes",{enumerable:!0,get:function(){return s(a).default}});var u=n(7);Object.defineProperty(t,"CognitoAuth",{enumerable:!0,get:function(){return s(u).default}});var c=n(5);Object.defineProperty(t,"CognitoAuthSession",{enumerable:!0,get:function(){return s(c).default}});var g=n(8);Object.defineProperty(t,"DateHelper",{enumerable:!0,get:function(){return s(g).default}});var h=n(6);Object.defineProperty(t,"StorageHelper",{enumerable:!0,get:function(){return s(h).default}})}])}); | ||
//# sourceMappingURL=amazon-cognito-auth.min.js.map |
@@ -20,6 +20,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
import { Buffer } from 'buffer/'; | ||
/** @class */ | ||
var CognitoAccessToken = function () { | ||
@@ -64,3 +61,7 @@ /** | ||
CognitoAccessToken.prototype.getExpiration = function getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
@@ -77,3 +78,4 @@ | ||
} | ||
return this.payload.username; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
}; | ||
@@ -87,5 +89,5 @@ | ||
CognitoAccessToken.prototype.decodePayload = function decodePayload() { | ||
var payload = this.jwtToken.split('.')[1]; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -92,0 +94,0 @@ return {}; |
@@ -132,2 +132,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
ERROR: 'error', | ||
ERROR_DESCRIPTION: 'error_description', | ||
STRINGTYPE: 'string', | ||
@@ -166,5 +167,5 @@ STATELENGTH: 32, | ||
/** | ||
* method for getting the current user of the application from the local storage | ||
* method for getting the current signed in user of the application | ||
* | ||
* @returns {CognitoAuth} the user retrieved from storage | ||
* @returns {string} the current signed in user's username | ||
*/ | ||
@@ -191,2 +192,6 @@ | ||
CognitoAuth.prototype.getFlag = function getFlag() { | ||
return this.AdvancedSecurityDataCollectionFlag; | ||
}; | ||
/** | ||
@@ -307,7 +312,13 @@ * sets response type to 'code' | ||
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) { | ||
var map = void 0; | ||
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) { | ||
this.getCodeQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUESTIONMARK); | ||
this.getCodeQueryParameter(map); | ||
} else if (httpRequestResponse.indexOf(this.getCognitoConstants().POUNDSIGN) > -1) { | ||
// To parse the response to get tokens | ||
this.getTokenQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUERYPARAMETERREGEX1); | ||
if (map.has(this.getCognitoConstants().ERROR)) { | ||
return this.userhandler.onFailure(map.get(this.getCognitoConstants().ERROR_DESCRIPTION)); | ||
} | ||
// To use the map to get tokens | ||
this.getTokenQueryParameter(map); | ||
} | ||
@@ -317,10 +328,9 @@ }; | ||
/** | ||
* @param {string} httpRequestResponse the http request response | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
* Parse the http request response and proceed according to code response type. | ||
* Get the query parameter map and proceed according to code response type. | ||
*/ | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(httpRequestResponse) { | ||
var map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUESTIONMARK); | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) { | ||
var state = null; | ||
@@ -350,4 +360,4 @@ if (map.has(this.getCognitoConstants().STATE)) { | ||
/** | ||
* Parse the http request response and proceed according to token response type. | ||
* @param {string} httpRequestResponse the http request response | ||
* Get the query parameter map and proceed according to token response type. | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
@@ -357,4 +367,3 @@ */ | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(httpRequestResponse) { | ||
var map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUERYPARAMETERREGEX1); | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) { | ||
var idToken = new CognitoIdToken(); | ||
@@ -376,8 +385,2 @@ var accessToken = new CognitoAccessToken(); | ||
} | ||
if (map.has(this.getCognitoConstants().REFRESHTOKEN)) { | ||
refreshToken.setToken(map.get(this.getCognitoConstants().REFRESHTOKEN)); | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} else { | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} | ||
if (map.has(this.getCognitoConstants().STATE)) { | ||
@@ -389,3 +392,3 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE)); | ||
this.cacheTokensScopes(); | ||
return this.userhandler.onSuccess(this.signInUserSession); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
@@ -392,0 +395,0 @@ |
@@ -6,3 +6,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
@@ -21,6 +20,3 @@ * You may not use this file except in compliance with the License. | ||
import { Buffer } from 'buffer/'; | ||
/** @class */ | ||
var CognitoIdToken = function () { | ||
@@ -65,3 +61,7 @@ /** | ||
CognitoIdToken.prototype.getExpiration = function getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
@@ -75,5 +75,5 @@ | ||
CognitoIdToken.prototype.decodePayload = function decodePayload() { | ||
var payload = this.jwtToken.split('.')[1]; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -80,0 +80,0 @@ return {}; |
@@ -5,21 +5,21 @@ 'use strict'; | ||
var _buffer = require('buffer/'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
/** @class */ | ||
@@ -65,3 +65,7 @@ var CognitoAccessToken = function () { | ||
CognitoAccessToken.prototype.getExpiration = function getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
@@ -78,3 +82,4 @@ | ||
} | ||
return this.payload.username; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
}; | ||
@@ -88,5 +93,5 @@ | ||
CognitoAccessToken.prototype.decodePayload = function decodePayload() { | ||
var payload = this.jwtToken.split('.')[1]; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(_buffer.Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -93,0 +98,0 @@ return {}; |
@@ -152,2 +152,3 @@ 'use strict'; | ||
ERROR: 'error', | ||
ERROR_DESCRIPTION: 'error_description', | ||
STRINGTYPE: 'string', | ||
@@ -186,5 +187,5 @@ STATELENGTH: 32, | ||
/** | ||
* method for getting the current user of the application from the local storage | ||
* method for getting the current signed in user of the application | ||
* | ||
* @returns {CognitoAuth} the user retrieved from storage | ||
* @returns {string} the current signed in user's username | ||
*/ | ||
@@ -211,2 +212,6 @@ | ||
CognitoAuth.prototype.getFlag = function getFlag() { | ||
return this.AdvancedSecurityDataCollectionFlag; | ||
}; | ||
/** | ||
@@ -327,7 +332,13 @@ * sets response type to 'code' | ||
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) { | ||
var map = void 0; | ||
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) { | ||
this.getCodeQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUESTIONMARK); | ||
this.getCodeQueryParameter(map); | ||
} else if (httpRequestResponse.indexOf(this.getCognitoConstants().POUNDSIGN) > -1) { | ||
// To parse the response to get tokens | ||
this.getTokenQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUERYPARAMETERREGEX1); | ||
if (map.has(this.getCognitoConstants().ERROR)) { | ||
return this.userhandler.onFailure(map.get(this.getCognitoConstants().ERROR_DESCRIPTION)); | ||
} | ||
// To use the map to get tokens | ||
this.getTokenQueryParameter(map); | ||
} | ||
@@ -337,10 +348,9 @@ }; | ||
/** | ||
* @param {string} httpRequestResponse the http request response | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
* Parse the http request response and proceed according to code response type. | ||
* Get the query parameter map and proceed according to code response type. | ||
*/ | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(httpRequestResponse) { | ||
var map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUESTIONMARK); | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) { | ||
var state = null; | ||
@@ -370,4 +380,4 @@ if (map.has(this.getCognitoConstants().STATE)) { | ||
/** | ||
* Parse the http request response and proceed according to token response type. | ||
* @param {string} httpRequestResponse the http request response | ||
* Get the query parameter map and proceed according to token response type. | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
@@ -377,4 +387,3 @@ */ | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(httpRequestResponse) { | ||
var map = this.getQueryParameters(httpRequestResponse, this.getCognitoConstants().QUERYPARAMETERREGEX1); | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) { | ||
var idToken = new _CognitoIdToken2.default(); | ||
@@ -396,8 +405,2 @@ var accessToken = new _CognitoAccessToken2.default(); | ||
} | ||
if (map.has(this.getCognitoConstants().REFRESHTOKEN)) { | ||
refreshToken.setToken(map.get(this.getCognitoConstants().REFRESHTOKEN)); | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} else { | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} | ||
if (map.has(this.getCognitoConstants().STATE)) { | ||
@@ -409,3 +412,3 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE)); | ||
this.cacheTokensScopes(); | ||
return this.userhandler.onSuccess(this.signInUserSession); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
@@ -412,0 +415,0 @@ |
@@ -5,20 +5,19 @@ 'use strict'; | ||
var _buffer = require('buffer/'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. | ||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
@@ -65,3 +64,7 @@ /** @class */ | ||
CognitoIdToken.prototype.getExpiration = function getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
@@ -75,5 +78,5 @@ | ||
CognitoIdToken.prototype.decodePayload = function decodePayload() { | ||
var payload = this.jwtToken.split('.')[1]; | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(_buffer.Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -80,0 +83,0 @@ return {}; |
{ | ||
"name": "amazon-cognito-auth-js", | ||
"description": "Amazon Cognito Auth JavaScript SDK", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"author": { | ||
@@ -48,5 +48,2 @@ "name": "Amazon Web Services", | ||
"jsnext:main": "es/index.js", | ||
"dependencies": { | ||
"buffer": "4.9.1" | ||
}, | ||
"devDependencies": { | ||
@@ -67,2 +64,2 @@ "babel-cli": "^6.23.0", | ||
} | ||
} | ||
} |
@@ -214,2 +214,7 @@ # Amazon Cognito Auth SDK for JavaScript | ||
**v1.1.5** | ||
* Added `parseCognitoWebResponse()` onFailure() callback and fixed the `CognitoAuth.getCurrentUser()` returning `undefined` when using implicit grant flow. | ||
**v1.1.4** | ||
@@ -222,3 +227,3 @@ | ||
* Updated doc and uploaded `es` folder. | ||
* Updated doc and uploaded `es` folder. | ||
@@ -235,3 +240,2 @@ | ||
**v1.1.0** | ||
@@ -238,0 +242,0 @@ |
@@ -18,4 +18,2 @@ /*! | ||
import { Buffer } from 'buffer/'; | ||
/** @class */ | ||
@@ -53,3 +51,7 @@ export default class CognitoAccessToken { | ||
getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
} | ||
@@ -64,3 +66,4 @@ | ||
} | ||
return this.payload.username; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
} | ||
@@ -72,5 +75,5 @@ | ||
decodePayload() { | ||
const payload = this.jwtToken.split('.')[1]; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -77,0 +80,0 @@ return {}; |
@@ -118,2 +118,3 @@ /*! | ||
ERROR: 'error', | ||
ERROR_DESCRIPTION: 'error_description', | ||
STRINGTYPE: 'string', | ||
@@ -151,8 +152,8 @@ STATELENGTH: 32, | ||
* @returns {CognitoAuth} the user retrieved from storage | ||
*/ | ||
getCurrentUser() { | ||
*/ | ||
getCurrentUser() { | ||
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`; | ||
const lastAuthUser = this.storage.getItem(lastUserKey); | ||
return lastAuthUser; | ||
return lastAuthUser; | ||
} | ||
@@ -267,7 +268,19 @@ | ||
parseCognitoWebResponse(httpRequestResponse) { | ||
let map; | ||
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) { | ||
this.getCodeQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters( | ||
httpRequestResponse, | ||
this.getCognitoConstants().QUESTIONMARK | ||
); | ||
this.getCodeQueryParameter(map); | ||
} else if (httpRequestResponse.indexOf(this.getCognitoConstants().POUNDSIGN) > -1) { | ||
// To parse the response to get tokens | ||
this.getTokenQueryParameter(httpRequestResponse); | ||
map = this.getQueryParameters( | ||
httpRequestResponse, | ||
this.getCognitoConstants().QUERYPARAMETERREGEX1 | ||
); | ||
if (map.has(this.getCognitoConstants().ERROR)) { | ||
return this.userhandler.onFailure(map.get(this.getCognitoConstants().ERROR_DESCRIPTION)); | ||
} | ||
// To use the map to get tokens | ||
this.getTokenQueryParameter(map); | ||
} | ||
@@ -277,11 +290,7 @@ } | ||
/** | ||
* @param {string} httpRequestResponse the http request response | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
* Parse the http request response and proceed according to code response type. | ||
* Get the query parameter map and proceed according to code response type. | ||
*/ | ||
getCodeQueryParameter(httpRequestResponse) { | ||
const map = this.getQueryParameters( | ||
httpRequestResponse, | ||
this.getCognitoConstants().QUESTIONMARK | ||
); | ||
getCodeQueryParameter(map) { | ||
const state = null; | ||
@@ -313,11 +322,7 @@ if (map.has(this.getCognitoConstants().STATE)) { | ||
/** | ||
* Parse the http request response and proceed according to token response type. | ||
* @param {string} httpRequestResponse the http request response | ||
* Get the query parameter map and proceed according to token response type. | ||
* @param {map} Query parameter map | ||
* @returns {void} | ||
*/ | ||
getTokenQueryParameter(httpRequestResponse) { | ||
const map = this.getQueryParameters( | ||
httpRequestResponse, | ||
this.getCognitoConstants().QUERYPARAMETERREGEX1 | ||
); | ||
getTokenQueryParameter(map) { | ||
const idToken = new CognitoIdToken(); | ||
@@ -339,8 +344,2 @@ const accessToken = new CognitoAccessToken(); | ||
} | ||
if (map.has(this.getCognitoConstants().REFRESHTOKEN)) { | ||
refreshToken.setToken(map.get(this.getCognitoConstants().REFRESHTOKEN)); | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} else { | ||
this.signInUserSession.setRefreshToken(refreshToken); | ||
} | ||
if (map.has(this.getCognitoConstants().STATE)) { | ||
@@ -352,3 +351,3 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE)); | ||
this.cacheTokensScopes(); | ||
return this.userhandler.onSuccess(this.signInUserSession); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
} | ||
@@ -355,0 +354,0 @@ |
/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
@@ -18,4 +17,2 @@ * You may not use this file except in compliance with the License. | ||
import { Buffer } from 'buffer/'; | ||
/** @class */ | ||
@@ -53,3 +50,7 @@ export default class CognitoIdToken { | ||
getExpiration() { | ||
return this.payload.exp; | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
} | ||
@@ -61,5 +62,5 @@ | ||
decodePayload() { | ||
const payload = this.jwtToken.split('.')[1]; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(Buffer.from(payload, 'base64').toString('utf8')); | ||
return JSON.parse(atob(jwtPayload)); | ||
} catch (err) { | ||
@@ -69,2 +70,2 @@ return {}; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
256
1237163
22821
- Removedbuffer@4.9.1
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedisarray@1.0.0(transitive)