amazon-cognito-auth-js
Advanced tools
Comparing version 1.2.4 to 1.2.5-atob-react-native
@@ -17,3 +17,3 @@ /*! | ||
*/ | ||
!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);/*! | ||
!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(o){if(n[o])return n[o].exports;var s=n[o]={exports:{},id:o,loaded:!1};return e[o].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function o(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 s=n(11);Object.keys(s).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(t,e,{enumerable:!0,get:function(){return s[e]}})});o(s);/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
@@ -34,3 +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(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,f=n.Storage;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 d=new u.default(this.TokenScopesArray);this.RedirectUriSignIn=a,this.RedirectUriSignOut=c,this.IdentityProvider=g,this.responseType=this.getCognitoConstants().TOKEN,this.storage=f||(new p.default).getStorage(),this.username=this.getLastUser(),this.userPoolId=h,this.signInUserSession=this.getCachedSession(),+this.signInUserSession.setTokenScopes(d),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:"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){var n=e.split(this.getCognitoConstants().POUNDSIGN)[0];t=this.getQueryParameters(n,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.signInUserSession&&this.signInUserSession.isValid()||null!=this.getCachedSession()&&this.getCachedSession().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}})}])}); | ||
"undefined"!=typeof window&&!window.crypto&&window.msCrypto&&(window.crypto=window.msCrypto)},function(e,t,n){"use strict";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 s=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),i=n(6),r=function(){function e(t){o(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((0,i.decode)(e)).exp}}},{key:"getUsername",value:function(){if(null!==this.jwtToken){var e=this.jwtToken.split(".")[1];return JSON.parse((0,i.decode)(e)).username}}},{key:"decodePayload",value:function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse((0,i.decode)(e))}catch(e){return{}}}}]),e}();t.default=r},function(e,t,n){"use strict";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 s=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),i=n(6),r=function(){function e(t){o(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((0,i.decode)(e)).exp}}},{key:"decodePayload",value:function(){var e=this.jwtToken.split(".")[1];try{return JSON.parse((0,i.decode)(e))}catch(e){return{}}}}]),e}();t.default=r},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 o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s=function(){function e(t){n(this,e),this.refreshToken=t||""}return o(e,[{key:"getToken",value:function(){return this.refreshToken}},{key:"setToken",value:function(e){this.refreshToken=e}}]),e}();t.default=s},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 o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s=function(){function e(t){n(this,e),this.tokenScopes=t||[]}return o(e,[{key:"getScopes",value:function(){return this.tokenScopes}},{key:"setTokenScopes",value:function(e){this.tokenScopes=e}}]),e}();t.default=s},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function s(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=n(4),a=o(r),u=n(1),c=o(u),h=n(2),g=o(h),l=n(3),f=o(l),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.IdToken,o=t.RefreshToken,i=t.AccessToken,r=t.TokenScopes,u=t.State;s(this,e),n?this.idToken=n:this.idToken=new g.default,o?this.refreshToken=o: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){(function(e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.decode=function(t){return e.atob(t)}}).call(t,function(){return this}())},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 o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s={},i=function(){function e(){n(this,e)}return o(e,null,[{key:"setItem",value:function(e,t){return s[e]=t,s[e]}},{key:"getItem",value:function(e){return Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0}},{key:"removeItem",value:function(e){return delete s[e]}},{key:"clear",value:function(){return s={}}}]),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 o(e,[{key:"getStorage",value:function(){return this.storageWindow}}]),e}();t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function s(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=n(4),u=o(a),c=n(1),h=o(c),g=n(2),l=o(g),f=n(3),d=o(f),C=n(5),S=o(C),p=n(7),T=o(p),y=function(){function e(t){s(this,e);var n=t||{},o=n.ClientId,i=n.AppWebDomain,r=n.TokenScopesArray,a=n.RedirectUriSignIn,c=n.RedirectUriSignOut,h=n.IdentityProvider,g=n.UserPoolId,l=n.AdvancedSecurityDataCollectionFlag,f=n.Storage;if(!(null!=t&&o&&i&&a&&c))throw new Error(this.getCognitoConstants().PARAMETERERROR);if(this.clientId=o,this.appWebDomain=i,this.TokenScopesArray=r||[],!Array.isArray(r))throw new Error(this.getCognitoConstants().SCOPETYPEERROR);var d=new u.default(this.TokenScopesArray);this.RedirectUriSignIn=a,this.RedirectUriSignOut=c,this.IdentityProvider=h,this.responseType=this.getCognitoConstants().TOKEN,this.storage=f||(new T.default).getStorage(),this.username=this.getLastUser(),this.userPoolId=g,this.signInUserSession=this.getCachedSession(),+this.signInUserSession.setTokenScopes(d),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:"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 o=new u.default(this.TokenScopesArray),s=new l.default,i=new h.default,r=new d.default;this.signInUserSession.setTokenScopes(o),this.signInUserSession.setIdToken(s),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){var n=e.split(this.getCognitoConstants().POUNDSIGN)[0];t=this.getQueryParameters(n,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),o=this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH,this.getAppWebDomain(),this.getCognitoConstants().SLASH,this.getCognitoConstants().DOMAIN_PATH_TOKEN),s=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(s,i,o,r,a)}}},{key:"getTokenQueryParameter",value:function(e){var t=new l.default,n=new h.default,o=(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(o),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",o=e+".refreshToken",s=e+".tokenScopesString",i=this.storage.getItem(s),r=[];i&&(r=i.split(" "));var a=new u.default(r),c=new l.default(this.storage.getItem(t)),g=new h.default(this.storage.getItem(n)),f=new d.default(this.storage.getItem(o)),C={IdToken:c,AccessToken:g,RefreshToken:f,TokenScopes:a},p=new S.default(C);return p}},{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",o=e+"."+t+".accessToken",s=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(o,this.signInUserSession.getAccessToken().getJwtToken()),this.storage.setItem(s,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,o=!1,s=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){o=!0,s=e}finally{try{!n&&r.return&&r.return()}finally{if(o)throw s}}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),o=n[1],s=String(o).split(this.getCognitoConstants().AMPERSAND),i=s.length,r=new Map,a=void 0;for(a=0;a<i;a++)s[a]=String(s[a]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2),r.set(s[a][0],s[a][1]);return r}},{key:"generateRandomString",value:function(e,t){for(var n="",o=e;o>0;--o)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",o=e+"."+this.username+".refreshToken",s=e+".LastAuthUser",i=e+"."+this.username+".tokenScopesString";this.storage.removeItem(t),this.storage.removeItem(n),this.storage.removeItem(o),this.storage.removeItem(s),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,o={grant_type:this.getCognitoConstants().REFRESHTOKEN,client_id:this.getClientId(),redirect_uri:this.RedirectUriSignIn,refresh_token:e},s=this.onSuccessRefreshToken.bind(this),i=this.onFailure.bind(this);this.makePOSTRequest(n,o,t,s,i)}},{key:"makePOSTRequest",value:function(e,t,n,o,s){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?o(i.responseText):s(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 h.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,o=new h.default,s=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(s),Object.prototype.hasOwnProperty.call(t,this.getCognitoConstants().ACCESSTOKEN)?this.signInUserSession.setAccessToken(new h.default(t.access_token)):this.signInUserSession.setAccessToken(o),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="",o=this.getUserContextData();o&&(n=this.getCognitoConstants().AMPERSAND+this.getCognitoConstants().DOMAIN_QUERY_PARAM_USERCONTEXTDATA+this.getCognitoConstants().EQUALSIGN+this.getUserContextData());var s=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 s}},{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.signInUserSession&&this.signInUserSession.isValid()||null!=this.getCachedSession()&&this.getCachedSession().isValid()}}]),e}();t.default=y},function(e,t,n){"use strict";function o(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}function s(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 o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=n(12),a=o(r),u=function(){function e(t){s(this,e),this.domain=t.domain,t.path?this.path=t.path:this.path="/",Object.prototype.hasOwnProperty.call(t,"expires")?this.expires=t.expires:this.expires=365,Object.prototype.hasOwnProperty.call(t,"secure")?this.secure=t.secure:this.secure=!0}return i(e,[{key:"setItem",value:function(e,t){return a.set(e,t,{path:this.path,expires:this.expires,domain:this.domain,secure:this.secure}),a.get(e)}},{key:"getItem",value:function(e){return a.get(e)}},{key:"removeItem",value:function(e){return a.remove(e,{path:this.path,domain:this.domain,secure:this.secure})}},{key:"clear",value:function(){var e=a.get(),t=void 0;for(t=0;t<e.length;++t)a.remove(e[t]);return{}}}]),e}();t.default=u},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 o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s=["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 o(e,[{key:"getNowString",value:function(){var e=new Date,t=i[e.getUTCDay()],n=s[e.getUTCMonth()],o=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(),h=t+" "+n+" "+o+" "+r+":"+a+":"+u+" UTC "+c;return h}}]),e}();t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var s=n(1);Object.defineProperty(t,"CognitoAccessToken",{enumerable:!0,get:function(){return o(s).default}});var i=n(2);Object.defineProperty(t,"CognitoIdToken",{enumerable:!0,get:function(){return o(i).default}});var r=n(3);Object.defineProperty(t,"CognitoRefreshToken",{enumerable:!0,get:function(){return o(r).default}});var a=n(4);Object.defineProperty(t,"CognitoTokenScopes",{enumerable:!0,get:function(){return o(a).default}});var u=n(8);Object.defineProperty(t,"CognitoAuth",{enumerable:!0,get:function(){return o(u).default}});var c=n(5);Object.defineProperty(t,"CognitoAuthSession",{enumerable:!0,get:function(){return o(c).default}});var h=n(10);Object.defineProperty(t,"DateHelper",{enumerable:!0,get:function(){return o(h).default}});var g=n(7);Object.defineProperty(t,"StorageHelper",{enumerable:!0,get:function(){return o(g).default}});var l=n(9);Object.defineProperty(t,"CookieStorage",{enumerable:!0,get:function(){return o(l).default}})},function(e,t,n){var o,s;!function(i){var r=!1;if(o=i,s="function"==typeof o?o.call(t,n,t,e):o,!(void 0!==s&&(e.exports=s)),r=!0,e.exports=i(),r=!0,!r){var a=window.Cookies,u=window.Cookies=i();u.noConflict=function(){return window.Cookies=a,u}}}(function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function t(n){function o(t,s,i){var r;if("undefined"!=typeof document){if(arguments.length>1){if(i=e({path:"/"},o.defaults,i),"number"==typeof i.expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i.expires=i.expires?i.expires.toUTCString():"";try{r=JSON.stringify(s),/^[\{\[]/.test(r)&&(s=r)}catch(e){}s=n.write?n.write(s,t):encodeURIComponent(String(s)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)),t=t.replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent),t=t.replace(/[\(\)]/g,escape);var u="";for(var c in i)i[c]&&(u+="; "+c,i[c]!==!0&&(u+="="+i[c]));return document.cookie=t+"="+s+u}t||(r={});for(var h=document.cookie?document.cookie.split("; "):[],g=/(%[0-9A-Z]{2})+/g,l=0;l<h.length;l++){var f=h[l].split("="),d=f.slice(1).join("=");this.json||'"'!==d.charAt(0)||(d=d.slice(1,-1));try{var C=f[0].replace(g,decodeURIComponent);if(d=n.read?n.read(d,C):n(d,C)||d.replace(g,decodeURIComponent),this.json)try{d=JSON.parse(d)}catch(e){}if(t===C){r=d;break}t||(r[C]=d)}catch(e){}}return r}}return o.set=o,o.get=function(e){return o.call(o,e)},o.getJSON=function(){return o.apply({json:!0},[].slice.call(arguments))},o.defaults={},o.remove=function(t,n){o(t,"",e(n,{expires:-1}))},o.withConverter=t,o}return t(function(){})})}])}); | ||
//# sourceMappingURL=amazon-cognito-auth.min.js.map |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -20,4 +18,6 @@ * Amazon Cognito Auth SDK for JavaScript | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
var CognitoAccessToken = function () { | ||
export default class CognitoAccessToken { | ||
/** | ||
@@ -27,5 +27,3 @@ * Constructs a new CognitoAccessToken object | ||
*/ | ||
function CognitoAccessToken(AccessToken) { | ||
_classCallCheck(this, CognitoAccessToken); | ||
constructor(AccessToken) { | ||
// Assign object | ||
@@ -39,7 +37,5 @@ this.jwtToken = AccessToken || ''; | ||
*/ | ||
CognitoAccessToken.prototype.getJwtToken = function getJwtToken() { | ||
getJwtToken() { | ||
return this.jwtToken; | ||
}; | ||
} | ||
@@ -51,7 +47,5 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.setJwtToken = function setJwtToken(accessToken) { | ||
setJwtToken(accessToken) { | ||
this.jwtToken = accessToken; | ||
}; | ||
} | ||
@@ -61,11 +55,9 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.getExpiration = function getExpiration() { | ||
getExpiration() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -75,11 +67,9 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.getUsername = function getUsername() { | ||
getUsername() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).username; | ||
} | ||
@@ -89,16 +79,10 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.decodePayload = function decodePayload() { | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
decodePayload() { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
return {}; | ||
} | ||
}; | ||
return CognitoAccessToken; | ||
}(); | ||
export default CognitoAccessToken; | ||
} | ||
} |
@@ -1,5 +0,1 @@ | ||
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; }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -30,4 +26,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoAuth = function () { | ||
export default class CognitoAuth { | ||
/** | ||
@@ -52,16 +47,6 @@ * Constructs a new CognitoAuth object | ||
*/ | ||
function CognitoAuth(data) { | ||
_classCallCheck(this, CognitoAuth); | ||
var _ref = data || {}, | ||
ClientId = _ref.ClientId, | ||
AppWebDomain = _ref.AppWebDomain, | ||
TokenScopesArray = _ref.TokenScopesArray, | ||
RedirectUriSignIn = _ref.RedirectUriSignIn, | ||
RedirectUriSignOut = _ref.RedirectUriSignOut, | ||
IdentityProvider = _ref.IdentityProvider, | ||
UserPoolId = _ref.UserPoolId, | ||
AdvancedSecurityDataCollectionFlag = _ref.AdvancedSecurityDataCollectionFlag, | ||
Storage = _ref.Storage; | ||
constructor(data) { | ||
const { ClientId, AppWebDomain, TokenScopesArray, | ||
RedirectUriSignIn, RedirectUriSignOut, IdentityProvider, UserPoolId, | ||
AdvancedSecurityDataCollectionFlag, Storage } = data || {}; | ||
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) { | ||
@@ -77,3 +62,3 @@ throw new Error(this.getCognitoConstants().PARAMETERERROR); | ||
} | ||
var tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
this.RedirectUriSignIn = RedirectUriSignIn; | ||
@@ -101,6 +86,4 @@ this.RedirectUriSignOut = RedirectUriSignOut; | ||
*/ | ||
CognitoAuth.prototype.getCognitoConstants = function getCognitoConstants() { | ||
var CognitoConstants = { | ||
getCognitoConstants() { | ||
const CognitoConstants = { | ||
DOMAIN_SCHEME: 'https', | ||
@@ -150,3 +133,3 @@ DOMAIN_PATH_SIGNIN: 'oauth2/authorize', | ||
return CognitoConstants; | ||
}; | ||
} | ||
@@ -156,7 +139,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getClientId = function getClientId() { | ||
getClientId() { | ||
return this.clientId; | ||
}; | ||
} | ||
@@ -166,7 +147,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getAppWebDomain = function getAppWebDomain() { | ||
getAppWebDomain() { | ||
return this.appWebDomain; | ||
}; | ||
} | ||
@@ -178,10 +157,8 @@ /** | ||
*/ | ||
getCurrentUser() { | ||
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`; | ||
CognitoAuth.prototype.getCurrentUser = function getCurrentUser() { | ||
var lastUserKey = 'CognitoIdentityServiceProvider.' + this.clientId + '.LastAuthUser'; | ||
var lastAuthUser = this.storage.getItem(lastUserKey); | ||
const lastAuthUser = this.storage.getItem(lastUserKey); | ||
return lastAuthUser; | ||
}; | ||
} | ||
@@ -193,7 +170,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setUser = function setUser(Username) { | ||
setUser(Username) { | ||
this.username = Username; | ||
}; | ||
} | ||
@@ -204,7 +179,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.useCodeGrantFlow = function useCodeGrantFlow() { | ||
useCodeGrantFlow() { | ||
this.responseType = this.getCognitoConstants().CODE; | ||
}; | ||
} | ||
@@ -215,7 +188,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.useImplicitFlow = function useImplicitFlow() { | ||
useImplicitFlow() { | ||
this.responseType = this.getCognitoConstants().TOKEN; | ||
}; | ||
} | ||
@@ -225,7 +196,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSignInUserSession = function getSignInUserSession() { | ||
getSignInUserSession() { | ||
return this.signInUserSession; | ||
}; | ||
} | ||
@@ -235,7 +204,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getUsername = function getUsername() { | ||
getUsername() { | ||
return this.username; | ||
}; | ||
} | ||
@@ -246,7 +213,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setUsername = function setUsername(Username) { | ||
setUsername(Username) { | ||
this.username = Username; | ||
}; | ||
} | ||
@@ -256,7 +221,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getState = function getState() { | ||
getState() { | ||
return this.state; | ||
}; | ||
} | ||
@@ -267,7 +230,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setState = function setState(State) { | ||
setState(State) { | ||
this.state = State; | ||
}; | ||
} | ||
@@ -283,8 +244,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSession = function getSession() { | ||
var tokenScopesInputSet = new Set(this.TokenScopesArray); | ||
var cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes()); | ||
var URL = this.getFQDNSignIn(); | ||
getSession() { | ||
const tokenScopesInputSet = new Set(this.TokenScopesArray); | ||
const cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes()); | ||
const URL = this.getFQDNSignIn(); | ||
if (this.signInUserSession != null && this.signInUserSession.isValid()) { | ||
@@ -296,6 +255,6 @@ return this.userhandler.onSuccess(this.signInUserSession); | ||
if (!this.compareSets(tokenScopesInputSet, cachedScopesSet)) { | ||
var tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
var idToken = new CognitoIdToken(); | ||
var accessToken = new CognitoAccessToken(); | ||
var refreshToken = new CognitoRefreshToken(); | ||
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
const idToken = new CognitoIdToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const refreshToken = new CognitoRefreshToken(); | ||
this.signInUserSession.setTokenScopes(tokenScopes); | ||
@@ -314,3 +273,3 @@ this.signInUserSession.setIdToken(idToken); | ||
return undefined; | ||
}; | ||
} | ||
@@ -322,6 +281,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) { | ||
var map = void 0; | ||
parseCognitoWebResponse(httpRequestResponse) { | ||
let map; | ||
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) { | ||
@@ -331,3 +288,3 @@ // for code type | ||
// Sometimes the code will contain a poundsign in the end which breaks the parsing | ||
var response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0]; | ||
const response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0]; | ||
map = this.getQueryParameters(response, this.getCognitoConstants().QUESTIONMARK); | ||
@@ -344,3 +301,3 @@ this.getCodeQueryParameter(map); | ||
} | ||
}; | ||
} | ||
@@ -352,6 +309,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) { | ||
var state = null; | ||
getCodeQueryParameter(map) { | ||
const state = null; | ||
if (map.has(this.getCognitoConstants().STATE)) { | ||
@@ -366,14 +321,14 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE)); | ||
// To parse the response and get the code value. | ||
var codeParameter = map.get(this.getCognitoConstants().CODE); | ||
var url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
var header = this.getCognitoConstants().HEADER; | ||
var body = { grant_type: this.getCognitoConstants().AUTHORIZATIONCODE, | ||
const codeParameter = map.get(this.getCognitoConstants().CODE); | ||
const url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
const header = this.getCognitoConstants().HEADER; | ||
const body = { grant_type: this.getCognitoConstants().AUTHORIZATIONCODE, | ||
client_id: this.getClientId(), | ||
redirect_uri: this.RedirectUriSignIn, | ||
code: codeParameter }; | ||
var boundOnSuccess = this.onSuccessExchangeForToken.bind(this); | ||
var boundOnFailure = this.onFailure.bind(this); | ||
const boundOnSuccess = this.onSuccessExchangeForToken.bind(this); | ||
const boundOnFailure = this.onFailure.bind(this); | ||
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure); | ||
} | ||
}; | ||
} | ||
@@ -385,9 +340,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) { | ||
var idToken = new CognitoIdToken(); | ||
var accessToken = new CognitoAccessToken(); | ||
var refreshToken = new CognitoRefreshToken(); | ||
var state = null; | ||
getTokenQueryParameter(map) { | ||
const idToken = new CognitoIdToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const refreshToken = new CognitoRefreshToken(); | ||
const state = null; | ||
if (map.has(this.getCognitoConstants().IDTOKEN)) { | ||
@@ -412,3 +365,3 @@ idToken.setJwtToken(map.get(this.getCognitoConstants().IDTOKEN)); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
} | ||
@@ -419,25 +372,23 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getCachedSession = function getCachedSession() { | ||
getCachedSession() { | ||
if (!this.username) { | ||
return new CognitoAuthSession(); | ||
} | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId() + '.' + this.username; | ||
var idTokenKey = keyPrefix + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.refreshToken'; | ||
var scopeKey = keyPrefix + '.tokenScopesString'; | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}.${this.username}`; | ||
const idTokenKey = `${keyPrefix}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.refreshToken`; | ||
const scopeKey = `${keyPrefix}.tokenScopesString`; | ||
var scopesString = this.storage.getItem(scopeKey); | ||
var scopesArray = []; | ||
const scopesString = this.storage.getItem(scopeKey); | ||
let scopesArray = []; | ||
if (scopesString) { | ||
scopesArray = scopesString.split(' '); | ||
} | ||
var tokenScopes = new CognitoTokenScopes(scopesArray); | ||
var idToken = new CognitoIdToken(this.storage.getItem(idTokenKey)); | ||
var accessToken = new CognitoAccessToken(this.storage.getItem(accessTokenKey)); | ||
var refreshToken = new CognitoRefreshToken(this.storage.getItem(refreshTokenKey)); | ||
const tokenScopes = new CognitoTokenScopes(scopesArray); | ||
const idToken = new CognitoIdToken(this.storage.getItem(idTokenKey)); | ||
const accessToken = new CognitoAccessToken(this.storage.getItem(accessTokenKey)); | ||
const refreshToken = new CognitoRefreshToken(this.storage.getItem(refreshTokenKey)); | ||
var sessionData = { | ||
const sessionData = { | ||
IdToken: idToken, | ||
@@ -448,5 +399,5 @@ AccessToken: accessToken, | ||
}; | ||
var cachedSession = new CognitoAuthSession(sessionData); | ||
const cachedSession = new CognitoAuthSession(sessionData); | ||
return cachedSession; | ||
}; | ||
} | ||
@@ -457,8 +408,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getLastUser = function getLastUser() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var lastUserName = this.storage.getItem(lastUserKey); | ||
getLastUser() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const lastUserName = this.storage.getItem(lastUserKey); | ||
if (lastUserName) { | ||
@@ -468,3 +417,3 @@ return lastUserName; | ||
return undefined; | ||
}; | ||
} | ||
@@ -476,15 +425,13 @@ /** | ||
*/ | ||
CognitoAuth.prototype.cacheTokensScopes = function cacheTokensScopes() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var tokenUserName = this.signInUserSession.getAccessToken().getUsername(); | ||
cacheTokensScopes() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const tokenUserName = this.signInUserSession.getAccessToken().getUsername(); | ||
this.username = tokenUserName; | ||
var idTokenKey = keyPrefix + '.' + tokenUserName + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.' + tokenUserName + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.' + tokenUserName + '.refreshToken'; | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var scopeKey = keyPrefix + '.' + tokenUserName + '.tokenScopesString'; | ||
var scopesArray = this.signInUserSession.getTokenScopes().getScopes(); | ||
var scopesString = scopesArray.join(' '); | ||
const idTokenKey = `${keyPrefix}.${tokenUserName}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.${tokenUserName}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.${tokenUserName}.refreshToken`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const scopeKey = `${keyPrefix}.${tokenUserName}.tokenScopesString`; | ||
const scopesArray = this.signInUserSession.getTokenScopes().getScopes(); | ||
const scopesString = scopesArray.join(' '); | ||
this.storage.setItem(idTokenKey, this.signInUserSession.getIdToken().getJwtToken()); | ||
@@ -495,3 +442,3 @@ this.storage.setItem(accessTokenKey, this.signInUserSession.getAccessToken().getJwtToken()); | ||
this.storage.setItem(scopeKey, scopesString); | ||
}; | ||
} | ||
@@ -504,22 +451,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.compareSets = function compareSets(set1, set2) { | ||
compareSets(set1, set2) { | ||
if (set1.size !== set2.size) { | ||
return false; | ||
} | ||
for (var _iterator = set1, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
var item = _ref2; | ||
for (const item of set1) { | ||
if (!set2.has(item)) { | ||
@@ -530,3 +462,3 @@ return false; | ||
return true; | ||
}; | ||
} | ||
@@ -538,11 +470,9 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getHostName = function getHostName(url) { | ||
var match = url.match(this.getCognitoConstants().HOSTNAMEREGEX); | ||
if (match != null && match.length > 2 && _typeof(match[2]) === this.getCognitoConstants().STRINGTYPE && match[2].length > 0) { | ||
getHostName(url) { | ||
const match = url.match(this.getCognitoConstants().HOSTNAMEREGEX); | ||
if (match != null && match.length > 2 && typeof match[2] === this.getCognitoConstants().STRINGTYPE && match[2].length > 0) { | ||
return match[2]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
@@ -555,11 +485,9 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getQueryParameters = function getQueryParameters(url, splitMark) { | ||
var str = String(url).split(splitMark); | ||
var url2 = str[1]; | ||
var str1 = String(url2).split(this.getCognitoConstants().AMPERSAND); | ||
var num = str1.length; | ||
var map = new Map(); | ||
var i = void 0; | ||
getQueryParameters(url, splitMark) { | ||
const str = String(url).split(splitMark); | ||
const url2 = str[1]; | ||
const str1 = String(url2).split(this.getCognitoConstants().AMPERSAND); | ||
const num = str1.length; | ||
const map = new Map(); | ||
let i; | ||
for (i = 0; i < num; i++) { | ||
@@ -570,3 +498,3 @@ str1[i] = String(str1[i]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2); | ||
return map; | ||
}; | ||
} | ||
@@ -579,12 +507,9 @@ /** | ||
*/ | ||
generateRandomString(length, chars) { | ||
let result = ''; | ||
let i = length; | ||
for (; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; | ||
return result; | ||
} | ||
CognitoAuth.prototype.generateRandomString = function generateRandomString(length, chars) { | ||
var result = ''; | ||
var i = length; | ||
for (; i > 0; --i) { | ||
result += chars[Math.round(Math.random() * (chars.length - 1))]; | ||
}return result; | ||
}; | ||
/** | ||
@@ -594,12 +519,10 @@ * This is used to clear the session tokens and scopes from local storage | ||
*/ | ||
clearCachedTokensScopes() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const idTokenKey = `${keyPrefix}.${this.username}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.${this.username}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.${this.username}.refreshToken`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const scopeKey = `${keyPrefix}.${this.username}.tokenScopesString`; | ||
CognitoAuth.prototype.clearCachedTokensScopes = function clearCachedTokensScopes() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var idTokenKey = keyPrefix + '.' + this.username + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.' + this.username + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.' + this.username + '.refreshToken'; | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var scopeKey = keyPrefix + '.' + this.username + '.tokenScopesString'; | ||
this.storage.removeItem(idTokenKey); | ||
@@ -610,3 +533,3 @@ this.storage.removeItem(accessTokenKey); | ||
this.storage.removeItem(scopeKey); | ||
}; | ||
} | ||
@@ -618,16 +541,14 @@ /** | ||
*/ | ||
CognitoAuth.prototype.refreshSession = function refreshSession(refreshToken) { | ||
refreshSession(refreshToken) { | ||
// https POST call for refreshing token | ||
var url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
var header = this.getCognitoConstants().HEADER; | ||
var body = { grant_type: this.getCognitoConstants().REFRESHTOKEN, | ||
const url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
const header = this.getCognitoConstants().HEADER; | ||
const body = { grant_type: this.getCognitoConstants().REFRESHTOKEN, | ||
client_id: this.getClientId(), | ||
redirect_uri: this.RedirectUriSignIn, | ||
refresh_token: refreshToken }; | ||
var boundOnSuccess = this.onSuccessRefreshToken.bind(this); | ||
var boundOnFailure = this.onFailure.bind(this); | ||
const boundOnSuccess = this.onSuccessRefreshToken.bind(this); | ||
const boundOnFailure = this.onFailure.bind(this); | ||
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure); | ||
}; | ||
} | ||
@@ -643,8 +564,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.makePOSTRequest = function makePOSTRequest(header, body, url, onSuccess, onFailure) { | ||
makePOSTRequest(header, body, url, onSuccess, onFailure) { | ||
// This is a sample server that supports CORS. | ||
var xhr = this.createCORSRequest(this.getCognitoConstants().POST, url); | ||
var bodyString = ''; | ||
const xhr = this.createCORSRequest(this.getCognitoConstants().POST, url); | ||
let bodyString = ''; | ||
if (!xhr) { | ||
@@ -654,7 +573,7 @@ return; | ||
// set header | ||
for (var key in header) { | ||
for (let key in header) { | ||
xhr.setRequestHeader(key, header[key]); | ||
} | ||
for (var _key in body) { | ||
bodyString = bodyString.concat(_key, this.getCognitoConstants().EQUALSIGN, body[_key], this.getCognitoConstants().AMPERSAND); | ||
for (let key in body) { | ||
bodyString = bodyString.concat(key, this.getCognitoConstants().EQUALSIGN, body[key], this.getCognitoConstants().AMPERSAND); | ||
} | ||
@@ -672,3 +591,3 @@ bodyString = bodyString.substring(0, bodyString.length - 1); | ||
}; | ||
}; | ||
} | ||
@@ -681,6 +600,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.createCORSRequest = function createCORSRequest(method, url) { | ||
var xhr = new XMLHttpRequest(); | ||
createCORSRequest(method, url) { | ||
let xhr = new XMLHttpRequest(); | ||
xhr.open(method, url, true); | ||
@@ -690,3 +607,3 @@ if (this.getCognitoConstants().WITHCREDENTIALS in xhr) { | ||
xhr.open(method, url, true); | ||
} else if ((typeof XDomainRequest === 'undefined' ? 'undefined' : _typeof(XDomainRequest)) !== this.getCognitoConstants().UNDEFINED) { | ||
} else if (typeof XDomainRequest !== this.getCognitoConstants().UNDEFINED) { | ||
// XDomainRequest for IE. | ||
@@ -700,3 +617,3 @@ xhr = new XDomainRequest(); | ||
return xhr; | ||
}; | ||
} | ||
@@ -708,7 +625,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onFailure = function onFailure(err) { | ||
onFailure(err) { | ||
this.userhandler.onFailure(err); | ||
}; | ||
} | ||
@@ -719,8 +634,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onSuccessRefreshToken = function onSuccessRefreshToken(jsonData) { | ||
var jsonDataObject = JSON.parse(jsonData); | ||
onSuccessRefreshToken(jsonData) { | ||
const jsonDataObject = JSON.parse(jsonData); | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) { | ||
var URL = this.getFQDNSignIn(); | ||
const URL = this.getFQDNSignIn(); | ||
this.launchUri(URL); | ||
@@ -737,3 +650,3 @@ } else { | ||
} | ||
}; | ||
} | ||
@@ -744,10 +657,8 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onSuccessExchangeForToken = function onSuccessExchangeForToken(jsonData) { | ||
var jsonDataObject = JSON.parse(jsonData); | ||
var refreshToken = new CognitoRefreshToken(); | ||
var accessToken = new CognitoAccessToken(); | ||
var idToken = new CognitoIdToken(); | ||
var state = null; | ||
onSuccessExchangeForToken(jsonData) { | ||
const jsonDataObject = JSON.parse(jsonData); | ||
const refreshToken = new CognitoRefreshToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const idToken = new CognitoIdToken(); | ||
const state = null; | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) { | ||
@@ -773,3 +684,3 @@ return this.userhandler.onFailure(jsonData); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
} | ||
@@ -781,7 +692,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.launchUri = function launchUri(URL) { | ||
launchUri(URL) { | ||
window.open(URL, this.getCognitoConstants().SELF); | ||
}; | ||
} | ||
@@ -791,9 +700,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSpaceSeperatedScopeString = function getSpaceSeperatedScopeString() { | ||
var tokenScopesString = this.signInUserSession.getTokenScopes().getScopes(); | ||
getSpaceSeperatedScopeString() { | ||
let tokenScopesString = this.signInUserSession.getTokenScopes().getScopes(); | ||
tokenScopesString = tokenScopesString.join(this.getCognitoConstants().SPACE); | ||
return encodeURIComponent(tokenScopesString); | ||
}; | ||
} | ||
@@ -804,5 +711,3 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getFQDNSignIn = function getFQDNSignIn() { | ||
getFQDNSignIn() { | ||
if (this.state == null) { | ||
@@ -812,4 +717,4 @@ this.state = this.generateRandomString(this.getCognitoConstants().STATELENGTH, this.getCognitoConstants().STATEORIGINSTRING); | ||
var identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : ''; | ||
var tokenScopesString = this.getSpaceSeperatedScopeString(); | ||
const identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : ''; | ||
const tokenScopesString = this.getSpaceSeperatedScopeString(); | ||
@@ -823,6 +728,6 @@ var userContextDataParam = ''; | ||
// Build the complete web domain to launch the login screen | ||
var uri = 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, tokenScopesString, identityProviderParam, userContextDataParam); | ||
const uri = 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, tokenScopesString, identityProviderParam, userContextDataParam); | ||
return uri; | ||
}; | ||
} | ||
@@ -833,10 +738,8 @@ /** | ||
*/ | ||
CognitoAuth.prototype.signOut = function signOut() { | ||
var URL = this.getFQDNSignOut(); | ||
signOut() { | ||
const URL = this.getFQDNSignOut(); | ||
this.signInUserSession = null; | ||
this.clearCachedTokensScopes(); | ||
this.launchUri(URL); | ||
}; | ||
} | ||
@@ -847,8 +750,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getFQDNSignOut = function getFQDNSignOut() { | ||
var uri = 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()); | ||
getFQDNSignOut() { | ||
const uri = 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 uri; | ||
}; | ||
} | ||
@@ -861,5 +762,3 @@ /** | ||
**/ | ||
CognitoAuth.prototype.getUserContextData = function getUserContextData() { | ||
getUserContextData() { | ||
if (typeof AmazonCognitoAdvancedSecurityData === "undefined") { | ||
@@ -882,3 +781,3 @@ return; | ||
} | ||
}; | ||
} | ||
@@ -890,11 +789,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.isUserSignedIn = function isUserSignedIn() { | ||
isUserSignedIn() { | ||
return this.signInUserSession != null && this.signInUserSession.isValid() || this.getCachedSession() != null && this.getCachedSession().isValid(); | ||
}; | ||
return CognitoAuth; | ||
}(); | ||
export default CognitoAuth; | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -26,4 +24,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoAuthSession = function () { | ||
export default class CognitoAuthSession { | ||
/** | ||
@@ -37,12 +34,3 @@ * Constructs a new CognitoUserSession object | ||
*/ | ||
function CognitoAuthSession() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
IdToken = _ref.IdToken, | ||
RefreshToken = _ref.RefreshToken, | ||
AccessToken = _ref.AccessToken, | ||
TokenScopes = _ref.TokenScopes, | ||
State = _ref.State; | ||
_classCallCheck(this, CognitoAuthSession); | ||
constructor({ IdToken, RefreshToken, AccessToken, TokenScopes, State } = {}) { | ||
if (IdToken) { | ||
@@ -78,7 +66,5 @@ this.idToken = IdToken; | ||
*/ | ||
CognitoAuthSession.prototype.getIdToken = function getIdToken() { | ||
getIdToken() { | ||
return this.idToken; | ||
}; | ||
} | ||
@@ -90,7 +76,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setIdToken = function setIdToken(IdToken) { | ||
setIdToken(IdToken) { | ||
this.idToken = IdToken; | ||
}; | ||
} | ||
@@ -100,7 +84,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getRefreshToken = function getRefreshToken() { | ||
getRefreshToken() { | ||
return this.refreshToken; | ||
}; | ||
} | ||
@@ -112,7 +94,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setRefreshToken = function setRefreshToken(RefreshToken) { | ||
setRefreshToken(RefreshToken) { | ||
this.refreshToken = RefreshToken; | ||
}; | ||
} | ||
@@ -122,7 +102,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getAccessToken = function getAccessToken() { | ||
getAccessToken() { | ||
return this.accessToken; | ||
}; | ||
} | ||
@@ -134,7 +112,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setAccessToken = function setAccessToken(AccessToken) { | ||
setAccessToken(AccessToken) { | ||
this.accessToken = AccessToken; | ||
}; | ||
} | ||
@@ -144,7 +120,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getTokenScopes = function getTokenScopes() { | ||
getTokenScopes() { | ||
return this.tokenScopes; | ||
}; | ||
} | ||
@@ -156,7 +130,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setTokenScopes = function setTokenScopes(tokenScopes) { | ||
setTokenScopes(tokenScopes) { | ||
this.tokenScopes = tokenScopes; | ||
}; | ||
} | ||
@@ -166,7 +138,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getState = function getState() { | ||
getState() { | ||
return this.state; | ||
}; | ||
} | ||
@@ -178,7 +148,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setState = function setState(State) { | ||
setState(State) { | ||
this.state = State; | ||
}; | ||
} | ||
@@ -190,6 +158,4 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.isValid = function isValid() { | ||
var now = Math.floor(new Date() / 1000); | ||
isValid() { | ||
const now = Math.floor(new Date() / 1000); | ||
try { | ||
@@ -206,7 +172,3 @@ if (this.accessToken != null) { | ||
} | ||
}; | ||
return CognitoAuthSession; | ||
}(); | ||
export default CognitoAuthSession; | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -19,4 +17,6 @@ * Amazon Cognito Auth SDK for JavaScript | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
var CognitoIdToken = function () { | ||
export default class CognitoIdToken { | ||
/** | ||
@@ -26,5 +26,3 @@ * Constructs a new CognitoIdToken object | ||
*/ | ||
function CognitoIdToken(IdToken) { | ||
_classCallCheck(this, CognitoIdToken); | ||
constructor(IdToken) { | ||
// Assign object | ||
@@ -38,7 +36,5 @@ this.jwtToken = IdToken || ''; | ||
*/ | ||
CognitoIdToken.prototype.getJwtToken = function getJwtToken() { | ||
getJwtToken() { | ||
return this.jwtToken; | ||
}; | ||
} | ||
@@ -50,7 +46,5 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.setJwtToken = function setJwtToken(idToken) { | ||
setJwtToken(idToken) { | ||
this.jwtToken = idToken; | ||
}; | ||
} | ||
@@ -60,11 +54,9 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.getExpiration = function getExpiration() { | ||
getExpiration() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -74,16 +66,10 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.decodePayload = function decodePayload() { | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
decodePayload() { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
return {}; | ||
} | ||
}; | ||
return CognitoIdToken; | ||
}(); | ||
export default CognitoIdToken; | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -21,3 +19,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoRefreshToken = function () { | ||
export default class CognitoRefreshToken { | ||
/** | ||
@@ -27,5 +25,3 @@ * Constructs a new CognitoRefreshToken object | ||
*/ | ||
function CognitoRefreshToken(RefreshToken) { | ||
_classCallCheck(this, CognitoRefreshToken); | ||
constructor(RefreshToken) { | ||
// Assign object | ||
@@ -38,7 +34,5 @@ this.refreshToken = RefreshToken || ''; | ||
*/ | ||
CognitoRefreshToken.prototype.getToken = function getToken() { | ||
getToken() { | ||
return this.refreshToken; | ||
}; | ||
} | ||
@@ -50,11 +44,5 @@ /** | ||
*/ | ||
CognitoRefreshToken.prototype.setToken = function setToken(refreshToken) { | ||
setToken(refreshToken) { | ||
this.refreshToken = refreshToken; | ||
}; | ||
return CognitoRefreshToken; | ||
}(); | ||
export default CognitoRefreshToken; | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -21,3 +19,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoTokenScopes = function () { | ||
export default class CognitoTokenScopes { | ||
/** | ||
@@ -27,5 +25,3 @@ * Constructs a new CognitoTokenScopes object | ||
*/ | ||
function CognitoTokenScopes(TokenScopesArray) { | ||
_classCallCheck(this, CognitoTokenScopes); | ||
constructor(TokenScopesArray) { | ||
// Assign object | ||
@@ -38,7 +34,5 @@ this.tokenScopes = TokenScopesArray || []; | ||
*/ | ||
CognitoTokenScopes.prototype.getScopes = function getScopes() { | ||
getScopes() { | ||
return this.tokenScopes; | ||
}; | ||
} | ||
@@ -50,11 +44,5 @@ /** | ||
*/ | ||
CognitoTokenScopes.prototype.setTokenScopes = function setTokenScopes(tokenScopes) { | ||
setTokenScopes(tokenScopes) { | ||
this.tokenScopes = tokenScopes; | ||
}; | ||
return CognitoTokenScopes; | ||
}(); | ||
export default CognitoTokenScopes; | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -6,5 +5,4 @@ import * as Cookies from 'js-cookie'; | ||
/** @class */ | ||
export default class CookieStorage { | ||
var CookieStorage = function () { | ||
/** | ||
@@ -18,5 +16,3 @@ * Constructs a new CookieStorage object | ||
*/ | ||
function CookieStorage(data) { | ||
_classCallCheck(this, CookieStorage); | ||
constructor(data) { | ||
this.domain = data.domain; | ||
@@ -46,5 +42,3 @@ if (data.path) { | ||
*/ | ||
CookieStorage.prototype.setItem = function setItem(key, value) { | ||
setItem(key, value) { | ||
Cookies.set(key, value, { | ||
@@ -57,3 +51,3 @@ path: this.path, | ||
return Cookies.get(key); | ||
}; | ||
} | ||
@@ -66,7 +60,5 @@ /** | ||
*/ | ||
CookieStorage.prototype.getItem = function getItem(key) { | ||
getItem(key) { | ||
return Cookies.get(key); | ||
}; | ||
} | ||
@@ -78,5 +70,3 @@ /** | ||
*/ | ||
CookieStorage.prototype.removeItem = function removeItem(key) { | ||
removeItem(key) { | ||
return Cookies.remove(key, { | ||
@@ -87,3 +77,3 @@ path: this.path, | ||
}); | ||
}; | ||
} | ||
@@ -94,7 +84,5 @@ /** | ||
*/ | ||
CookieStorage.prototype.clear = function clear() { | ||
var cookies = Cookies.get(); | ||
var index = void 0; | ||
clear() { | ||
const cookies = Cookies.get(); | ||
let index; | ||
for (index = 0; index < cookies.length; ++index) { | ||
@@ -104,7 +92,3 @@ Cookies.remove(cookies[index]); | ||
return {}; | ||
}; | ||
return CookieStorage; | ||
}(); | ||
export default CookieStorage; | ||
} | ||
} |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -19,48 +17,39 @@ * Amazon Cognito Auth SDK for JavaScript | ||
*/ | ||
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | ||
var weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | ||
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | ||
const weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | ||
/** @class */ | ||
var DateHelper = function () { | ||
function DateHelper() { | ||
_classCallCheck(this, DateHelper); | ||
} | ||
export default class DateHelper { | ||
/** | ||
* @returns {string} The current time in "ddd MMM D HH:mm:ss UTC YYYY" format. | ||
*/ | ||
DateHelper.prototype.getNowString = function getNowString() { | ||
var now = new Date(); | ||
getNowString() { | ||
const now = new Date(); | ||
var weekDay = weekNames[now.getUTCDay()]; | ||
var month = monthNames[now.getUTCMonth()]; | ||
var day = now.getUTCDate(); | ||
const weekDay = weekNames[now.getUTCDay()]; | ||
const month = monthNames[now.getUTCMonth()]; | ||
const day = now.getUTCDate(); | ||
var hours = now.getUTCHours(); | ||
let hours = now.getUTCHours(); | ||
if (hours < 10) { | ||
hours = '0' + hours; | ||
hours = `0${hours}`; | ||
} | ||
var minutes = now.getUTCMinutes(); | ||
let minutes = now.getUTCMinutes(); | ||
if (minutes < 10) { | ||
minutes = '0' + minutes; | ||
minutes = `0${minutes}`; | ||
} | ||
var seconds = now.getUTCSeconds(); | ||
let seconds = now.getUTCSeconds(); | ||
if (seconds < 10) { | ||
seconds = '0' + seconds; | ||
seconds = `0${seconds}`; | ||
} | ||
var year = now.getUTCFullYear(); | ||
const year = now.getUTCFullYear(); | ||
// ddd MMM D HH:mm:ss UTC YYYY | ||
var dateNow = weekDay + ' ' + month + ' ' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' UTC ' + year; | ||
const dateNow = `${weekDay} ${month} ${day} ${hours}:${minutes}:${seconds} UTC ${year}`; | ||
return dateNow; | ||
}; | ||
return DateHelper; | ||
}(); | ||
export default DateHelper; | ||
} | ||
} |
@@ -25,2 +25,3 @@ /*! | ||
export { default as DateHelper } from './DateHelper'; | ||
export { default as StorageHelper } from './StorageHelper'; | ||
export { default as StorageHelper } from './StorageHelper'; | ||
export { default as CookieStorage } from './CookieStorage'; |
@@ -1,3 +0,1 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -19,11 +17,7 @@ * Amazon Cognito Auth SDK for JavaScript | ||
*/ | ||
var dataMemory = {}; | ||
let dataMemory = {}; | ||
/** @class */ | ||
class MemoryStorage { | ||
var MemoryStorage = function () { | ||
function MemoryStorage() { | ||
_classCallCheck(this, MemoryStorage); | ||
} | ||
/** | ||
@@ -35,6 +29,6 @@ * This is used to set a specific item in storage | ||
*/ | ||
MemoryStorage.setItem = function setItem(key, value) { | ||
static setItem(key, value) { | ||
dataMemory[key] = value; | ||
return dataMemory[key]; | ||
}; | ||
} | ||
@@ -47,7 +41,5 @@ /** | ||
*/ | ||
MemoryStorage.getItem = function getItem(key) { | ||
static getItem(key) { | ||
return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined; | ||
}; | ||
} | ||
@@ -59,7 +51,5 @@ /** | ||
*/ | ||
MemoryStorage.removeItem = function removeItem(key) { | ||
static removeItem(key) { | ||
return delete dataMemory[key]; | ||
}; | ||
} | ||
@@ -70,17 +60,11 @@ /** | ||
*/ | ||
MemoryStorage.clear = function clear() { | ||
static clear() { | ||
dataMemory = {}; | ||
return dataMemory; | ||
}; | ||
} | ||
} | ||
return MemoryStorage; | ||
}(); | ||
/** @class */ | ||
export default class StorageHelper { | ||
var StorageHelper = function () { | ||
/** | ||
@@ -90,5 +74,3 @@ * This is used to get a storage object | ||
*/ | ||
function StorageHelper() { | ||
_classCallCheck(this, StorageHelper); | ||
constructor() { | ||
try { | ||
@@ -107,11 +89,5 @@ this.storageWindow = window.localStorage; | ||
*/ | ||
StorageHelper.prototype.getStorage = function getStorage() { | ||
getStorage() { | ||
return this.storageWindow; | ||
}; | ||
return StorageHelper; | ||
}(); | ||
export default StorageHelper; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -24,4 +18,6 @@ * Amazon Cognito Auth SDK for JavaScript | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
var CognitoAccessToken = function () { | ||
export default class CognitoAccessToken { | ||
/** | ||
@@ -31,5 +27,3 @@ * Constructs a new CognitoAccessToken object | ||
*/ | ||
function CognitoAccessToken(AccessToken) { | ||
_classCallCheck(this, CognitoAccessToken); | ||
constructor(AccessToken) { | ||
// Assign object | ||
@@ -43,7 +37,5 @@ this.jwtToken = AccessToken || ''; | ||
*/ | ||
CognitoAccessToken.prototype.getJwtToken = function getJwtToken() { | ||
getJwtToken() { | ||
return this.jwtToken; | ||
}; | ||
} | ||
@@ -55,7 +47,5 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.setJwtToken = function setJwtToken(accessToken) { | ||
setJwtToken(accessToken) { | ||
this.jwtToken = accessToken; | ||
}; | ||
} | ||
@@ -65,11 +55,9 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.getExpiration = function getExpiration() { | ||
getExpiration() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -79,11 +67,9 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.getUsername = function getUsername() { | ||
getUsername() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).username; | ||
} | ||
@@ -93,16 +79,10 @@ /** | ||
*/ | ||
CognitoAccessToken.prototype.decodePayload = function decodePayload() { | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
decodePayload() { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
return {}; | ||
} | ||
}; | ||
return CognitoAccessToken; | ||
}(); | ||
exports.default = CognitoAccessToken; | ||
} | ||
} |
@@ -1,52 +0,27 @@ | ||
'use strict'; | ||
/*! | ||
* 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. | ||
*/ | ||
exports.__esModule = true; | ||
import CognitoTokenScopes from './CognitoTokenScopes'; | ||
import CognitoAccessToken from './CognitoAccessToken'; | ||
import CognitoIdToken from './CognitoIdToken'; | ||
import CognitoRefreshToken from './CognitoRefreshToken'; | ||
import CognitoAuthSession from './CognitoAuthSession'; | ||
import StorageHelper from './StorageHelper'; | ||
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; }; | ||
var _CognitoTokenScopes = require('./CognitoTokenScopes'); | ||
var _CognitoTokenScopes2 = _interopRequireDefault(_CognitoTokenScopes); | ||
var _CognitoAccessToken = require('./CognitoAccessToken'); | ||
var _CognitoAccessToken2 = _interopRequireDefault(_CognitoAccessToken); | ||
var _CognitoIdToken = require('./CognitoIdToken'); | ||
var _CognitoIdToken2 = _interopRequireDefault(_CognitoIdToken); | ||
var _CognitoRefreshToken = require('./CognitoRefreshToken'); | ||
var _CognitoRefreshToken2 = _interopRequireDefault(_CognitoRefreshToken); | ||
var _CognitoAuthSession = require('./CognitoAuthSession'); | ||
var _CognitoAuthSession2 = _interopRequireDefault(_CognitoAuthSession); | ||
var _StorageHelper = require('./StorageHelper'); | ||
var _StorageHelper2 = _interopRequireDefault(_StorageHelper); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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. | ||
*/ | ||
/** @class */ | ||
var CognitoAuth = function () { | ||
export default class CognitoAuth { | ||
/** | ||
@@ -71,16 +46,6 @@ * Constructs a new CognitoAuth object | ||
*/ | ||
function CognitoAuth(data) { | ||
_classCallCheck(this, CognitoAuth); | ||
var _ref = data || {}, | ||
ClientId = _ref.ClientId, | ||
AppWebDomain = _ref.AppWebDomain, | ||
TokenScopesArray = _ref.TokenScopesArray, | ||
RedirectUriSignIn = _ref.RedirectUriSignIn, | ||
RedirectUriSignOut = _ref.RedirectUriSignOut, | ||
IdentityProvider = _ref.IdentityProvider, | ||
UserPoolId = _ref.UserPoolId, | ||
AdvancedSecurityDataCollectionFlag = _ref.AdvancedSecurityDataCollectionFlag, | ||
Storage = _ref.Storage; | ||
constructor(data) { | ||
const { ClientId, AppWebDomain, TokenScopesArray, | ||
RedirectUriSignIn, RedirectUriSignOut, IdentityProvider, UserPoolId, | ||
AdvancedSecurityDataCollectionFlag, Storage } = data || {}; | ||
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) { | ||
@@ -96,3 +61,3 @@ throw new Error(this.getCognitoConstants().PARAMETERERROR); | ||
} | ||
var tokenScopes = new _CognitoTokenScopes2.default(this.TokenScopesArray); | ||
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
this.RedirectUriSignIn = RedirectUriSignIn; | ||
@@ -102,3 +67,3 @@ this.RedirectUriSignOut = RedirectUriSignOut; | ||
this.responseType = this.getCognitoConstants().TOKEN; | ||
this.storage = Storage || new _StorageHelper2.default().getStorage(); | ||
this.storage = Storage || new StorageHelper().getStorage(); | ||
this.username = this.getLastUser(); | ||
@@ -121,6 +86,4 @@ this.userPoolId = UserPoolId; | ||
*/ | ||
CognitoAuth.prototype.getCognitoConstants = function getCognitoConstants() { | ||
var CognitoConstants = { | ||
getCognitoConstants() { | ||
const CognitoConstants = { | ||
DOMAIN_SCHEME: 'https', | ||
@@ -170,3 +133,3 @@ DOMAIN_PATH_SIGNIN: 'oauth2/authorize', | ||
return CognitoConstants; | ||
}; | ||
} | ||
@@ -176,7 +139,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getClientId = function getClientId() { | ||
getClientId() { | ||
return this.clientId; | ||
}; | ||
} | ||
@@ -186,7 +147,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getAppWebDomain = function getAppWebDomain() { | ||
getAppWebDomain() { | ||
return this.appWebDomain; | ||
}; | ||
} | ||
@@ -198,10 +157,8 @@ /** | ||
*/ | ||
getCurrentUser() { | ||
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`; | ||
CognitoAuth.prototype.getCurrentUser = function getCurrentUser() { | ||
var lastUserKey = 'CognitoIdentityServiceProvider.' + this.clientId + '.LastAuthUser'; | ||
var lastAuthUser = this.storage.getItem(lastUserKey); | ||
const lastAuthUser = this.storage.getItem(lastUserKey); | ||
return lastAuthUser; | ||
}; | ||
} | ||
@@ -213,7 +170,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setUser = function setUser(Username) { | ||
setUser(Username) { | ||
this.username = Username; | ||
}; | ||
} | ||
@@ -224,7 +179,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.useCodeGrantFlow = function useCodeGrantFlow() { | ||
useCodeGrantFlow() { | ||
this.responseType = this.getCognitoConstants().CODE; | ||
}; | ||
} | ||
@@ -235,7 +188,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.useImplicitFlow = function useImplicitFlow() { | ||
useImplicitFlow() { | ||
this.responseType = this.getCognitoConstants().TOKEN; | ||
}; | ||
} | ||
@@ -245,7 +196,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSignInUserSession = function getSignInUserSession() { | ||
getSignInUserSession() { | ||
return this.signInUserSession; | ||
}; | ||
} | ||
@@ -255,7 +204,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getUsername = function getUsername() { | ||
getUsername() { | ||
return this.username; | ||
}; | ||
} | ||
@@ -266,7 +213,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setUsername = function setUsername(Username) { | ||
setUsername(Username) { | ||
this.username = Username; | ||
}; | ||
} | ||
@@ -276,7 +221,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getState = function getState() { | ||
getState() { | ||
return this.state; | ||
}; | ||
} | ||
@@ -287,7 +230,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.setState = function setState(State) { | ||
setState(State) { | ||
this.state = State; | ||
}; | ||
} | ||
@@ -303,8 +244,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSession = function getSession() { | ||
var tokenScopesInputSet = new Set(this.TokenScopesArray); | ||
var cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes()); | ||
var URL = this.getFQDNSignIn(); | ||
getSession() { | ||
const tokenScopesInputSet = new Set(this.TokenScopesArray); | ||
const cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes()); | ||
const URL = this.getFQDNSignIn(); | ||
if (this.signInUserSession != null && this.signInUserSession.isValid()) { | ||
@@ -316,6 +255,6 @@ return this.userhandler.onSuccess(this.signInUserSession); | ||
if (!this.compareSets(tokenScopesInputSet, cachedScopesSet)) { | ||
var tokenScopes = new _CognitoTokenScopes2.default(this.TokenScopesArray); | ||
var idToken = new _CognitoIdToken2.default(); | ||
var accessToken = new _CognitoAccessToken2.default(); | ||
var refreshToken = new _CognitoRefreshToken2.default(); | ||
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray); | ||
const idToken = new CognitoIdToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const refreshToken = new CognitoRefreshToken(); | ||
this.signInUserSession.setTokenScopes(tokenScopes); | ||
@@ -334,3 +273,3 @@ this.signInUserSession.setIdToken(idToken); | ||
return undefined; | ||
}; | ||
} | ||
@@ -342,6 +281,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) { | ||
var map = void 0; | ||
parseCognitoWebResponse(httpRequestResponse) { | ||
let map; | ||
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) { | ||
@@ -351,3 +288,3 @@ // for code type | ||
// Sometimes the code will contain a poundsign in the end which breaks the parsing | ||
var response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0]; | ||
const response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0]; | ||
map = this.getQueryParameters(response, this.getCognitoConstants().QUESTIONMARK); | ||
@@ -364,3 +301,3 @@ this.getCodeQueryParameter(map); | ||
} | ||
}; | ||
} | ||
@@ -372,6 +309,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) { | ||
var state = null; | ||
getCodeQueryParameter(map) { | ||
const state = null; | ||
if (map.has(this.getCognitoConstants().STATE)) { | ||
@@ -386,14 +321,14 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE)); | ||
// To parse the response and get the code value. | ||
var codeParameter = map.get(this.getCognitoConstants().CODE); | ||
var url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
var header = this.getCognitoConstants().HEADER; | ||
var body = { grant_type: this.getCognitoConstants().AUTHORIZATIONCODE, | ||
const codeParameter = map.get(this.getCognitoConstants().CODE); | ||
const url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
const header = this.getCognitoConstants().HEADER; | ||
const body = { grant_type: this.getCognitoConstants().AUTHORIZATIONCODE, | ||
client_id: this.getClientId(), | ||
redirect_uri: this.RedirectUriSignIn, | ||
code: codeParameter }; | ||
var boundOnSuccess = this.onSuccessExchangeForToken.bind(this); | ||
var boundOnFailure = this.onFailure.bind(this); | ||
const boundOnSuccess = this.onSuccessExchangeForToken.bind(this); | ||
const boundOnFailure = this.onFailure.bind(this); | ||
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure); | ||
} | ||
}; | ||
} | ||
@@ -405,9 +340,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) { | ||
var idToken = new _CognitoIdToken2.default(); | ||
var accessToken = new _CognitoAccessToken2.default(); | ||
var refreshToken = new _CognitoRefreshToken2.default(); | ||
var state = null; | ||
getTokenQueryParameter(map) { | ||
const idToken = new CognitoIdToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const refreshToken = new CognitoRefreshToken(); | ||
const state = null; | ||
if (map.has(this.getCognitoConstants().IDTOKEN)) { | ||
@@ -432,3 +365,3 @@ idToken.setJwtToken(map.get(this.getCognitoConstants().IDTOKEN)); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
} | ||
@@ -439,25 +372,23 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getCachedSession = function getCachedSession() { | ||
getCachedSession() { | ||
if (!this.username) { | ||
return new _CognitoAuthSession2.default(); | ||
return new CognitoAuthSession(); | ||
} | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId() + '.' + this.username; | ||
var idTokenKey = keyPrefix + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.refreshToken'; | ||
var scopeKey = keyPrefix + '.tokenScopesString'; | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}.${this.username}`; | ||
const idTokenKey = `${keyPrefix}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.refreshToken`; | ||
const scopeKey = `${keyPrefix}.tokenScopesString`; | ||
var scopesString = this.storage.getItem(scopeKey); | ||
var scopesArray = []; | ||
const scopesString = this.storage.getItem(scopeKey); | ||
let scopesArray = []; | ||
if (scopesString) { | ||
scopesArray = scopesString.split(' '); | ||
} | ||
var tokenScopes = new _CognitoTokenScopes2.default(scopesArray); | ||
var idToken = new _CognitoIdToken2.default(this.storage.getItem(idTokenKey)); | ||
var accessToken = new _CognitoAccessToken2.default(this.storage.getItem(accessTokenKey)); | ||
var refreshToken = new _CognitoRefreshToken2.default(this.storage.getItem(refreshTokenKey)); | ||
const tokenScopes = new CognitoTokenScopes(scopesArray); | ||
const idToken = new CognitoIdToken(this.storage.getItem(idTokenKey)); | ||
const accessToken = new CognitoAccessToken(this.storage.getItem(accessTokenKey)); | ||
const refreshToken = new CognitoRefreshToken(this.storage.getItem(refreshTokenKey)); | ||
var sessionData = { | ||
const sessionData = { | ||
IdToken: idToken, | ||
@@ -468,5 +399,5 @@ AccessToken: accessToken, | ||
}; | ||
var cachedSession = new _CognitoAuthSession2.default(sessionData); | ||
const cachedSession = new CognitoAuthSession(sessionData); | ||
return cachedSession; | ||
}; | ||
} | ||
@@ -477,8 +408,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getLastUser = function getLastUser() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var lastUserName = this.storage.getItem(lastUserKey); | ||
getLastUser() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const lastUserName = this.storage.getItem(lastUserKey); | ||
if (lastUserName) { | ||
@@ -488,3 +417,3 @@ return lastUserName; | ||
return undefined; | ||
}; | ||
} | ||
@@ -496,15 +425,13 @@ /** | ||
*/ | ||
CognitoAuth.prototype.cacheTokensScopes = function cacheTokensScopes() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var tokenUserName = this.signInUserSession.getAccessToken().getUsername(); | ||
cacheTokensScopes() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const tokenUserName = this.signInUserSession.getAccessToken().getUsername(); | ||
this.username = tokenUserName; | ||
var idTokenKey = keyPrefix + '.' + tokenUserName + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.' + tokenUserName + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.' + tokenUserName + '.refreshToken'; | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var scopeKey = keyPrefix + '.' + tokenUserName + '.tokenScopesString'; | ||
var scopesArray = this.signInUserSession.getTokenScopes().getScopes(); | ||
var scopesString = scopesArray.join(' '); | ||
const idTokenKey = `${keyPrefix}.${tokenUserName}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.${tokenUserName}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.${tokenUserName}.refreshToken`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const scopeKey = `${keyPrefix}.${tokenUserName}.tokenScopesString`; | ||
const scopesArray = this.signInUserSession.getTokenScopes().getScopes(); | ||
const scopesString = scopesArray.join(' '); | ||
this.storage.setItem(idTokenKey, this.signInUserSession.getIdToken().getJwtToken()); | ||
@@ -515,3 +442,3 @@ this.storage.setItem(accessTokenKey, this.signInUserSession.getAccessToken().getJwtToken()); | ||
this.storage.setItem(scopeKey, scopesString); | ||
}; | ||
} | ||
@@ -524,22 +451,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.compareSets = function compareSets(set1, set2) { | ||
compareSets(set1, set2) { | ||
if (set1.size !== set2.size) { | ||
return false; | ||
} | ||
for (var _iterator = set1, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref2 = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref2 = _i.value; | ||
} | ||
var item = _ref2; | ||
for (const item of set1) { | ||
if (!set2.has(item)) { | ||
@@ -550,3 +462,3 @@ return false; | ||
return true; | ||
}; | ||
} | ||
@@ -558,11 +470,9 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getHostName = function getHostName(url) { | ||
var match = url.match(this.getCognitoConstants().HOSTNAMEREGEX); | ||
if (match != null && match.length > 2 && _typeof(match[2]) === this.getCognitoConstants().STRINGTYPE && match[2].length > 0) { | ||
getHostName(url) { | ||
const match = url.match(this.getCognitoConstants().HOSTNAMEREGEX); | ||
if (match != null && match.length > 2 && typeof match[2] === this.getCognitoConstants().STRINGTYPE && match[2].length > 0) { | ||
return match[2]; | ||
} | ||
return undefined; | ||
}; | ||
} | ||
@@ -575,11 +485,9 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getQueryParameters = function getQueryParameters(url, splitMark) { | ||
var str = String(url).split(splitMark); | ||
var url2 = str[1]; | ||
var str1 = String(url2).split(this.getCognitoConstants().AMPERSAND); | ||
var num = str1.length; | ||
var map = new Map(); | ||
var i = void 0; | ||
getQueryParameters(url, splitMark) { | ||
const str = String(url).split(splitMark); | ||
const url2 = str[1]; | ||
const str1 = String(url2).split(this.getCognitoConstants().AMPERSAND); | ||
const num = str1.length; | ||
const map = new Map(); | ||
let i; | ||
for (i = 0; i < num; i++) { | ||
@@ -590,3 +498,3 @@ str1[i] = String(str1[i]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2); | ||
return map; | ||
}; | ||
} | ||
@@ -599,12 +507,9 @@ /** | ||
*/ | ||
generateRandomString(length, chars) { | ||
let result = ''; | ||
let i = length; | ||
for (; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; | ||
return result; | ||
} | ||
CognitoAuth.prototype.generateRandomString = function generateRandomString(length, chars) { | ||
var result = ''; | ||
var i = length; | ||
for (; i > 0; --i) { | ||
result += chars[Math.round(Math.random() * (chars.length - 1))]; | ||
}return result; | ||
}; | ||
/** | ||
@@ -614,12 +519,10 @@ * This is used to clear the session tokens and scopes from local storage | ||
*/ | ||
clearCachedTokensScopes() { | ||
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`; | ||
const idTokenKey = `${keyPrefix}.${this.username}.idToken`; | ||
const accessTokenKey = `${keyPrefix}.${this.username}.accessToken`; | ||
const refreshTokenKey = `${keyPrefix}.${this.username}.refreshToken`; | ||
const lastUserKey = `${keyPrefix}.LastAuthUser`; | ||
const scopeKey = `${keyPrefix}.${this.username}.tokenScopesString`; | ||
CognitoAuth.prototype.clearCachedTokensScopes = function clearCachedTokensScopes() { | ||
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId(); | ||
var idTokenKey = keyPrefix + '.' + this.username + '.idToken'; | ||
var accessTokenKey = keyPrefix + '.' + this.username + '.accessToken'; | ||
var refreshTokenKey = keyPrefix + '.' + this.username + '.refreshToken'; | ||
var lastUserKey = keyPrefix + '.LastAuthUser'; | ||
var scopeKey = keyPrefix + '.' + this.username + '.tokenScopesString'; | ||
this.storage.removeItem(idTokenKey); | ||
@@ -630,3 +533,3 @@ this.storage.removeItem(accessTokenKey); | ||
this.storage.removeItem(scopeKey); | ||
}; | ||
} | ||
@@ -638,16 +541,14 @@ /** | ||
*/ | ||
CognitoAuth.prototype.refreshSession = function refreshSession(refreshToken) { | ||
refreshSession(refreshToken) { | ||
// https POST call for refreshing token | ||
var url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
var header = this.getCognitoConstants().HEADER; | ||
var body = { grant_type: this.getCognitoConstants().REFRESHTOKEN, | ||
const url = this.getCognitoConstants().DOMAIN_SCHEME.concat(this.getCognitoConstants().COLONDOUBLESLASH, this.getAppWebDomain(), this.getCognitoConstants().SLASH, this.getCognitoConstants().DOMAIN_PATH_TOKEN); | ||
const header = this.getCognitoConstants().HEADER; | ||
const body = { grant_type: this.getCognitoConstants().REFRESHTOKEN, | ||
client_id: this.getClientId(), | ||
redirect_uri: this.RedirectUriSignIn, | ||
refresh_token: refreshToken }; | ||
var boundOnSuccess = this.onSuccessRefreshToken.bind(this); | ||
var boundOnFailure = this.onFailure.bind(this); | ||
const boundOnSuccess = this.onSuccessRefreshToken.bind(this); | ||
const boundOnFailure = this.onFailure.bind(this); | ||
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure); | ||
}; | ||
} | ||
@@ -663,8 +564,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.makePOSTRequest = function makePOSTRequest(header, body, url, onSuccess, onFailure) { | ||
makePOSTRequest(header, body, url, onSuccess, onFailure) { | ||
// This is a sample server that supports CORS. | ||
var xhr = this.createCORSRequest(this.getCognitoConstants().POST, url); | ||
var bodyString = ''; | ||
const xhr = this.createCORSRequest(this.getCognitoConstants().POST, url); | ||
let bodyString = ''; | ||
if (!xhr) { | ||
@@ -674,7 +573,7 @@ return; | ||
// set header | ||
for (var key in header) { | ||
for (let key in header) { | ||
xhr.setRequestHeader(key, header[key]); | ||
} | ||
for (var _key in body) { | ||
bodyString = bodyString.concat(_key, this.getCognitoConstants().EQUALSIGN, body[_key], this.getCognitoConstants().AMPERSAND); | ||
for (let key in body) { | ||
bodyString = bodyString.concat(key, this.getCognitoConstants().EQUALSIGN, body[key], this.getCognitoConstants().AMPERSAND); | ||
} | ||
@@ -692,3 +591,3 @@ bodyString = bodyString.substring(0, bodyString.length - 1); | ||
}; | ||
}; | ||
} | ||
@@ -701,6 +600,4 @@ /** | ||
*/ | ||
CognitoAuth.prototype.createCORSRequest = function createCORSRequest(method, url) { | ||
var xhr = new XMLHttpRequest(); | ||
createCORSRequest(method, url) { | ||
let xhr = new XMLHttpRequest(); | ||
xhr.open(method, url, true); | ||
@@ -710,3 +607,3 @@ if (this.getCognitoConstants().WITHCREDENTIALS in xhr) { | ||
xhr.open(method, url, true); | ||
} else if ((typeof XDomainRequest === 'undefined' ? 'undefined' : _typeof(XDomainRequest)) !== this.getCognitoConstants().UNDEFINED) { | ||
} else if (typeof XDomainRequest !== this.getCognitoConstants().UNDEFINED) { | ||
// XDomainRequest for IE. | ||
@@ -720,3 +617,3 @@ xhr = new XDomainRequest(); | ||
return xhr; | ||
}; | ||
} | ||
@@ -728,7 +625,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onFailure = function onFailure(err) { | ||
onFailure(err) { | ||
this.userhandler.onFailure(err); | ||
}; | ||
} | ||
@@ -739,15 +634,13 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onSuccessRefreshToken = function onSuccessRefreshToken(jsonData) { | ||
var jsonDataObject = JSON.parse(jsonData); | ||
onSuccessRefreshToken(jsonData) { | ||
const jsonDataObject = JSON.parse(jsonData); | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) { | ||
var URL = this.getFQDNSignIn(); | ||
const URL = this.getFQDNSignIn(); | ||
this.launchUri(URL); | ||
} else { | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().IDTOKEN)) { | ||
this.signInUserSession.setIdToken(new _CognitoIdToken2.default(jsonDataObject.id_token)); | ||
this.signInUserSession.setIdToken(new CognitoIdToken(jsonDataObject.id_token)); | ||
} | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ACCESSTOKEN)) { | ||
this.signInUserSession.setAccessToken(new _CognitoAccessToken2.default(jsonDataObject.access_token)); | ||
this.signInUserSession.setAccessToken(new CognitoAccessToken(jsonDataObject.access_token)); | ||
} | ||
@@ -757,3 +650,3 @@ this.cacheTokensScopes(); | ||
} | ||
}; | ||
} | ||
@@ -764,10 +657,8 @@ /** | ||
*/ | ||
CognitoAuth.prototype.onSuccessExchangeForToken = function onSuccessExchangeForToken(jsonData) { | ||
var jsonDataObject = JSON.parse(jsonData); | ||
var refreshToken = new _CognitoRefreshToken2.default(); | ||
var accessToken = new _CognitoAccessToken2.default(); | ||
var idToken = new _CognitoIdToken2.default(); | ||
var state = null; | ||
onSuccessExchangeForToken(jsonData) { | ||
const jsonDataObject = JSON.parse(jsonData); | ||
const refreshToken = new CognitoRefreshToken(); | ||
const accessToken = new CognitoAccessToken(); | ||
const idToken = new CognitoIdToken(); | ||
const state = null; | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) { | ||
@@ -777,3 +668,3 @@ return this.userhandler.onFailure(jsonData); | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().IDTOKEN)) { | ||
this.signInUserSession.setIdToken(new _CognitoIdToken2.default(jsonDataObject.id_token)); | ||
this.signInUserSession.setIdToken(new CognitoIdToken(jsonDataObject.id_token)); | ||
} else { | ||
@@ -783,3 +674,3 @@ this.signInUserSession.setIdToken(idToken); | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ACCESSTOKEN)) { | ||
this.signInUserSession.setAccessToken(new _CognitoAccessToken2.default(jsonDataObject.access_token)); | ||
this.signInUserSession.setAccessToken(new CognitoAccessToken(jsonDataObject.access_token)); | ||
} else { | ||
@@ -789,3 +680,3 @@ this.signInUserSession.setAccessToken(accessToken); | ||
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().REFRESHTOKEN)) { | ||
this.signInUserSession.setRefreshToken(new _CognitoRefreshToken2.default(jsonDataObject.refresh_token)); | ||
this.signInUserSession.setRefreshToken(new CognitoRefreshToken(jsonDataObject.refresh_token)); | ||
} else { | ||
@@ -796,3 +687,3 @@ this.signInUserSession.setRefreshToken(refreshToken); | ||
this.userhandler.onSuccess(this.signInUserSession); | ||
}; | ||
} | ||
@@ -804,7 +695,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.launchUri = function launchUri(URL) { | ||
launchUri(URL) { | ||
window.open(URL, this.getCognitoConstants().SELF); | ||
}; | ||
} | ||
@@ -814,9 +703,7 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getSpaceSeperatedScopeString = function getSpaceSeperatedScopeString() { | ||
var tokenScopesString = this.signInUserSession.getTokenScopes().getScopes(); | ||
getSpaceSeperatedScopeString() { | ||
let tokenScopesString = this.signInUserSession.getTokenScopes().getScopes(); | ||
tokenScopesString = tokenScopesString.join(this.getCognitoConstants().SPACE); | ||
return encodeURIComponent(tokenScopesString); | ||
}; | ||
} | ||
@@ -827,5 +714,3 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getFQDNSignIn = function getFQDNSignIn() { | ||
getFQDNSignIn() { | ||
if (this.state == null) { | ||
@@ -835,4 +720,4 @@ this.state = this.generateRandomString(this.getCognitoConstants().STATELENGTH, this.getCognitoConstants().STATEORIGINSTRING); | ||
var identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : ''; | ||
var tokenScopesString = this.getSpaceSeperatedScopeString(); | ||
const identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : ''; | ||
const tokenScopesString = this.getSpaceSeperatedScopeString(); | ||
@@ -846,6 +731,6 @@ var userContextDataParam = ''; | ||
// Build the complete web domain to launch the login screen | ||
var uri = 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, tokenScopesString, identityProviderParam, userContextDataParam); | ||
const uri = 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, tokenScopesString, identityProviderParam, userContextDataParam); | ||
return uri; | ||
}; | ||
} | ||
@@ -856,10 +741,8 @@ /** | ||
*/ | ||
CognitoAuth.prototype.signOut = function signOut() { | ||
var URL = this.getFQDNSignOut(); | ||
signOut() { | ||
const URL = this.getFQDNSignOut(); | ||
this.signInUserSession = null; | ||
this.clearCachedTokensScopes(); | ||
this.launchUri(URL); | ||
}; | ||
} | ||
@@ -870,8 +753,6 @@ /** | ||
*/ | ||
CognitoAuth.prototype.getFQDNSignOut = function getFQDNSignOut() { | ||
var uri = 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()); | ||
getFQDNSignOut() { | ||
const uri = 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 uri; | ||
}; | ||
} | ||
@@ -884,5 +765,3 @@ /** | ||
**/ | ||
CognitoAuth.prototype.getUserContextData = function getUserContextData() { | ||
getUserContextData() { | ||
if (typeof AmazonCognitoAdvancedSecurityData === "undefined") { | ||
@@ -905,3 +784,3 @@ return; | ||
} | ||
}; | ||
} | ||
@@ -913,11 +792,5 @@ /** | ||
*/ | ||
CognitoAuth.prototype.isUserSignedIn = function isUserSignedIn() { | ||
isUserSignedIn() { | ||
return this.signInUserSession != null && this.signInUserSession.isValid() || this.getCachedSession() != null && this.getCachedSession().isValid(); | ||
}; | ||
return CognitoAuth; | ||
}(); | ||
exports.default = CognitoAuth; | ||
} | ||
} |
@@ -1,42 +0,25 @@ | ||
'use strict'; | ||
/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
exports.__esModule = true; | ||
* 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. | ||
*/ | ||
var _CognitoTokenScopes = require('./CognitoTokenScopes'); | ||
import CognitoTokenScopes from './CognitoTokenScopes'; | ||
import CognitoAccessToken from './CognitoAccessToken'; | ||
import CognitoIdToken from './CognitoIdToken'; | ||
import CognitoRefreshToken from './CognitoRefreshToken'; | ||
var _CognitoTokenScopes2 = _interopRequireDefault(_CognitoTokenScopes); | ||
var _CognitoAccessToken = require('./CognitoAccessToken'); | ||
var _CognitoAccessToken2 = _interopRequireDefault(_CognitoAccessToken); | ||
var _CognitoIdToken = require('./CognitoIdToken'); | ||
var _CognitoIdToken2 = _interopRequireDefault(_CognitoIdToken); | ||
var _CognitoRefreshToken = require('./CognitoRefreshToken'); | ||
var _CognitoRefreshToken2 = _interopRequireDefault(_CognitoRefreshToken); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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. | ||
*/ | ||
/** @class */ | ||
var CognitoAuthSession = function () { | ||
export default class CognitoAuthSession { | ||
/** | ||
@@ -50,16 +33,7 @@ * Constructs a new CognitoUserSession object | ||
*/ | ||
function CognitoAuthSession() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
IdToken = _ref.IdToken, | ||
RefreshToken = _ref.RefreshToken, | ||
AccessToken = _ref.AccessToken, | ||
TokenScopes = _ref.TokenScopes, | ||
State = _ref.State; | ||
_classCallCheck(this, CognitoAuthSession); | ||
constructor({ IdToken, RefreshToken, AccessToken, TokenScopes, State } = {}) { | ||
if (IdToken) { | ||
this.idToken = IdToken; | ||
} else { | ||
this.idToken = new _CognitoIdToken2.default(); | ||
this.idToken = new CognitoIdToken(); | ||
} | ||
@@ -69,3 +43,3 @@ if (RefreshToken) { | ||
} else { | ||
this.refreshToken = new _CognitoRefreshToken2.default(); | ||
this.refreshToken = new CognitoRefreshToken(); | ||
} | ||
@@ -75,3 +49,3 @@ if (AccessToken) { | ||
} else { | ||
this.accessToken = new _CognitoAccessToken2.default(); | ||
this.accessToken = new CognitoAccessToken(); | ||
} | ||
@@ -81,3 +55,3 @@ if (TokenScopes) { | ||
} else { | ||
this.tokenScopes = new _CognitoTokenScopes2.default(); | ||
this.tokenScopes = new CognitoTokenScopes(); | ||
} | ||
@@ -94,7 +68,5 @@ if (State) { | ||
*/ | ||
CognitoAuthSession.prototype.getIdToken = function getIdToken() { | ||
getIdToken() { | ||
return this.idToken; | ||
}; | ||
} | ||
@@ -106,7 +78,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setIdToken = function setIdToken(IdToken) { | ||
setIdToken(IdToken) { | ||
this.idToken = IdToken; | ||
}; | ||
} | ||
@@ -116,7 +86,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getRefreshToken = function getRefreshToken() { | ||
getRefreshToken() { | ||
return this.refreshToken; | ||
}; | ||
} | ||
@@ -128,7 +96,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setRefreshToken = function setRefreshToken(RefreshToken) { | ||
setRefreshToken(RefreshToken) { | ||
this.refreshToken = RefreshToken; | ||
}; | ||
} | ||
@@ -138,7 +104,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getAccessToken = function getAccessToken() { | ||
getAccessToken() { | ||
return this.accessToken; | ||
}; | ||
} | ||
@@ -150,7 +114,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setAccessToken = function setAccessToken(AccessToken) { | ||
setAccessToken(AccessToken) { | ||
this.accessToken = AccessToken; | ||
}; | ||
} | ||
@@ -160,7 +122,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getTokenScopes = function getTokenScopes() { | ||
getTokenScopes() { | ||
return this.tokenScopes; | ||
}; | ||
} | ||
@@ -172,7 +132,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setTokenScopes = function setTokenScopes(tokenScopes) { | ||
setTokenScopes(tokenScopes) { | ||
this.tokenScopes = tokenScopes; | ||
}; | ||
} | ||
@@ -182,7 +140,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.getState = function getState() { | ||
getState() { | ||
return this.state; | ||
}; | ||
} | ||
@@ -194,7 +150,5 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.setState = function setState(State) { | ||
setState(State) { | ||
this.state = State; | ||
}; | ||
} | ||
@@ -206,6 +160,4 @@ /** | ||
*/ | ||
CognitoAuthSession.prototype.isValid = function isValid() { | ||
var now = Math.floor(new Date() / 1000); | ||
isValid() { | ||
const now = Math.floor(new Date() / 1000); | ||
try { | ||
@@ -222,7 +174,3 @@ if (this.accessToken != null) { | ||
} | ||
}; | ||
return CognitoAuthSession; | ||
}(); | ||
exports.default = CognitoAuthSession; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -23,4 +17,6 @@ * Amazon Cognito Auth SDK for JavaScript | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
var CognitoIdToken = function () { | ||
export default class CognitoIdToken { | ||
/** | ||
@@ -30,5 +26,3 @@ * Constructs a new CognitoIdToken object | ||
*/ | ||
function CognitoIdToken(IdToken) { | ||
_classCallCheck(this, CognitoIdToken); | ||
constructor(IdToken) { | ||
// Assign object | ||
@@ -42,7 +36,5 @@ this.jwtToken = IdToken || ''; | ||
*/ | ||
CognitoIdToken.prototype.getJwtToken = function getJwtToken() { | ||
getJwtToken() { | ||
return this.jwtToken; | ||
}; | ||
} | ||
@@ -54,7 +46,5 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.setJwtToken = function setJwtToken(idToken) { | ||
setJwtToken(idToken) { | ||
this.jwtToken = idToken; | ||
}; | ||
} | ||
@@ -64,11 +54,9 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.getExpiration = function getExpiration() { | ||
getExpiration() { | ||
if (this.jwtToken === null) { | ||
return undefined; | ||
} | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
}; | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -78,16 +66,10 @@ /** | ||
*/ | ||
CognitoIdToken.prototype.decodePayload = function decodePayload() { | ||
var jwtPayload = this.jwtToken.split('.')[1]; | ||
decodePayload() { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
return {}; | ||
} | ||
}; | ||
return CognitoIdToken; | ||
}(); | ||
exports.default = CognitoIdToken; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -25,3 +19,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoRefreshToken = function () { | ||
export default class CognitoRefreshToken { | ||
/** | ||
@@ -31,5 +25,3 @@ * Constructs a new CognitoRefreshToken object | ||
*/ | ||
function CognitoRefreshToken(RefreshToken) { | ||
_classCallCheck(this, CognitoRefreshToken); | ||
constructor(RefreshToken) { | ||
// Assign object | ||
@@ -42,7 +34,5 @@ this.refreshToken = RefreshToken || ''; | ||
*/ | ||
CognitoRefreshToken.prototype.getToken = function getToken() { | ||
getToken() { | ||
return this.refreshToken; | ||
}; | ||
} | ||
@@ -54,11 +44,5 @@ /** | ||
*/ | ||
CognitoRefreshToken.prototype.setToken = function setToken(refreshToken) { | ||
setToken(refreshToken) { | ||
this.refreshToken = refreshToken; | ||
}; | ||
return CognitoRefreshToken; | ||
}(); | ||
exports.default = CognitoRefreshToken; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -25,3 +19,3 @@ * Amazon Cognito Auth SDK for JavaScript | ||
/** @class */ | ||
var CognitoTokenScopes = function () { | ||
export default class CognitoTokenScopes { | ||
/** | ||
@@ -31,5 +25,3 @@ * Constructs a new CognitoTokenScopes object | ||
*/ | ||
function CognitoTokenScopes(TokenScopesArray) { | ||
_classCallCheck(this, CognitoTokenScopes); | ||
constructor(TokenScopesArray) { | ||
// Assign object | ||
@@ -42,7 +34,5 @@ this.tokenScopes = TokenScopesArray || []; | ||
*/ | ||
CognitoTokenScopes.prototype.getScopes = function getScopes() { | ||
getScopes() { | ||
return this.tokenScopes; | ||
}; | ||
} | ||
@@ -54,11 +44,5 @@ /** | ||
*/ | ||
CognitoTokenScopes.prototype.setTokenScopes = function setTokenScopes(tokenScopes) { | ||
setTokenScopes(tokenScopes) { | ||
this.tokenScopes = tokenScopes; | ||
}; | ||
return CognitoTokenScopes; | ||
}(); | ||
exports.default = CognitoTokenScopes; | ||
} | ||
} |
@@ -1,15 +0,6 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
import * as Cookies from 'js-cookie'; | ||
var _jsCookie = require('js-cookie'); | ||
var Cookies = _interopRequireWildcard(_jsCookie); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** @class */ | ||
var CookieStorage = function () { | ||
export default class CookieStorage { | ||
@@ -24,5 +15,3 @@ /** | ||
*/ | ||
function CookieStorage(data) { | ||
_classCallCheck(this, CookieStorage); | ||
constructor(data) { | ||
this.domain = data.domain; | ||
@@ -52,5 +41,3 @@ if (data.path) { | ||
*/ | ||
CookieStorage.prototype.setItem = function setItem(key, value) { | ||
setItem(key, value) { | ||
Cookies.set(key, value, { | ||
@@ -63,3 +50,3 @@ path: this.path, | ||
return Cookies.get(key); | ||
}; | ||
} | ||
@@ -72,7 +59,5 @@ /** | ||
*/ | ||
CookieStorage.prototype.getItem = function getItem(key) { | ||
getItem(key) { | ||
return Cookies.get(key); | ||
}; | ||
} | ||
@@ -84,5 +69,3 @@ /** | ||
*/ | ||
CookieStorage.prototype.removeItem = function removeItem(key) { | ||
removeItem(key) { | ||
return Cookies.remove(key, { | ||
@@ -93,3 +76,3 @@ path: this.path, | ||
}); | ||
}; | ||
} | ||
@@ -100,7 +83,5 @@ /** | ||
*/ | ||
CookieStorage.prototype.clear = function clear() { | ||
var cookies = Cookies.get(); | ||
var index = void 0; | ||
clear() { | ||
const cookies = Cookies.get(); | ||
let index; | ||
for (index = 0; index < cookies.length; ++index) { | ||
@@ -110,7 +91,3 @@ Cookies.remove(cookies[index]); | ||
return {}; | ||
}; | ||
return CookieStorage; | ||
}(); | ||
exports.default = CookieStorage; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -23,48 +17,39 @@ * Amazon Cognito Auth SDK for JavaScript | ||
*/ | ||
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | ||
var weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | ||
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | ||
const weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | ||
/** @class */ | ||
var DateHelper = function () { | ||
function DateHelper() { | ||
_classCallCheck(this, DateHelper); | ||
} | ||
export default class DateHelper { | ||
/** | ||
* @returns {string} The current time in "ddd MMM D HH:mm:ss UTC YYYY" format. | ||
*/ | ||
DateHelper.prototype.getNowString = function getNowString() { | ||
var now = new Date(); | ||
getNowString() { | ||
const now = new Date(); | ||
var weekDay = weekNames[now.getUTCDay()]; | ||
var month = monthNames[now.getUTCMonth()]; | ||
var day = now.getUTCDate(); | ||
const weekDay = weekNames[now.getUTCDay()]; | ||
const month = monthNames[now.getUTCMonth()]; | ||
const day = now.getUTCDate(); | ||
var hours = now.getUTCHours(); | ||
let hours = now.getUTCHours(); | ||
if (hours < 10) { | ||
hours = '0' + hours; | ||
hours = `0${hours}`; | ||
} | ||
var minutes = now.getUTCMinutes(); | ||
let minutes = now.getUTCMinutes(); | ||
if (minutes < 10) { | ||
minutes = '0' + minutes; | ||
minutes = `0${minutes}`; | ||
} | ||
var seconds = now.getUTCSeconds(); | ||
let seconds = now.getUTCSeconds(); | ||
if (seconds < 10) { | ||
seconds = '0' + seconds; | ||
seconds = `0${seconds}`; | ||
} | ||
var year = now.getUTCFullYear(); | ||
const year = now.getUTCFullYear(); | ||
// ddd MMM D HH:mm:ss UTC YYYY | ||
var dateNow = weekDay + ' ' + month + ' ' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' UTC ' + year; | ||
const dateNow = `${weekDay} ${month} ${day} ${hours}:${minutes}:${seconds} UTC ${year}`; | ||
return dateNow; | ||
}; | ||
return DateHelper; | ||
}(); | ||
exports.default = DateHelper; | ||
} | ||
} |
@@ -1,77 +0,26 @@ | ||
'use strict'; | ||
/*! | ||
* Amazon Cognito Auth SDK for JavaScript | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
exports.__esModule = true; | ||
* 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. | ||
*/ | ||
var _CognitoAccessToken = require('./CognitoAccessToken'); | ||
Object.defineProperty(exports, 'CognitoAccessToken', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoAccessToken).default; | ||
} | ||
}); | ||
var _CognitoIdToken = require('./CognitoIdToken'); | ||
Object.defineProperty(exports, 'CognitoIdToken', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoIdToken).default; | ||
} | ||
}); | ||
var _CognitoRefreshToken = require('./CognitoRefreshToken'); | ||
Object.defineProperty(exports, 'CognitoRefreshToken', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoRefreshToken).default; | ||
} | ||
}); | ||
var _CognitoTokenScopes = require('./CognitoTokenScopes'); | ||
Object.defineProperty(exports, 'CognitoTokenScopes', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoTokenScopes).default; | ||
} | ||
}); | ||
var _CognitoAuth = require('./CognitoAuth'); | ||
Object.defineProperty(exports, 'CognitoAuth', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoAuth).default; | ||
} | ||
}); | ||
var _CognitoAuthSession = require('./CognitoAuthSession'); | ||
Object.defineProperty(exports, 'CognitoAuthSession', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_CognitoAuthSession).default; | ||
} | ||
}); | ||
var _DateHelper = require('./DateHelper'); | ||
Object.defineProperty(exports, 'DateHelper', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_DateHelper).default; | ||
} | ||
}); | ||
var _StorageHelper = require('./StorageHelper'); | ||
Object.defineProperty(exports, 'StorageHelper', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_StorageHelper).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
export { default as CognitoAccessToken } from './CognitoAccessToken'; | ||
export { default as CognitoIdToken } from './CognitoIdToken'; | ||
export { default as CognitoRefreshToken } from './CognitoRefreshToken'; | ||
export { default as CognitoTokenScopes } from './CognitoTokenScopes'; | ||
export { default as CognitoAuth } from './CognitoAuth'; | ||
export { default as CognitoAuthSession } from './CognitoAuthSession'; | ||
export { default as DateHelper } from './DateHelper'; | ||
export { default as StorageHelper } from './StorageHelper'; | ||
export { default as CookieStorage } from './CookieStorage'; |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*! | ||
@@ -23,11 +17,7 @@ * Amazon Cognito Auth SDK for JavaScript | ||
*/ | ||
var dataMemory = {}; | ||
let dataMemory = {}; | ||
/** @class */ | ||
class MemoryStorage { | ||
var MemoryStorage = function () { | ||
function MemoryStorage() { | ||
_classCallCheck(this, MemoryStorage); | ||
} | ||
/** | ||
@@ -39,6 +29,6 @@ * This is used to set a specific item in storage | ||
*/ | ||
MemoryStorage.setItem = function setItem(key, value) { | ||
static setItem(key, value) { | ||
dataMemory[key] = value; | ||
return dataMemory[key]; | ||
}; | ||
} | ||
@@ -51,7 +41,5 @@ /** | ||
*/ | ||
MemoryStorage.getItem = function getItem(key) { | ||
static getItem(key) { | ||
return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined; | ||
}; | ||
} | ||
@@ -63,7 +51,5 @@ /** | ||
*/ | ||
MemoryStorage.removeItem = function removeItem(key) { | ||
static removeItem(key) { | ||
return delete dataMemory[key]; | ||
}; | ||
} | ||
@@ -74,17 +60,11 @@ /** | ||
*/ | ||
MemoryStorage.clear = function clear() { | ||
static clear() { | ||
dataMemory = {}; | ||
return dataMemory; | ||
}; | ||
} | ||
} | ||
return MemoryStorage; | ||
}(); | ||
/** @class */ | ||
export default class StorageHelper { | ||
var StorageHelper = function () { | ||
/** | ||
@@ -94,5 +74,3 @@ * This is used to get a storage object | ||
*/ | ||
function StorageHelper() { | ||
_classCallCheck(this, StorageHelper); | ||
constructor() { | ||
try { | ||
@@ -111,11 +89,5 @@ this.storageWindow = window.localStorage; | ||
*/ | ||
StorageHelper.prototype.getStorage = function getStorage() { | ||
getStorage() { | ||
return this.storageWindow; | ||
}; | ||
return StorageHelper; | ||
}(); | ||
exports.default = StorageHelper; | ||
} | ||
} |
{ | ||
"name": "amazon-cognito-auth-js", | ||
"description": "Amazon Cognito Auth JavaScript SDK", | ||
"version": "1.2.4", | ||
"version": "1.2.5-atob-react-native", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Amazon Web Services", |
@@ -18,2 +18,4 @@ /*! | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
@@ -55,3 +57,3 @@ export default class CognitoAccessToken { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -67,3 +69,3 @@ | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).username; | ||
return JSON.parse(decode(jwtPayload)).username; | ||
} | ||
@@ -77,3 +79,3 @@ | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
@@ -80,0 +82,0 @@ return {}; |
@@ -17,2 +17,4 @@ /*! | ||
import { decode } from './DecodingHelper'; | ||
/** @class */ | ||
@@ -54,3 +56,3 @@ export default class CognitoIdToken { | ||
const jwtPayload = this.jwtToken.split('.')[1]; | ||
return JSON.parse(atob(jwtPayload)).exp; | ||
return JSON.parse(decode(jwtPayload)).exp; | ||
} | ||
@@ -64,3 +66,3 @@ | ||
try { | ||
return JSON.parse(atob(jwtPayload)); | ||
return JSON.parse(decode(jwtPayload)); | ||
} catch (err) { | ||
@@ -67,0 +69,0 @@ 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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
1297136
54
23169
0
2
1