Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amazon-cognito-auth-js

Package Overview
Dependencies
Maintainers
11
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amazon-cognito-auth-js - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

.babelrc

51

es/CognitoAccessToken.js

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -21,3 +23,4 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoAccessToken {
var CognitoAccessToken = function () {
/**

@@ -27,3 +30,5 @@ * Constructs a new CognitoAccessToken object

*/
constructor(AccessToken) {
function CognitoAccessToken(AccessToken) {
_classCallCheck(this, CognitoAccessToken);
// Assign object

@@ -37,5 +42,7 @@ this.jwtToken = AccessToken || '';

*/
getJwtToken() {
CognitoAccessToken.prototype.getJwtToken = function getJwtToken() {
return this.jwtToken;
}
};

@@ -47,5 +54,7 @@ /**

*/
setJwtToken(accessToken) {
CognitoAccessToken.prototype.setJwtToken = function setJwtToken(accessToken) {
this.jwtToken = accessToken;
}
};

@@ -55,9 +64,11 @@ /**

*/
getExpiration() {
CognitoAccessToken.prototype.getExpiration = function getExpiration() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).exp;
}
};

@@ -67,9 +78,11 @@ /**

*/
getUsername() {
CognitoAccessToken.prototype.getUsername = function getUsername() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).username;
}
};

@@ -79,4 +92,6 @@ /**

*/
decodePayload() {
const jwtPayload = this.jwtToken.split('.')[1];
CognitoAccessToken.prototype.decodePayload = function decodePayload() {
var jwtPayload = this.jwtToken.split('.')[1];
try {

@@ -87,3 +102,7 @@ return JSON.parse(decode(jwtPayload));

}
}
}
};
return CognitoAccessToken;
}();
export default CognitoAccessToken;

@@ -0,1 +1,5 @@

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"); } }
/*!

@@ -27,3 +31,4 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoAuth {
var CognitoAuth = function () {
/**

@@ -50,6 +55,17 @@ * Constructs a new CognitoAuth object

*/
constructor(data) {
const { ClientId, AppWebDomain, TokenScopesArray,
RedirectUriSignIn, RedirectUriSignOut, IdentityProvider, UserPoolId,
AdvancedSecurityDataCollectionFlag, Storage, LaunchUri } = data || {};
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,
LaunchUri = _ref.LaunchUri;
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {

@@ -65,3 +81,3 @@ throw new Error(this.getCognitoConstants().PARAMETERERROR);

}
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
var tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
this.RedirectUriSignIn = RedirectUriSignIn;

@@ -90,4 +106,6 @@ this.RedirectUriSignOut = RedirectUriSignOut;

*/
getCognitoConstants() {
const CognitoConstants = {
CognitoAuth.prototype.getCognitoConstants = function getCognitoConstants() {
var CognitoConstants = {
DOMAIN_SCHEME: 'https',

@@ -136,3 +154,3 @@ DOMAIN_PATH_SIGNIN: 'oauth2/authorize',

return CognitoConstants;
}
};

@@ -142,5 +160,7 @@ /**

*/
getClientId() {
CognitoAuth.prototype.getClientId = function getClientId() {
return this.clientId;
}
};

@@ -150,5 +170,7 @@ /**

*/
getAppWebDomain() {
CognitoAuth.prototype.getAppWebDomain = function getAppWebDomain() {
return this.appWebDomain;
}
};

@@ -160,8 +182,10 @@ /**

*/
getCurrentUser() {
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`;
const lastAuthUser = this.storage.getItem(lastUserKey);
CognitoAuth.prototype.getCurrentUser = function getCurrentUser() {
var lastUserKey = 'CognitoIdentityServiceProvider.' + this.clientId + '.LastAuthUser';
var lastAuthUser = this.storage.getItem(lastUserKey);
return lastAuthUser;
}
};

@@ -173,5 +197,7 @@ /**

*/
setUser(Username) {
CognitoAuth.prototype.setUser = function setUser(Username) {
this.username = Username;
}
};

@@ -182,5 +208,7 @@ /**

*/
useCodeGrantFlow() {
CognitoAuth.prototype.useCodeGrantFlow = function useCodeGrantFlow() {
this.responseType = this.getCognitoConstants().CODE;
}
};

@@ -191,5 +219,7 @@ /**

*/
useImplicitFlow() {
CognitoAuth.prototype.useImplicitFlow = function useImplicitFlow() {
this.responseType = this.getCognitoConstants().TOKEN;
}
};

@@ -199,5 +229,7 @@ /**

*/
getSignInUserSession() {
CognitoAuth.prototype.getSignInUserSession = function getSignInUserSession() {
return this.signInUserSession;
}
};

@@ -207,5 +239,7 @@ /**

*/
getUsername() {
CognitoAuth.prototype.getUsername = function getUsername() {
return this.username;
}
};

@@ -216,5 +250,7 @@ /**

*/
setUsername(Username) {
CognitoAuth.prototype.setUsername = function setUsername(Username) {
this.username = Username;
}
};

@@ -224,5 +260,7 @@ /**

*/
getState() {
CognitoAuth.prototype.getState = function getState() {
return this.state;
}
};

@@ -233,5 +271,7 @@ /**

*/
setState(State) {
CognitoAuth.prototype.setState = function setState(State) {
this.state = State;
}
};

@@ -247,6 +287,8 @@ /**

*/
getSession() {
const tokenScopesInputSet = new Set(this.TokenScopesArray);
const cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes());
const URL = this.getFQDNSignIn();
CognitoAuth.prototype.getSession = function getSession() {
var tokenScopesInputSet = new Set(this.TokenScopesArray);
var cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes());
var URL = this.getFQDNSignIn();
if (this.signInUserSession != null && this.signInUserSession.isValid()) {

@@ -258,6 +300,6 @@ return this.userhandler.onSuccess(this.signInUserSession);

if (!this.compareSets(tokenScopesInputSet, cachedScopesSet)) {
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
const idToken = new CognitoIdToken();
const accessToken = new CognitoAccessToken();
const refreshToken = new CognitoRefreshToken();
var tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
var idToken = new CognitoIdToken();
var accessToken = new CognitoAccessToken();
var refreshToken = new CognitoRefreshToken();
this.signInUserSession.setTokenScopes(tokenScopes);

@@ -276,3 +318,3 @@ this.signInUserSession.setIdToken(idToken);

return undefined;
}
};

@@ -284,4 +326,6 @@ /**

*/
parseCognitoWebResponse(httpRequestResponse) {
let map;
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) {
var map = void 0;
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) {

@@ -291,3 +335,3 @@ // for code type

// Sometimes the code will contain a poundsign in the end which breaks the parsing
const response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0];
var response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0];
map = this.getQueryParameters(response, this.getCognitoConstants().QUESTIONMARK);

@@ -307,3 +351,3 @@ if (map.has(this.getCognitoConstants().ERROR)) {

}
}
};

@@ -315,4 +359,6 @@ /**

*/
getCodeQueryParameter(map) {
const state = null;
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) {
var state = null;
if (map.has(this.getCognitoConstants().STATE)) {

@@ -327,14 +373,14 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE));

// To parse the response and get the code value.
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,
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,
client_id: this.getClientId(),
redirect_uri: this.RedirectUriSignIn,
code: codeParameter };
const boundOnSuccess = this.onSuccessExchangeForToken.bind(this);
const boundOnFailure = this.onFailure.bind(this);
var boundOnSuccess = this.onSuccessExchangeForToken.bind(this);
var boundOnFailure = this.onFailure.bind(this);
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure);
}
}
};

@@ -346,7 +392,9 @@ /**

*/
getTokenQueryParameter(map) {
const idToken = new CognitoIdToken();
const accessToken = new CognitoAccessToken();
const refreshToken = new CognitoRefreshToken();
const state = null;
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) {
var idToken = new CognitoIdToken();
var accessToken = new CognitoAccessToken();
var refreshToken = new CognitoRefreshToken();
var state = null;
if (map.has(this.getCognitoConstants().IDTOKEN)) {

@@ -371,3 +419,3 @@ idToken.setJwtToken(map.get(this.getCognitoConstants().IDTOKEN));

this.userhandler.onSuccess(this.signInUserSession);
}
};

@@ -378,23 +426,25 @@ /**

*/
getCachedSession() {
CognitoAuth.prototype.getCachedSession = function getCachedSession() {
if (!this.username) {
return new CognitoAuthSession();
}
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}.${this.username}`;
const idTokenKey = `${keyPrefix}.idToken`;
const accessTokenKey = `${keyPrefix}.accessToken`;
const refreshTokenKey = `${keyPrefix}.refreshToken`;
const scopeKey = `${keyPrefix}.tokenScopesString`;
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId() + '.' + this.username;
var idTokenKey = keyPrefix + '.idToken';
var accessTokenKey = keyPrefix + '.accessToken';
var refreshTokenKey = keyPrefix + '.refreshToken';
var scopeKey = keyPrefix + '.tokenScopesString';
const scopesString = this.storage.getItem(scopeKey);
let scopesArray = [];
var scopesString = this.storage.getItem(scopeKey);
var scopesArray = [];
if (scopesString) {
scopesArray = scopesString.split(' ');
}
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 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 sessionData = {
var sessionData = {
IdToken: idToken,

@@ -405,5 +455,5 @@ AccessToken: accessToken,

};
const cachedSession = new CognitoAuthSession(sessionData);
var cachedSession = new CognitoAuthSession(sessionData);
return cachedSession;
}
};

@@ -414,6 +464,8 @@ /**

*/
getLastUser() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`;
const lastUserKey = `${keyPrefix}.LastAuthUser`;
const lastUserName = this.storage.getItem(lastUserKey);
CognitoAuth.prototype.getLastUser = function getLastUser() {
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId();
var lastUserKey = keyPrefix + '.LastAuthUser';
var lastUserName = this.storage.getItem(lastUserKey);
if (lastUserName) {

@@ -423,3 +475,3 @@ return lastUserName;

return undefined;
}
};

@@ -431,13 +483,15 @@ /**

*/
cacheTokensScopes() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`;
const tokenUserName = this.signInUserSession.getAccessToken().getUsername();
CognitoAuth.prototype.cacheTokensScopes = function cacheTokensScopes() {
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId();
var tokenUserName = this.signInUserSession.getAccessToken().getUsername();
this.username = tokenUserName;
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(' ');
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(' ');
this.storage.setItem(idTokenKey, this.signInUserSession.getIdToken().getJwtToken());

@@ -448,3 +502,3 @@ this.storage.setItem(accessTokenKey, this.signInUserSession.getAccessToken().getJwtToken());

this.storage.setItem(scopeKey, scopesString);
}
};

@@ -457,7 +511,22 @@ /**

*/
compareSets(set1, set2) {
CognitoAuth.prototype.compareSets = function compareSets(set1, set2) {
if (set1.size !== set2.size) {
return false;
}
for (const item of set1) {
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;
if (!set2.has(item)) {

@@ -468,3 +537,3 @@ return false;

return true;
}
};

@@ -476,9 +545,11 @@ /**

*/
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) {
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) {
return match[2];
}
return undefined;
}
};

@@ -491,9 +562,11 @@ /**

*/
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;
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;
for (i = 0; i < num; i++) {

@@ -504,3 +577,3 @@ str1[i] = String(str1[i]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2);

return map;
}
};

@@ -513,9 +586,12 @@ /**

*/
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;
};
/**

@@ -525,10 +601,12 @@ * 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);

@@ -539,3 +617,3 @@ this.storage.removeItem(accessTokenKey);

this.storage.removeItem(scopeKey);
}
};

@@ -547,14 +625,16 @@ /**

*/
refreshSession(refreshToken) {
CognitoAuth.prototype.refreshSession = function refreshSession(refreshToken) {
// https POST call for refreshing token
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,
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,
client_id: this.getClientId(),
redirect_uri: this.RedirectUriSignIn,
refresh_token: refreshToken };
const boundOnSuccess = this.onSuccessRefreshToken.bind(this);
const boundOnFailure = this.onFailure.bind(this);
var boundOnSuccess = this.onSuccessRefreshToken.bind(this);
var boundOnFailure = this.onFailure.bind(this);
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure);
}
};

@@ -570,6 +650,8 @@ /**

*/
makePOSTRequest(header, body, url, onSuccess, onFailure) {
CognitoAuth.prototype.makePOSTRequest = function makePOSTRequest(header, body, url, onSuccess, onFailure) {
// This is a sample server that supports CORS.
const xhr = this.createCORSRequest(this.getCognitoConstants().POST, url);
let bodyString = '';
var xhr = this.createCORSRequest(this.getCognitoConstants().POST, url);
var bodyString = '';
if (!xhr) {

@@ -579,7 +661,7 @@ return;

// set header
for (let key in header) {
for (var key in header) {
xhr.setRequestHeader(key, header[key]);
}
for (let key in body) {
bodyString = bodyString.concat(key, this.getCognitoConstants().EQUALSIGN, body[key], this.getCognitoConstants().AMPERSAND);
for (var _key in body) {
bodyString = bodyString.concat(_key, this.getCognitoConstants().EQUALSIGN, body[_key], this.getCognitoConstants().AMPERSAND);
}

@@ -597,3 +679,3 @@ bodyString = bodyString.substring(0, bodyString.length - 1);

};
}
};

@@ -606,8 +688,10 @@ /**

*/
createCORSRequest(method, url) {
let xhr = new XMLHttpRequest();
CognitoAuth.prototype.createCORSRequest = function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if (this.getCognitoConstants().WITHCREDENTIALS in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest !== this.getCognitoConstants().UNDEFINED) {
} else if ((typeof XDomainRequest === 'undefined' ? 'undefined' : _typeof(XDomainRequest)) !== this.getCognitoConstants().UNDEFINED) {
// XDomainRequest for IE.

@@ -621,3 +705,3 @@ xhr = new XDomainRequest();

return xhr;
}
};

@@ -629,5 +713,7 @@ /**

*/
onFailure(err) {
CognitoAuth.prototype.onFailure = function onFailure(err) {
this.userhandler.onFailure(err);
}
};

@@ -638,6 +724,8 @@ /**

*/
onSuccessRefreshToken(jsonData) {
const jsonDataObject = JSON.parse(jsonData);
CognitoAuth.prototype.onSuccessRefreshToken = function onSuccessRefreshToken(jsonData) {
var jsonDataObject = JSON.parse(jsonData);
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) {
const URL = this.getFQDNSignIn();
var URL = this.getFQDNSignIn();
this.launchUri(URL);

@@ -654,3 +742,3 @@ } else {

}
}
};

@@ -661,8 +749,10 @@ /**

*/
onSuccessExchangeForToken(jsonData) {
const jsonDataObject = JSON.parse(jsonData);
const refreshToken = new CognitoRefreshToken();
const accessToken = new CognitoAccessToken();
const idToken = new CognitoIdToken();
const state = null;
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;
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) {

@@ -688,3 +778,3 @@ return this.userhandler.onFailure(jsonData);

this.userhandler.onSuccess(this.signInUserSession);
}
};

@@ -696,12 +786,16 @@ /**

*/
launchUri() {} // overwritten in constructor
CognitoAuth.prototype.launchUri = function launchUri() {};
// overwritten in constructor
/**
* @returns {string} scopes string
*/
getSpaceSeperatedScopeString() {
let tokenScopesString = this.signInUserSession.getTokenScopes().getScopes();
CognitoAuth.prototype.getSpaceSeperatedScopeString = function getSpaceSeperatedScopeString() {
var tokenScopesString = this.signInUserSession.getTokenScopes().getScopes();
tokenScopesString = tokenScopesString.join(this.getCognitoConstants().SPACE);
return encodeURIComponent(tokenScopesString);
}
};

@@ -712,3 +806,5 @@ /**

*/
getFQDNSignIn() {
CognitoAuth.prototype.getFQDNSignIn = function getFQDNSignIn() {
if (this.state == null) {

@@ -718,4 +814,4 @@ this.state = this.generateRandomString(this.getCognitoConstants().STATELENGTH, this.getCognitoConstants().STATEORIGINSTRING);

const identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : '';
const tokenScopesString = this.getSpaceSeperatedScopeString();
var identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : '';
var tokenScopesString = this.getSpaceSeperatedScopeString();

@@ -729,6 +825,6 @@ var userContextDataParam = '';

// Build the complete web domain to launch the login screen
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);
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);
return uri;
}
};

@@ -739,8 +835,10 @@ /**

*/
signOut() {
const URL = this.getFQDNSignOut();
CognitoAuth.prototype.signOut = function signOut() {
var URL = this.getFQDNSignOut();
this.signInUserSession = null;
this.clearCachedTokensScopes();
this.launchUri(URL);
}
};

@@ -751,6 +849,8 @@ /**

*/
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());
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());
return uri;
}
};

@@ -763,3 +863,5 @@ /**

**/
getUserContextData() {
CognitoAuth.prototype.getUserContextData = function getUserContextData() {
if (typeof AmazonCognitoAdvancedSecurityData === "undefined") {

@@ -782,3 +884,3 @@ return;

}
}
};

@@ -790,5 +892,11 @@ /**

*/
isUserSignedIn() {
CognitoAuth.prototype.isUserSignedIn = function isUserSignedIn() {
return this.signInUserSession != null && this.signInUserSession.isValid() || this.getCachedSession() != null && this.getCachedSession().isValid();
}
}
};
return CognitoAuth;
}();
export default CognitoAuth;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -24,3 +26,4 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoAuthSession {
var CognitoAuthSession = function () {
/**

@@ -34,3 +37,12 @@ * Constructs a new CognitoUserSession object

*/
constructor({ IdToken, RefreshToken, AccessToken, TokenScopes, State } = {}) {
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);
if (IdToken) {

@@ -66,5 +78,7 @@ this.idToken = IdToken;

*/
getIdToken() {
CognitoAuthSession.prototype.getIdToken = function getIdToken() {
return this.idToken;
}
};

@@ -76,5 +90,7 @@ /**

*/
setIdToken(IdToken) {
CognitoAuthSession.prototype.setIdToken = function setIdToken(IdToken) {
this.idToken = IdToken;
}
};

@@ -84,5 +100,7 @@ /**

*/
getRefreshToken() {
CognitoAuthSession.prototype.getRefreshToken = function getRefreshToken() {
return this.refreshToken;
}
};

@@ -94,5 +112,7 @@ /**

*/
setRefreshToken(RefreshToken) {
CognitoAuthSession.prototype.setRefreshToken = function setRefreshToken(RefreshToken) {
this.refreshToken = RefreshToken;
}
};

@@ -102,5 +122,7 @@ /**

*/
getAccessToken() {
CognitoAuthSession.prototype.getAccessToken = function getAccessToken() {
return this.accessToken;
}
};

@@ -112,5 +134,7 @@ /**

*/
setAccessToken(AccessToken) {
CognitoAuthSession.prototype.setAccessToken = function setAccessToken(AccessToken) {
this.accessToken = AccessToken;
}
};

@@ -120,5 +144,7 @@ /**

*/
getTokenScopes() {
CognitoAuthSession.prototype.getTokenScopes = function getTokenScopes() {
return this.tokenScopes;
}
};

@@ -130,5 +156,7 @@ /**

*/
setTokenScopes(tokenScopes) {
CognitoAuthSession.prototype.setTokenScopes = function setTokenScopes(tokenScopes) {
this.tokenScopes = tokenScopes;
}
};

@@ -138,5 +166,7 @@ /**

*/
getState() {
CognitoAuthSession.prototype.getState = function getState() {
return this.state;
}
};

@@ -148,5 +178,7 @@ /**

*/
setState(State) {
CognitoAuthSession.prototype.setState = function setState(State) {
this.state = State;
}
};

@@ -158,4 +190,6 @@ /**

*/
isValid() {
const now = Math.floor(new Date() / 1000);
CognitoAuthSession.prototype.isValid = function isValid() {
var now = Math.floor(new Date() / 1000);
try {

@@ -172,3 +206,7 @@ if (this.accessToken != null) {

}
}
}
};
return CognitoAuthSession;
}();
export default CognitoAuthSession;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -20,3 +22,4 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoIdToken {
var CognitoIdToken = function () {
/**

@@ -26,3 +29,5 @@ * Constructs a new CognitoIdToken object

*/
constructor(IdToken) {
function CognitoIdToken(IdToken) {
_classCallCheck(this, CognitoIdToken);
// Assign object

@@ -36,5 +41,7 @@ this.jwtToken = IdToken || '';

*/
getJwtToken() {
CognitoIdToken.prototype.getJwtToken = function getJwtToken() {
return this.jwtToken;
}
};

@@ -46,5 +53,7 @@ /**

*/
setJwtToken(idToken) {
CognitoIdToken.prototype.setJwtToken = function setJwtToken(idToken) {
this.jwtToken = idToken;
}
};

@@ -54,9 +63,11 @@ /**

*/
getExpiration() {
CognitoIdToken.prototype.getExpiration = function getExpiration() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).exp;
}
};

@@ -66,4 +77,6 @@ /**

*/
decodePayload() {
const jwtPayload = this.jwtToken.split('.')[1];
CognitoIdToken.prototype.decodePayload = function decodePayload() {
var jwtPayload = this.jwtToken.split('.')[1];
try {

@@ -74,3 +87,7 @@ return JSON.parse(decode(jwtPayload));

}
}
}
};
return CognitoIdToken;
}();
export default CognitoIdToken;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -19,3 +21,3 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoRefreshToken {
var CognitoRefreshToken = function () {
/**

@@ -25,3 +27,5 @@ * Constructs a new CognitoRefreshToken object

*/
constructor(RefreshToken) {
function CognitoRefreshToken(RefreshToken) {
_classCallCheck(this, CognitoRefreshToken);
// Assign object

@@ -34,5 +38,7 @@ this.refreshToken = RefreshToken || '';

*/
getToken() {
CognitoRefreshToken.prototype.getToken = function getToken() {
return this.refreshToken;
}
};

@@ -44,5 +50,11 @@ /**

*/
setToken(refreshToken) {
CognitoRefreshToken.prototype.setToken = function setToken(refreshToken) {
this.refreshToken = refreshToken;
}
}
};
return CognitoRefreshToken;
}();
export default CognitoRefreshToken;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -19,3 +21,3 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoTokenScopes {
var CognitoTokenScopes = function () {
/**

@@ -25,3 +27,5 @@ * Constructs a new CognitoTokenScopes object

*/
constructor(TokenScopesArray) {
function CognitoTokenScopes(TokenScopesArray) {
_classCallCheck(this, CognitoTokenScopes);
// Assign object

@@ -34,5 +38,7 @@ this.tokenScopes = TokenScopesArray || [];

*/
getScopes() {
CognitoTokenScopes.prototype.getScopes = function getScopes() {
return this.tokenScopes;
}
};

@@ -44,5 +50,11 @@ /**

*/
setTokenScopes(tokenScopes) {
CognitoTokenScopes.prototype.setTokenScopes = function setTokenScopes(tokenScopes) {
this.tokenScopes = tokenScopes;
}
}
};
return CognitoTokenScopes;
}();
export default CognitoTokenScopes;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -5,4 +6,5 @@ import * as Cookies from 'js-cookie';

/** @class */
export default class CookieStorage {
var CookieStorage = function () {
/**

@@ -16,3 +18,5 @@ * Constructs a new CookieStorage object

*/
constructor(data) {
function CookieStorage(data) {
_classCallCheck(this, CookieStorage);
this.domain = data.domain;

@@ -42,3 +46,5 @@ if (data.path) {

*/
setItem(key, value) {
CookieStorage.prototype.setItem = function setItem(key, value) {
Cookies.set(key, value, {

@@ -51,3 +57,3 @@ path: this.path,

return Cookies.get(key);
}
};

@@ -60,5 +66,7 @@ /**

*/
getItem(key) {
CookieStorage.prototype.getItem = function getItem(key) {
return Cookies.get(key);
}
};

@@ -70,3 +78,5 @@ /**

*/
removeItem(key) {
CookieStorage.prototype.removeItem = function removeItem(key) {
return Cookies.remove(key, {

@@ -77,3 +87,3 @@ path: this.path,

});
}
};

@@ -84,5 +94,7 @@ /**

*/
clear() {
const cookies = Cookies.get();
let index;
CookieStorage.prototype.clear = function clear() {
var cookies = Cookies.get();
var index = void 0;
for (index = 0; index < cookies.length; ++index) {

@@ -92,3 +104,7 @@ Cookies.remove(cookies[index]);

return {};
}
}
};
return CookieStorage;
}();
export default CookieStorage;

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -17,39 +19,48 @@ * Amazon Cognito Auth SDK for JavaScript

*/
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
/** @class */
export default class DateHelper {
var DateHelper = function () {
function DateHelper() {
_classCallCheck(this, DateHelper);
}
/**
* @returns {string} The current time in "ddd MMM D HH:mm:ss UTC YYYY" format.
*/
getNowString() {
const now = new Date();
DateHelper.prototype.getNowString = function getNowString() {
var now = new Date();
const weekDay = weekNames[now.getUTCDay()];
const month = monthNames[now.getUTCMonth()];
const day = now.getUTCDate();
var weekDay = weekNames[now.getUTCDay()];
var month = monthNames[now.getUTCMonth()];
var day = now.getUTCDate();
let hours = now.getUTCHours();
var hours = now.getUTCHours();
if (hours < 10) {
hours = `0${hours}`;
hours = '0' + hours;
}
let minutes = now.getUTCMinutes();
var minutes = now.getUTCMinutes();
if (minutes < 10) {
minutes = `0${minutes}`;
minutes = '0' + minutes;
}
let seconds = now.getUTCSeconds();
var seconds = now.getUTCSeconds();
if (seconds < 10) {
seconds = `0${seconds}`;
seconds = '0' + seconds;
}
const year = now.getUTCFullYear();
var year = now.getUTCFullYear();
// ddd MMM D HH:mm:ss UTC YYYY
const dateNow = `${weekDay} ${month} ${day} ${hours}:${minutes}:${seconds} UTC ${year}`;
var dateNow = weekDay + ' ' + month + ' ' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' UTC ' + year;
return dateNow;
}
}
};
return DateHelper;
}();
export default DateHelper;

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

export const decode = str => global.atob(str);
export var decode = str => global.atob(str);
import { Buffer } from 'buffer';
export const decode = str => Buffer.from(str, 'base64').toString('utf8');
export var decode = str => Buffer.from(str, 'base64').toString('utf8');

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -17,7 +19,11 @@ * Amazon Cognito Auth SDK for JavaScript

*/
let dataMemory = {};
var dataMemory = {};
/** @class */
class MemoryStorage {
var MemoryStorage = function () {
function MemoryStorage() {
_classCallCheck(this, MemoryStorage);
}
/**

@@ -29,6 +35,6 @@ * This is used to set a specific item in storage

*/
static setItem(key, value) {
MemoryStorage.setItem = function setItem(key, value) {
dataMemory[key] = value;
return dataMemory[key];
}
};

@@ -41,5 +47,7 @@ /**

*/
static getItem(key) {
MemoryStorage.getItem = function getItem(key) {
return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined;
}
};

@@ -51,5 +59,7 @@ /**

*/
static removeItem(key) {
MemoryStorage.removeItem = function removeItem(key) {
return delete dataMemory[key];
}
};

@@ -60,11 +70,17 @@ /**

*/
static clear() {
MemoryStorage.clear = function clear() {
dataMemory = {};
return dataMemory;
}
}
};
return MemoryStorage;
}();
/** @class */
export default class StorageHelper {
var StorageHelper = function () {
/**

@@ -74,3 +90,5 @@ * This is used to get a storage object

*/
constructor() {
function StorageHelper() {
_classCallCheck(this, StorageHelper);
try {

@@ -89,5 +107,11 @@ this.storageWindow = window.localStorage;

*/
getStorage() {
StorageHelper.prototype.getStorage = function getStorage() {
return this.storageWindow;
}
}
};
return StorageHelper;
}();
export default StorageHelper;

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

const SELF = '_self';
var SELF = '_self';
export const launchUri = url => window.open(url, SELF);
export var launchUri = url => window.open(url, SELF);
import { Linking } from 'react-native';
export const launchUri = url => Linking.openURL(url);
export var launchUri = url => Linking.openURL(url);

@@ -1,22 +0,26 @@

/*!
* Amazon Cognito Auth SDK for JavaScript
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
'use strict';
* 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 { decode } from './DecodingHelper';
var _DecodingHelper = require('./DecodingHelper');
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 */
export default class CognitoAccessToken {
var CognitoAccessToken = function () {
/**

@@ -26,3 +30,5 @@ * Constructs a new CognitoAccessToken object

*/
constructor(AccessToken) {
function CognitoAccessToken(AccessToken) {
_classCallCheck(this, CognitoAccessToken);
// Assign object

@@ -36,5 +42,7 @@ this.jwtToken = AccessToken || '';

*/
getJwtToken() {
CognitoAccessToken.prototype.getJwtToken = function getJwtToken() {
return this.jwtToken;
}
};

@@ -46,5 +54,7 @@ /**

*/
setJwtToken(accessToken) {
CognitoAccessToken.prototype.setJwtToken = function setJwtToken(accessToken) {
this.jwtToken = accessToken;
}
};

@@ -54,9 +64,11 @@ /**

*/
getExpiration() {
CognitoAccessToken.prototype.getExpiration = function getExpiration() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).exp;
}
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse((0, _DecodingHelper.decode)(jwtPayload)).exp;
};

@@ -66,9 +78,11 @@ /**

*/
getUsername() {
CognitoAccessToken.prototype.getUsername = function getUsername() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).username;
}
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse((0, _DecodingHelper.decode)(jwtPayload)).username;
};

@@ -78,10 +92,16 @@ /**

*/
decodePayload() {
const jwtPayload = this.jwtToken.split('.')[1];
CognitoAccessToken.prototype.decodePayload = function decodePayload() {
var jwtPayload = this.jwtToken.split('.')[1];
try {
return JSON.parse(decode(jwtPayload));
return JSON.parse((0, _DecodingHelper.decode)(jwtPayload));
} catch (err) {
return {};
}
}
}
};
return CognitoAccessToken;
}();
exports.default = CognitoAccessToken;

@@ -1,28 +0,54 @@

/*!
* 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.
*/
'use strict';
import CognitoTokenScopes from './CognitoTokenScopes';
import CognitoAccessToken from './CognitoAccessToken';
import CognitoIdToken from './CognitoIdToken';
import CognitoRefreshToken from './CognitoRefreshToken';
import CognitoAuthSession from './CognitoAuthSession';
import StorageHelper from './StorageHelper';
import { launchUri } from './UriHelper';
exports.__esModule = true;
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);
var _UriHelper = require('./UriHelper');
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 */
export default class CognitoAuth {
var CognitoAuth = function () {
/**

@@ -49,6 +75,17 @@ * Constructs a new CognitoAuth object

*/
constructor(data) {
const { ClientId, AppWebDomain, TokenScopesArray,
RedirectUriSignIn, RedirectUriSignOut, IdentityProvider, UserPoolId,
AdvancedSecurityDataCollectionFlag, Storage, LaunchUri } = data || {};
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,
LaunchUri = _ref.LaunchUri;
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {

@@ -64,3 +101,3 @@ throw new Error(this.getCognitoConstants().PARAMETERERROR);

}
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
var tokenScopes = new _CognitoTokenScopes2.default(this.TokenScopesArray);
this.RedirectUriSignIn = RedirectUriSignIn;

@@ -70,3 +107,3 @@ this.RedirectUriSignOut = RedirectUriSignOut;

this.responseType = this.getCognitoConstants().TOKEN;
this.storage = Storage || new StorageHelper().getStorage();
this.storage = Storage || new _StorageHelper2.default().getStorage();
this.username = this.getLastUser();

@@ -76,3 +113,3 @@ this.userPoolId = UserPoolId;

this.signInUserSession.setTokenScopes(tokenScopes);
this.launchUri = typeof LaunchUri === 'function' ? LaunchUri : launchUri;
this.launchUri = typeof LaunchUri === 'function' ? LaunchUri : _UriHelper.launchUri;

@@ -91,4 +128,6 @@ /**

*/
getCognitoConstants() {
const CognitoConstants = {
CognitoAuth.prototype.getCognitoConstants = function getCognitoConstants() {
var CognitoConstants = {
DOMAIN_SCHEME: 'https',

@@ -137,3 +176,3 @@ DOMAIN_PATH_SIGNIN: 'oauth2/authorize',

return CognitoConstants;
}
};

@@ -143,5 +182,7 @@ /**

*/
getClientId() {
CognitoAuth.prototype.getClientId = function getClientId() {
return this.clientId;
}
};

@@ -151,5 +192,7 @@ /**

*/
getAppWebDomain() {
CognitoAuth.prototype.getAppWebDomain = function getAppWebDomain() {
return this.appWebDomain;
}
};

@@ -161,8 +204,10 @@ /**

*/
getCurrentUser() {
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`;
const lastAuthUser = this.storage.getItem(lastUserKey);
CognitoAuth.prototype.getCurrentUser = function getCurrentUser() {
var lastUserKey = 'CognitoIdentityServiceProvider.' + this.clientId + '.LastAuthUser';
var lastAuthUser = this.storage.getItem(lastUserKey);
return lastAuthUser;
}
};

@@ -174,5 +219,7 @@ /**

*/
setUser(Username) {
CognitoAuth.prototype.setUser = function setUser(Username) {
this.username = Username;
}
};

@@ -183,5 +230,7 @@ /**

*/
useCodeGrantFlow() {
CognitoAuth.prototype.useCodeGrantFlow = function useCodeGrantFlow() {
this.responseType = this.getCognitoConstants().CODE;
}
};

@@ -192,5 +241,7 @@ /**

*/
useImplicitFlow() {
CognitoAuth.prototype.useImplicitFlow = function useImplicitFlow() {
this.responseType = this.getCognitoConstants().TOKEN;
}
};

@@ -200,5 +251,7 @@ /**

*/
getSignInUserSession() {
CognitoAuth.prototype.getSignInUserSession = function getSignInUserSession() {
return this.signInUserSession;
}
};

@@ -208,5 +261,7 @@ /**

*/
getUsername() {
CognitoAuth.prototype.getUsername = function getUsername() {
return this.username;
}
};

@@ -217,5 +272,7 @@ /**

*/
setUsername(Username) {
CognitoAuth.prototype.setUsername = function setUsername(Username) {
this.username = Username;
}
};

@@ -225,5 +282,7 @@ /**

*/
getState() {
CognitoAuth.prototype.getState = function getState() {
return this.state;
}
};

@@ -234,5 +293,7 @@ /**

*/
setState(State) {
CognitoAuth.prototype.setState = function setState(State) {
this.state = State;
}
};

@@ -248,6 +309,8 @@ /**

*/
getSession() {
const tokenScopesInputSet = new Set(this.TokenScopesArray);
const cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes());
const URL = this.getFQDNSignIn();
CognitoAuth.prototype.getSession = function getSession() {
var tokenScopesInputSet = new Set(this.TokenScopesArray);
var cachedScopesSet = new Set(this.signInUserSession.tokenScopes.getScopes());
var URL = this.getFQDNSignIn();
if (this.signInUserSession != null && this.signInUserSession.isValid()) {

@@ -259,6 +322,6 @@ return this.userhandler.onSuccess(this.signInUserSession);

if (!this.compareSets(tokenScopesInputSet, cachedScopesSet)) {
const tokenScopes = new CognitoTokenScopes(this.TokenScopesArray);
const idToken = new CognitoIdToken();
const accessToken = new CognitoAccessToken();
const refreshToken = new CognitoRefreshToken();
var tokenScopes = new _CognitoTokenScopes2.default(this.TokenScopesArray);
var idToken = new _CognitoIdToken2.default();
var accessToken = new _CognitoAccessToken2.default();
var refreshToken = new _CognitoRefreshToken2.default();
this.signInUserSession.setTokenScopes(tokenScopes);

@@ -277,3 +340,3 @@ this.signInUserSession.setIdToken(idToken);

return undefined;
}
};

@@ -285,4 +348,6 @@ /**

*/
parseCognitoWebResponse(httpRequestResponse) {
let map;
CognitoAuth.prototype.parseCognitoWebResponse = function parseCognitoWebResponse(httpRequestResponse) {
var map = void 0;
if (httpRequestResponse.indexOf(this.getCognitoConstants().QUESTIONMARK) > -1) {

@@ -292,3 +357,3 @@ // for code type

// Sometimes the code will contain a poundsign in the end which breaks the parsing
const response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0];
var response = httpRequestResponse.split(this.getCognitoConstants().POUNDSIGN)[0];
map = this.getQueryParameters(response, this.getCognitoConstants().QUESTIONMARK);

@@ -308,3 +373,3 @@ if (map.has(this.getCognitoConstants().ERROR)) {

}
}
};

@@ -316,4 +381,6 @@ /**

*/
getCodeQueryParameter(map) {
const state = null;
CognitoAuth.prototype.getCodeQueryParameter = function getCodeQueryParameter(map) {
var state = null;
if (map.has(this.getCognitoConstants().STATE)) {

@@ -328,14 +395,14 @@ this.signInUserSession.setState(map.get(this.getCognitoConstants().STATE));

// To parse the response and get the code value.
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,
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,
client_id: this.getClientId(),
redirect_uri: this.RedirectUriSignIn,
code: codeParameter };
const boundOnSuccess = this.onSuccessExchangeForToken.bind(this);
const boundOnFailure = this.onFailure.bind(this);
var boundOnSuccess = this.onSuccessExchangeForToken.bind(this);
var boundOnFailure = this.onFailure.bind(this);
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure);
}
}
};

@@ -347,7 +414,9 @@ /**

*/
getTokenQueryParameter(map) {
const idToken = new CognitoIdToken();
const accessToken = new CognitoAccessToken();
const refreshToken = new CognitoRefreshToken();
const state = null;
CognitoAuth.prototype.getTokenQueryParameter = function getTokenQueryParameter(map) {
var idToken = new _CognitoIdToken2.default();
var accessToken = new _CognitoAccessToken2.default();
var refreshToken = new _CognitoRefreshToken2.default();
var state = null;
if (map.has(this.getCognitoConstants().IDTOKEN)) {

@@ -372,3 +441,3 @@ idToken.setJwtToken(map.get(this.getCognitoConstants().IDTOKEN));

this.userhandler.onSuccess(this.signInUserSession);
}
};

@@ -379,23 +448,25 @@ /**

*/
getCachedSession() {
CognitoAuth.prototype.getCachedSession = function getCachedSession() {
if (!this.username) {
return new CognitoAuthSession();
return new _CognitoAuthSession2.default();
}
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}.${this.username}`;
const idTokenKey = `${keyPrefix}.idToken`;
const accessTokenKey = `${keyPrefix}.accessToken`;
const refreshTokenKey = `${keyPrefix}.refreshToken`;
const scopeKey = `${keyPrefix}.tokenScopesString`;
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId() + '.' + this.username;
var idTokenKey = keyPrefix + '.idToken';
var accessTokenKey = keyPrefix + '.accessToken';
var refreshTokenKey = keyPrefix + '.refreshToken';
var scopeKey = keyPrefix + '.tokenScopesString';
const scopesString = this.storage.getItem(scopeKey);
let scopesArray = [];
var scopesString = this.storage.getItem(scopeKey);
var scopesArray = [];
if (scopesString) {
scopesArray = scopesString.split(' ');
}
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 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 sessionData = {
var sessionData = {
IdToken: idToken,

@@ -406,5 +477,5 @@ AccessToken: accessToken,

};
const cachedSession = new CognitoAuthSession(sessionData);
var cachedSession = new _CognitoAuthSession2.default(sessionData);
return cachedSession;
}
};

@@ -415,6 +486,8 @@ /**

*/
getLastUser() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`;
const lastUserKey = `${keyPrefix}.LastAuthUser`;
const lastUserName = this.storage.getItem(lastUserKey);
CognitoAuth.prototype.getLastUser = function getLastUser() {
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId();
var lastUserKey = keyPrefix + '.LastAuthUser';
var lastUserName = this.storage.getItem(lastUserKey);
if (lastUserName) {

@@ -424,3 +497,3 @@ return lastUserName;

return undefined;
}
};

@@ -432,13 +505,15 @@ /**

*/
cacheTokensScopes() {
const keyPrefix = `CognitoIdentityServiceProvider.${this.getClientId()}`;
const tokenUserName = this.signInUserSession.getAccessToken().getUsername();
CognitoAuth.prototype.cacheTokensScopes = function cacheTokensScopes() {
var keyPrefix = 'CognitoIdentityServiceProvider.' + this.getClientId();
var tokenUserName = this.signInUserSession.getAccessToken().getUsername();
this.username = tokenUserName;
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(' ');
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(' ');
this.storage.setItem(idTokenKey, this.signInUserSession.getIdToken().getJwtToken());

@@ -449,3 +524,3 @@ this.storage.setItem(accessTokenKey, this.signInUserSession.getAccessToken().getJwtToken());

this.storage.setItem(scopeKey, scopesString);
}
};

@@ -458,7 +533,22 @@ /**

*/
compareSets(set1, set2) {
CognitoAuth.prototype.compareSets = function compareSets(set1, set2) {
if (set1.size !== set2.size) {
return false;
}
for (const item of set1) {
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;
if (!set2.has(item)) {

@@ -469,3 +559,3 @@ return false;

return true;
}
};

@@ -477,9 +567,11 @@ /**

*/
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) {
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) {
return match[2];
}
return undefined;
}
};

@@ -492,9 +584,11 @@ /**

*/
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;
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;
for (i = 0; i < num; i++) {

@@ -505,3 +599,3 @@ str1[i] = String(str1[i]).split(this.getCognitoConstants().QUERYPARAMETERREGEX2);

return map;
}
};

@@ -514,9 +608,12 @@ /**

*/
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;
};
/**

@@ -526,10 +623,12 @@ * 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);

@@ -540,3 +639,3 @@ this.storage.removeItem(accessTokenKey);

this.storage.removeItem(scopeKey);
}
};

@@ -548,14 +647,16 @@ /**

*/
refreshSession(refreshToken) {
CognitoAuth.prototype.refreshSession = function refreshSession(refreshToken) {
// https POST call for refreshing token
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,
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,
client_id: this.getClientId(),
redirect_uri: this.RedirectUriSignIn,
refresh_token: refreshToken };
const boundOnSuccess = this.onSuccessRefreshToken.bind(this);
const boundOnFailure = this.onFailure.bind(this);
var boundOnSuccess = this.onSuccessRefreshToken.bind(this);
var boundOnFailure = this.onFailure.bind(this);
this.makePOSTRequest(header, body, url, boundOnSuccess, boundOnFailure);
}
};

@@ -571,6 +672,8 @@ /**

*/
makePOSTRequest(header, body, url, onSuccess, onFailure) {
CognitoAuth.prototype.makePOSTRequest = function makePOSTRequest(header, body, url, onSuccess, onFailure) {
// This is a sample server that supports CORS.
const xhr = this.createCORSRequest(this.getCognitoConstants().POST, url);
let bodyString = '';
var xhr = this.createCORSRequest(this.getCognitoConstants().POST, url);
var bodyString = '';
if (!xhr) {

@@ -580,7 +683,7 @@ return;

// set header
for (let key in header) {
for (var key in header) {
xhr.setRequestHeader(key, header[key]);
}
for (let key in body) {
bodyString = bodyString.concat(key, this.getCognitoConstants().EQUALSIGN, body[key], this.getCognitoConstants().AMPERSAND);
for (var _key in body) {
bodyString = bodyString.concat(_key, this.getCognitoConstants().EQUALSIGN, body[_key], this.getCognitoConstants().AMPERSAND);
}

@@ -598,3 +701,3 @@ bodyString = bodyString.substring(0, bodyString.length - 1);

};
}
};

@@ -607,8 +710,10 @@ /**

*/
createCORSRequest(method, url) {
let xhr = new XMLHttpRequest();
CognitoAuth.prototype.createCORSRequest = function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if (this.getCognitoConstants().WITHCREDENTIALS in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest !== this.getCognitoConstants().UNDEFINED) {
} else if ((typeof XDomainRequest === 'undefined' ? 'undefined' : _typeof(XDomainRequest)) !== this.getCognitoConstants().UNDEFINED) {
// XDomainRequest for IE.

@@ -622,3 +727,3 @@ xhr = new XDomainRequest();

return xhr;
}
};

@@ -630,5 +735,7 @@ /**

*/
onFailure(err) {
CognitoAuth.prototype.onFailure = function onFailure(err) {
this.userhandler.onFailure(err);
}
};

@@ -639,13 +746,15 @@ /**

*/
onSuccessRefreshToken(jsonData) {
const jsonDataObject = JSON.parse(jsonData);
CognitoAuth.prototype.onSuccessRefreshToken = function onSuccessRefreshToken(jsonData) {
var jsonDataObject = JSON.parse(jsonData);
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) {
const URL = this.getFQDNSignIn();
var URL = this.getFQDNSignIn();
this.launchUri(URL);
} else {
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().IDTOKEN)) {
this.signInUserSession.setIdToken(new CognitoIdToken(jsonDataObject.id_token));
this.signInUserSession.setIdToken(new _CognitoIdToken2.default(jsonDataObject.id_token));
}
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ACCESSTOKEN)) {
this.signInUserSession.setAccessToken(new CognitoAccessToken(jsonDataObject.access_token));
this.signInUserSession.setAccessToken(new _CognitoAccessToken2.default(jsonDataObject.access_token));
}

@@ -655,3 +764,3 @@ this.cacheTokensScopes();

}
}
};

@@ -662,8 +771,10 @@ /**

*/
onSuccessExchangeForToken(jsonData) {
const jsonDataObject = JSON.parse(jsonData);
const refreshToken = new CognitoRefreshToken();
const accessToken = new CognitoAccessToken();
const idToken = new CognitoIdToken();
const state = null;
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;
if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ERROR)) {

@@ -673,3 +784,3 @@ return this.userhandler.onFailure(jsonData);

if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().IDTOKEN)) {
this.signInUserSession.setIdToken(new CognitoIdToken(jsonDataObject.id_token));
this.signInUserSession.setIdToken(new _CognitoIdToken2.default(jsonDataObject.id_token));
} else {

@@ -679,3 +790,3 @@ this.signInUserSession.setIdToken(idToken);

if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().ACCESSTOKEN)) {
this.signInUserSession.setAccessToken(new CognitoAccessToken(jsonDataObject.access_token));
this.signInUserSession.setAccessToken(new _CognitoAccessToken2.default(jsonDataObject.access_token));
} else {

@@ -685,3 +796,3 @@ this.signInUserSession.setAccessToken(accessToken);

if (Object.prototype.hasOwnProperty.call(jsonDataObject, this.getCognitoConstants().REFRESHTOKEN)) {
this.signInUserSession.setRefreshToken(new CognitoRefreshToken(jsonDataObject.refresh_token));
this.signInUserSession.setRefreshToken(new _CognitoRefreshToken2.default(jsonDataObject.refresh_token));
} else {

@@ -692,3 +803,3 @@ this.signInUserSession.setRefreshToken(refreshToken);

this.userhandler.onSuccess(this.signInUserSession);
}
};

@@ -700,12 +811,16 @@ /**

*/
launchUri() {} // overwritten in constructor
CognitoAuth.prototype.launchUri = function launchUri() {};
// overwritten in constructor
/**
* @returns {string} scopes string
*/
getSpaceSeperatedScopeString() {
let tokenScopesString = this.signInUserSession.getTokenScopes().getScopes();
CognitoAuth.prototype.getSpaceSeperatedScopeString = function getSpaceSeperatedScopeString() {
var tokenScopesString = this.signInUserSession.getTokenScopes().getScopes();
tokenScopesString = tokenScopesString.join(this.getCognitoConstants().SPACE);
return encodeURIComponent(tokenScopesString);
}
};

@@ -716,3 +831,5 @@ /**

*/
getFQDNSignIn() {
CognitoAuth.prototype.getFQDNSignIn = function getFQDNSignIn() {
if (this.state == null) {

@@ -722,4 +839,4 @@ this.state = this.generateRandomString(this.getCognitoConstants().STATELENGTH, this.getCognitoConstants().STATEORIGINSTRING);

const identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : '';
const tokenScopesString = this.getSpaceSeperatedScopeString();
var identityProviderParam = this.IdentityProvider ? this.getCognitoConstants().AMPERSAND.concat(this.getCognitoConstants().DOMAIN_QUERY_PARAM_IDENTITY_PROVIDER, this.getCognitoConstants().EQUALSIGN, this.IdentityProvider) : '';
var tokenScopesString = this.getSpaceSeperatedScopeString();

@@ -733,6 +850,6 @@ var userContextDataParam = '';

// Build the complete web domain to launch the login screen
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);
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);
return uri;
}
};

@@ -743,8 +860,10 @@ /**

*/
signOut() {
const URL = this.getFQDNSignOut();
CognitoAuth.prototype.signOut = function signOut() {
var URL = this.getFQDNSignOut();
this.signInUserSession = null;
this.clearCachedTokensScopes();
this.launchUri(URL);
}
};

@@ -755,6 +874,8 @@ /**

*/
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());
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());
return uri;
}
};

@@ -767,3 +888,5 @@ /**

**/
getUserContextData() {
CognitoAuth.prototype.getUserContextData = function getUserContextData() {
if (typeof AmazonCognitoAdvancedSecurityData === "undefined") {

@@ -786,3 +909,3 @@ return;

}
}
};

@@ -794,5 +917,11 @@ /**

*/
isUserSignedIn() {
CognitoAuth.prototype.isUserSignedIn = function isUserSignedIn() {
return this.signInUserSession != null && this.signInUserSession.isValid() || this.getCachedSession() != null && this.getCachedSession().isValid();
}
}
};
return CognitoAuth;
}();
exports.default = CognitoAuth;

@@ -1,25 +0,42 @@

/*!
* Amazon Cognito Auth SDK for JavaScript
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
'use strict';
* 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';
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);
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 */
export default class CognitoAuthSession {
var CognitoAuthSession = function () {
/**

@@ -33,7 +50,16 @@ * Constructs a new CognitoUserSession object

*/
constructor({ IdToken, RefreshToken, AccessToken, TokenScopes, State } = {}) {
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);
if (IdToken) {
this.idToken = IdToken;
} else {
this.idToken = new CognitoIdToken();
this.idToken = new _CognitoIdToken2.default();
}

@@ -43,3 +69,3 @@ if (RefreshToken) {

} else {
this.refreshToken = new CognitoRefreshToken();
this.refreshToken = new _CognitoRefreshToken2.default();
}

@@ -49,3 +75,3 @@ if (AccessToken) {

} else {
this.accessToken = new CognitoAccessToken();
this.accessToken = new _CognitoAccessToken2.default();
}

@@ -55,3 +81,3 @@ if (TokenScopes) {

} else {
this.tokenScopes = new CognitoTokenScopes();
this.tokenScopes = new _CognitoTokenScopes2.default();
}

@@ -68,5 +94,7 @@ if (State) {

*/
getIdToken() {
CognitoAuthSession.prototype.getIdToken = function getIdToken() {
return this.idToken;
}
};

@@ -78,5 +106,7 @@ /**

*/
setIdToken(IdToken) {
CognitoAuthSession.prototype.setIdToken = function setIdToken(IdToken) {
this.idToken = IdToken;
}
};

@@ -86,5 +116,7 @@ /**

*/
getRefreshToken() {
CognitoAuthSession.prototype.getRefreshToken = function getRefreshToken() {
return this.refreshToken;
}
};

@@ -96,5 +128,7 @@ /**

*/
setRefreshToken(RefreshToken) {
CognitoAuthSession.prototype.setRefreshToken = function setRefreshToken(RefreshToken) {
this.refreshToken = RefreshToken;
}
};

@@ -104,5 +138,7 @@ /**

*/
getAccessToken() {
CognitoAuthSession.prototype.getAccessToken = function getAccessToken() {
return this.accessToken;
}
};

@@ -114,5 +150,7 @@ /**

*/
setAccessToken(AccessToken) {
CognitoAuthSession.prototype.setAccessToken = function setAccessToken(AccessToken) {
this.accessToken = AccessToken;
}
};

@@ -122,5 +160,7 @@ /**

*/
getTokenScopes() {
CognitoAuthSession.prototype.getTokenScopes = function getTokenScopes() {
return this.tokenScopes;
}
};

@@ -132,5 +172,7 @@ /**

*/
setTokenScopes(tokenScopes) {
CognitoAuthSession.prototype.setTokenScopes = function setTokenScopes(tokenScopes) {
this.tokenScopes = tokenScopes;
}
};

@@ -140,5 +182,7 @@ /**

*/
getState() {
CognitoAuthSession.prototype.getState = function getState() {
return this.state;
}
};

@@ -150,5 +194,7 @@ /**

*/
setState(State) {
CognitoAuthSession.prototype.setState = function setState(State) {
this.state = State;
}
};

@@ -160,4 +206,6 @@ /**

*/
isValid() {
const now = Math.floor(new Date() / 1000);
CognitoAuthSession.prototype.isValid = function isValid() {
var now = Math.floor(new Date() / 1000);
try {

@@ -174,3 +222,7 @@ if (this.accessToken != null) {

}
}
}
};
return CognitoAuthSession;
}();
exports.default = CognitoAuthSession;

@@ -1,21 +0,25 @@

/*!
* 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.
*/
'use strict';
import { decode } from './DecodingHelper';
exports.__esModule = true;
var _DecodingHelper = require('./DecodingHelper');
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 */
export default class CognitoIdToken {
var CognitoIdToken = function () {
/**

@@ -25,3 +29,5 @@ * Constructs a new CognitoIdToken object

*/
constructor(IdToken) {
function CognitoIdToken(IdToken) {
_classCallCheck(this, CognitoIdToken);
// Assign object

@@ -35,5 +41,7 @@ this.jwtToken = IdToken || '';

*/
getJwtToken() {
CognitoIdToken.prototype.getJwtToken = function getJwtToken() {
return this.jwtToken;
}
};

@@ -45,5 +53,7 @@ /**

*/
setJwtToken(idToken) {
CognitoIdToken.prototype.setJwtToken = function setJwtToken(idToken) {
this.jwtToken = idToken;
}
};

@@ -53,9 +63,11 @@ /**

*/
getExpiration() {
CognitoIdToken.prototype.getExpiration = function getExpiration() {
if (this.jwtToken === null) {
return undefined;
}
const jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse(decode(jwtPayload)).exp;
}
var jwtPayload = this.jwtToken.split('.')[1];
return JSON.parse((0, _DecodingHelper.decode)(jwtPayload)).exp;
};

@@ -65,10 +77,16 @@ /**

*/
decodePayload() {
const jwtPayload = this.jwtToken.split('.')[1];
CognitoIdToken.prototype.decodePayload = function decodePayload() {
var jwtPayload = this.jwtToken.split('.')[1];
try {
return JSON.parse(decode(jwtPayload));
return JSON.parse((0, _DecodingHelper.decode)(jwtPayload));
} catch (err) {
return {};
}
}
}
};
return CognitoIdToken;
}();
exports.default = CognitoIdToken;

@@ -0,1 +1,7 @@

'use strict';
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -19,3 +25,3 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoRefreshToken {
var CognitoRefreshToken = function () {
/**

@@ -25,3 +31,5 @@ * Constructs a new CognitoRefreshToken object

*/
constructor(RefreshToken) {
function CognitoRefreshToken(RefreshToken) {
_classCallCheck(this, CognitoRefreshToken);
// Assign object

@@ -34,5 +42,7 @@ this.refreshToken = RefreshToken || '';

*/
getToken() {
CognitoRefreshToken.prototype.getToken = function getToken() {
return this.refreshToken;
}
};

@@ -44,5 +54,11 @@ /**

*/
setToken(refreshToken) {
CognitoRefreshToken.prototype.setToken = function setToken(refreshToken) {
this.refreshToken = refreshToken;
}
}
};
return CognitoRefreshToken;
}();
exports.default = CognitoRefreshToken;

@@ -0,1 +1,7 @@

"use strict";
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -19,3 +25,3 @@ * Amazon Cognito Auth SDK for JavaScript

/** @class */
export default class CognitoTokenScopes {
var CognitoTokenScopes = function () {
/**

@@ -25,3 +31,5 @@ * Constructs a new CognitoTokenScopes object

*/
constructor(TokenScopesArray) {
function CognitoTokenScopes(TokenScopesArray) {
_classCallCheck(this, CognitoTokenScopes);
// Assign object

@@ -34,5 +42,7 @@ this.tokenScopes = TokenScopesArray || [];

*/
getScopes() {
CognitoTokenScopes.prototype.getScopes = function getScopes() {
return this.tokenScopes;
}
};

@@ -44,5 +54,11 @@ /**

*/
setTokenScopes(tokenScopes) {
CognitoTokenScopes.prototype.setTokenScopes = function setTokenScopes(tokenScopes) {
this.tokenScopes = tokenScopes;
}
}
};
return CognitoTokenScopes;
}();
exports.default = CognitoTokenScopes;

@@ -0,6 +1,15 @@

'use strict';
import * as Cookies from 'js-cookie';
exports.__esModule = true;
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 */
export default class CookieStorage {
var CookieStorage = function () {

@@ -15,3 +24,5 @@ /**

*/
constructor(data) {
function CookieStorage(data) {
_classCallCheck(this, CookieStorage);
this.domain = data.domain;

@@ -41,3 +52,5 @@ if (data.path) {

*/
setItem(key, value) {
CookieStorage.prototype.setItem = function setItem(key, value) {
Cookies.set(key, value, {

@@ -50,3 +63,3 @@ path: this.path,

return Cookies.get(key);
}
};

@@ -59,5 +72,7 @@ /**

*/
getItem(key) {
CookieStorage.prototype.getItem = function getItem(key) {
return Cookies.get(key);
}
};

@@ -69,3 +84,5 @@ /**

*/
removeItem(key) {
CookieStorage.prototype.removeItem = function removeItem(key) {
return Cookies.remove(key, {

@@ -76,3 +93,3 @@ path: this.path,

});
}
};

@@ -83,5 +100,7 @@ /**

*/
clear() {
const cookies = Cookies.get();
let index;
CookieStorage.prototype.clear = function clear() {
var cookies = Cookies.get();
var index = void 0;
for (index = 0; index < cookies.length; ++index) {

@@ -91,3 +110,7 @@ Cookies.remove(cookies[index]);

return {};
}
}
};
return CookieStorage;
}();
exports.default = CookieStorage;

@@ -0,1 +1,7 @@

'use strict';
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -17,39 +23,48 @@ * Amazon Cognito Auth SDK for JavaScript

*/
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var weekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
/** @class */
export default class DateHelper {
var DateHelper = function () {
function DateHelper() {
_classCallCheck(this, DateHelper);
}
/**
* @returns {string} The current time in "ddd MMM D HH:mm:ss UTC YYYY" format.
*/
getNowString() {
const now = new Date();
DateHelper.prototype.getNowString = function getNowString() {
var now = new Date();
const weekDay = weekNames[now.getUTCDay()];
const month = monthNames[now.getUTCMonth()];
const day = now.getUTCDate();
var weekDay = weekNames[now.getUTCDay()];
var month = monthNames[now.getUTCMonth()];
var day = now.getUTCDate();
let hours = now.getUTCHours();
var hours = now.getUTCHours();
if (hours < 10) {
hours = `0${hours}`;
hours = '0' + hours;
}
let minutes = now.getUTCMinutes();
var minutes = now.getUTCMinutes();
if (minutes < 10) {
minutes = `0${minutes}`;
minutes = '0' + minutes;
}
let seconds = now.getUTCSeconds();
var seconds = now.getUTCSeconds();
if (seconds < 10) {
seconds = `0${seconds}`;
seconds = '0' + seconds;
}
const year = now.getUTCFullYear();
var year = now.getUTCFullYear();
// ddd MMM D HH:mm:ss UTC YYYY
const dateNow = `${weekDay} ${month} ${day} ${hours}:${minutes}:${seconds} UTC ${year}`;
var dateNow = weekDay + ' ' + month + ' ' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' UTC ' + year;
return dateNow;
}
}
};
return DateHelper;
}();
exports.default = DateHelper;

@@ -1,1 +0,6 @@

export const decode = str => global.atob(str);
"use strict";
exports.__esModule = true;
var decode = exports.decode = function decode(str) {
return global.atob(str);
};

@@ -1,3 +0,10 @@

import { Buffer } from 'buffer';
'use strict';
export const decode = str => Buffer.from(str, 'base64').toString('utf8');
exports.__esModule = true;
exports.decode = undefined;
var _buffer = require('buffer');
var decode = exports.decode = function decode(str) {
return _buffer.Buffer.from(str, 'base64').toString('utf8');
};

@@ -1,26 +0,86 @@

/*!
* Amazon Cognito Auth SDK for JavaScript
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
'use strict';
* 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;
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';
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;
}
});
var _CookieStorage = require('./CookieStorage');
Object.defineProperty(exports, 'CookieStorage', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_CookieStorage).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -0,1 +1,7 @@

'use strict';
exports.__esModule = true;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!

@@ -17,7 +23,11 @@ * Amazon Cognito Auth SDK for JavaScript

*/
let dataMemory = {};
var dataMemory = {};
/** @class */
class MemoryStorage {
var MemoryStorage = function () {
function MemoryStorage() {
_classCallCheck(this, MemoryStorage);
}
/**

@@ -29,6 +39,6 @@ * This is used to set a specific item in storage

*/
static setItem(key, value) {
MemoryStorage.setItem = function setItem(key, value) {
dataMemory[key] = value;
return dataMemory[key];
}
};

@@ -41,5 +51,7 @@ /**

*/
static getItem(key) {
MemoryStorage.getItem = function getItem(key) {
return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined;
}
};

@@ -51,5 +63,7 @@ /**

*/
static removeItem(key) {
MemoryStorage.removeItem = function removeItem(key) {
return delete dataMemory[key];
}
};

@@ -60,11 +74,17 @@ /**

*/
static clear() {
MemoryStorage.clear = function clear() {
dataMemory = {};
return dataMemory;
}
}
};
return MemoryStorage;
}();
/** @class */
export default class StorageHelper {
var StorageHelper = function () {
/**

@@ -74,3 +94,5 @@ * This is used to get a storage object

*/
constructor() {
function StorageHelper() {
_classCallCheck(this, StorageHelper);
try {

@@ -89,5 +111,11 @@ this.storageWindow = window.localStorage;

*/
getStorage() {
StorageHelper.prototype.getStorage = function getStorage() {
return this.storageWindow;
}
}
};
return StorageHelper;
}();
exports.default = StorageHelper;

@@ -1,3 +0,8 @@

const SELF = '_self';
'use strict';
export const launchUri = url => window.open(url, SELF);
exports.__esModule = true;
var SELF = '_self';
var launchUri = exports.launchUri = function launchUri(url) {
return window.open(url, SELF);
};

@@ -1,3 +0,10 @@

import { Linking } from 'react-native';
'use strict';
export const launchUri = url => Linking.openURL(url);
exports.__esModule = true;
exports.launchUri = undefined;
var _reactNative = require('react-native');
var launchUri = exports.launchUri = function launchUri(url) {
return _reactNative.Linking.openURL(url);
};
{
"name": "amazon-cognito-auth-js",
"description": "Amazon Cognito Auth JavaScript SDK",
"version": "1.3.0",
"version": "1.3.1",
"author": {

@@ -6,0 +6,0 @@ "name": "Amazon Web Services",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc