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

aws-amplify

Package Overview
Dependencies
Maintainers
8
Versions
2399
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-amplify - npm Package Compare versions

Comparing version 0.3.0 to 0.3.2

2

lib/Analytics/Analytics.js

@@ -92,3 +92,3 @@ "use strict";

var amplifyConfig = Common_1.Parser.parseMobilehubConfig(config);
var conf = Object.assign({}, this._config, amplifyConfig.Analytics);
var conf = Object.assign({}, this._config, amplifyConfig.Analytics, config);
var clientInfo = Common_1.ClientDevice.clientInfo();

@@ -95,0 +95,0 @@ conf['clientInfo'] = conf['client_info'] ? conf['client_info'] : clientInfo;

@@ -9,2 +9,3 @@ import { AuthOptions, FederatedResponse } from './types';

private userPool;
private _cognitoAuthClient;
private credentials;

@@ -11,0 +12,0 @@ private credentials_source;

@@ -55,2 +55,3 @@ "use strict";

var CognitoIdentityCredentials = Common_1.AWS.CognitoIdentityCredentials, Credentials = Common_1.AWS.Credentials;
var CognitoAuth = Common_1.CognitoHostedUI.CognitoAuth;
var CookieStorage = Common_1.Cognito.CookieStorage, CognitoUserPool = Common_1.Cognito.CognitoUserPool, CognitoUserAttribute = Common_1.Cognito.CognitoUserAttribute, CognitoUser = Common_1.Cognito.CognitoUser, AuthenticationDetails = Common_1.Cognito.AuthenticationDetails;

@@ -70,2 +71,3 @@ var dispatchAuthEvent = function (event, data) {

this.userPool = null;
this._cognitoAuthClient = null;
this.credentials = null;

@@ -89,18 +91,11 @@ this.credentials_source = ''; // aws, guest, userPool, federated

var _this = this;
if (!config)
return this._config;
logger.debug('configure Auth');
var conf = config ? config.Auth || config : {};
if (conf['aws_cognito_identity_pool_id']) {
conf = {
userPoolId: conf['aws_user_pools_id'],
userPoolWebClientId: conf['aws_user_pools_web_client_id'],
region: conf['aws_cognito_region'],
identityPoolId: conf['aws_cognito_identity_pool_id'],
mandatorySignIn: conf['aws_mandatory_sign_in'] === 'enable' ? true : false
};
}
this._config = Object.assign({}, this._config, conf);
var conf = Object.assign({}, this._config, Common_1.Parser.parseMobilehubConfig(config).Auth, config);
this._config = conf;
if (!this._config.identityPoolId) {
logger.debug('Do not have identityPoolId yet.');
}
var _a = this._config, userPoolId = _a.userPoolId, userPoolWebClientId = _a.userPoolWebClientId, cookieStorage = _a.cookieStorage;
var _a = this._config, userPoolId = _a.userPoolId, userPoolWebClientId = _a.userPoolWebClientId, cookieStorage = _a.cookieStorage, oauth = _a.oauth;
if (userPoolId) {

@@ -129,2 +124,41 @@ var userPoolData = {

}
// initiailize cognitoauth client if hosted ui options provided
if (oauth) {
var that_1 = this;
var cognitoAuthParams = Object.assign({
ClientId: userPoolWebClientId,
UserPoolId: userPoolId,
AppWebDomain: oauth.domain,
TokenScopesArray: oauth.scope,
RedirectUriSignIn: oauth.redirectSignIn,
RedirectUriSignOut: oauth.redirectSignOut,
ResponseType: oauth.responseType
}, oauth.options);
logger.debug('cognito auth params', cognitoAuthParams);
this._cognitoAuthClient = new CognitoAuth(cognitoAuthParams);
this._cognitoAuthClient.userhandler = {
// user signed in
onSuccess: function (result) {
that_1.user = that_1.userPool.getCurrentUser();
logger.debug("Cognito Hosted authentication result", result);
that_1.currentSession().then(function (session) {
that_1._setCredentialsFromSession(session).then(function (cred) {
logger.debug('sign in succefully with', cred);
dispatchAuthEvent('signIn', that_1.user);
});
});
},
onFailure: function (err) {
logger.debug("Error in cognito hosted auth response", err);
}
};
// if not logged in, try to parse the url.
this.currentAuthenticatedUser().then(function () {
logger.debug('user already logged in');
}).catch(function (e) {
logger.debug('not logged in, try to parse the url');
var curUrl = window.location.href;
_this._cognitoAuthClient.parseCognitoWebResponse(curUrl);
});
}
dispatchAuthEvent('configured', null);

@@ -257,2 +291,3 @@ return this._config;

AuthClass.prototype.signIn = function (username, password) {
var _this = this;
if (!this.userPool) {

@@ -275,13 +310,29 @@ return Promise.reject('No userPool');

user.authenticateUser(authDetails, {
onSuccess: function (session) {
logger.debug(session);
that._setCredentialsFromSession(session).then(function (cred) {
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
}).catch(function (e) {
logger.debug('cannot get cognito credentials');
reject('signin failed');
onSuccess: function (session) { return __awaiter(_this, void 0, void 0, function () {
var cred, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.debug(session);
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, that._setCredentialsFromSession(session)];
case 2:
cred = _a.sent();
logger.debug('succeed to get cognito credentials', cred);
return [3 /*break*/, 5];
case 3:
e_1 = _a.sent();
logger.debug('cannot get cognito credentials', e_1);
return [3 /*break*/, 5];
case 4:
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
}
});
},
}); },
onFailure: function (err) {

@@ -502,2 +553,3 @@ logger.debug('signIn failure', err);

AuthClass.prototype.confirmSignIn = function (user, code, mfaType) {
var _this = this;
if (!code) {

@@ -509,13 +561,29 @@ return Promise.reject('Code cannot be empty');

user.sendMFACode(code, {
onSuccess: function (session) {
logger.debug(session);
that._setCredentialsFromSession(session).then(function (cred) {
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
}).catch(function (e) {
logger.debug('cannot get cognito credentials');
reject('signin failed');
onSuccess: function (session) { return __awaiter(_this, void 0, void 0, function () {
var cred, e_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.debug(session);
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, that._setCredentialsFromSession(session)];
case 2:
cred = _a.sent();
logger.debug('succeed to get cognito credentials', cred);
return [3 /*break*/, 5];
case 3:
e_2 = _a.sent();
logger.debug('cannot get cognito credentials', e_2);
return [3 /*break*/, 5];
case 4:
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
}
});
},
}); },
onFailure: function (err) {

@@ -529,2 +597,3 @@ logger.debug('confirm signIn failure', err);

AuthClass.prototype.completeNewPassword = function (user, password, requiredAttributes) {
var _this = this;
if (!password) {

@@ -536,13 +605,29 @@ return Promise.reject('Password cannot be empty');

user.completeNewPasswordChallenge(password, requiredAttributes, {
onSuccess: function (session) {
logger.debug(session);
that._setCredentialsFromSession(session).then(function (cred) {
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
}).catch(function (e) {
logger.debug('cannot get cognito credentials');
reject('signin failed');
onSuccess: function (session) { return __awaiter(_this, void 0, void 0, function () {
var cred, e_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
logger.debug(session);
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
return [4 /*yield*/, that._setCredentialsFromSession(session)];
case 2:
cred = _a.sent();
logger.debug('succeed to get cognito credentials', cred);
return [3 /*break*/, 5];
case 3:
e_3 = _a.sent();
logger.debug('cannot get cognito credentials', e_3);
return [3 /*break*/, 5];
case 4:
that.user = user;
dispatchAuthEvent('signIn', user);
resolve(user);
return [7 /*endfinally*/];
case 5: return [2 /*return*/];
}
});
},
}); },
onFailure: function (err) {

@@ -707,6 +792,7 @@ logger.debug('completeNewPassword failure', err);

return __awaiter(this, void 0, void 0, function () {
var federatedUser, e_1, _a, e_2;
var federatedUser, e_4, _a, e_5;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
logger.debug('getting current authenticted user');
federatedUser = null;

@@ -721,3 +807,3 @@ _b.label = 1;

case 3:
e_1 = _b.sent();
e_4 = _b.sent();
logger.debug('cannot load federated user from cache');

@@ -741,3 +827,3 @@ return [3 /*break*/, 4];

case 8:
e_2 = _b.sent();
e_5 = _b.sent();
return [2 /*return*/, Promise.reject('not authenticated')];

@@ -756,3 +842,3 @@ case 9: return [2 /*return*/];

var that = this;
logger.debug('getting current session');
logger.debug('Getting current session');
if (!this.userPool) {

@@ -764,2 +850,3 @@ return Promise.reject('No userPool');

if (!user) {
logger.debug('Failed to get user from user pool');
return Promise.reject('No current user');

@@ -773,2 +860,3 @@ }

if (!user) {
logger.debug('Failed to get user from user pool');
return Promise.reject('No current user');

@@ -786,9 +874,27 @@ }

return new Promise(function (resolve, reject) {
logger.debug(user);
logger.debug('Getting the session from this user:', user);
user.getSession(function (err, session) {
if (err) {
logger.debug('Failed to get the session from user', user);
reject(err);
}
else {
resolve(session);
logger.debug('Succeed to get the user session', session);
// check if session is expired
if (!session.isValid()) {
var refreshToken = session.getRefreshToken();
logger.debug('Session is not valid, refreshing session with refreshToken', refreshToken);
user.refreshSession(refreshToken, function (err, newSession) {
if (err) {
logger.debug('Refresh Cognito Session failed', err);
reject(err);
}
logger.debug('Refresh Cognito Session success', newSession);
resolve(newSession);
});
}
else {
logger.debug('Session is valid, directly return this session');
resolve(session);
}
}

@@ -805,3 +911,3 @@ });

var that = this;
logger.debug('getting current user credential');
logger.debug('Getting current user credentials');
if (Platform_1.default.isReactNative) {

@@ -848,2 +954,3 @@ // asyncstorage

var _this = this;
logger.debug('Getting federated credentials');
var provider = federatedInfo.provider, user = federatedInfo.user;

@@ -882,2 +989,3 @@ var token = federatedInfo.token;

AuthClass.prototype.currentCredentials = function () {
logger.debug('getting current credntials');
return this.pickupCredentials();

@@ -939,3 +1047,3 @@ };

return __awaiter(this, void 0, void 0, function () {
var e_3, source, user, that;
var e_6, source, user, that;
return __generator(this, function (_a) {

@@ -950,3 +1058,3 @@ switch (_a.label) {

case 2:
e_3 = _a.sent();
e_6 = _a.sent();
logger.debug('failed to clear cached items');

@@ -961,6 +1069,10 @@ return [3 /*break*/, 3];

user = this.userPool.getCurrentUser();
if (user) {
logger.debug('user sign out', user);
user.signOut();
if (!user) {
return [2 /*return*/, Promise.resolve()];
}
logger.debug('user sign out', user);
user.signOut();
if (this._cognitoAuthClient) {
this._cognitoAuthClient.signOut();
}
}

@@ -1096,3 +1208,3 @@ that = this;

return __awaiter(this, void 0, void 0, function () {
var source, user, attributes, userAttrs, e_4, info, err_1, user;
var source, user, attributes, userAttrs, e_7, info, err_1, user;
return __generator(this, function (_a) {

@@ -1126,4 +1238,4 @@ switch (_a.label) {

case 6:
e_4 = _a.sent();
logger.debug('Failed to retrieve credentials while getting current user info', e_4);
e_7 = _a.sent();
logger.debug('Failed to retrieve credentials while getting current user info', e_7);
return [3 /*break*/, 7];

@@ -1161,4 +1273,2 @@ case 7:

var token = response.token, expires_at = response.expires_at;
// store it into localstorage
// Cache.setItem('federatedInfo', { provider, token, user, expires_at }, { priority: 1 });
var that = this;

@@ -1312,7 +1422,9 @@ return new Promise(function (res, rej) {

AuthClass.prototype.keepAlive = function () {
logger.debug('checking if credentials exists and not expired');
var cred = this.credentials;
if (cred && !this._isExpired(cred)) {
logger.debug('not changed, directly return credentials');
logger.debug('credentials not changed and not expired, directly return');
return Promise.resolve(cred);
}
logger.debug('need to get a new credential or refresh the existing one');
return this.currentUserCredentials();

@@ -1319,0 +1431,0 @@ };

@@ -20,2 +20,3 @@ import { ICookieStorageData } from "amazon-cognito-identity-js";

cookieStorage?: ICookieStorageData;
oauth?: OAuth;
}

@@ -36,1 +37,9 @@ /**

}
export interface OAuth {
domain: string;
scope: Array<string>;
redirectSignIn: string;
redirectSignOut: string;
responseType: string;
options?: object;
}

@@ -6,2 +6,3 @@ import * as S3 from 'aws-sdk/clients/s3';

import * as MobileAnalytics from 'aws-sdk/clients/mobileanalytics';
export { AWS, S3, Cognito, Pinpoint, MobileAnalytics };
import * as CognitoHostedUI from 'amazon-cognito-auth-js';
export { AWS, S3, Cognito, Pinpoint, MobileAnalytics, CognitoHostedUI };

@@ -26,2 +26,4 @@ "use strict";

exports.MobileAnalytics = MobileAnalytics;
var CognitoHostedUI = require("amazon-cognito-auth-js");
exports.CognitoHostedUI = CognitoHostedUI;
//# sourceMappingURL=Facet.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Common_1 = require("../Common");
var logger = new Common_1.ConsoleLogger('Parser');
var Parser = /** @class */ (function () {

@@ -10,8 +12,22 @@ function Parser() {

if (config['aws_mobile_analytics_app_id']) {
var Analytics = {};
Analytics['appId'] = config['aws_mobile_analytics_app_id'];
Analytics['region'] = config['aws_mobile_analytics_app_region'];
var Analytics = {
appId: config['aws_mobile_analytics_app_id'],
region: config['aws_mobile_analytics_app_region']
};
amplifyConfig.Analytics = Analytics;
}
// Auth
if (config['aws_cognito_identity_pool_id']) {
var Auth = {
userPoolId: config['aws_user_pools_id'],
userPoolWebClientId: config['aws_user_pools_web_client_id'],
region: config['aws_cognito_region'],
identityPoolId: config['aws_cognito_identity_pool_id'],
mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable' ? true : false
};
amplifyConfig.Auth = Auth;
}
amplifyConfig.Analytics = Object.assign({}, amplifyConfig.Analytics, config.Analytics);
amplifyConfig.Auth = Object.assign({}, amplifyConfig.Auth, config.Auth);
logger.debug('parse config', config, 'to amplifyconfig', amplifyConfig);
return amplifyConfig;

@@ -18,0 +34,0 @@ };

@@ -337,9 +337,13 @@ "use strict";

var credentials = options.credentials, level = options.level;
var customPrefix = options.customPrefix || {};
var privatePath = (customPrefix.private || 'private/') + credentials.identityId + '/';
var protectedPath = (customPrefix.protected || 'protected/') + credentials.identityId + '/';
var publicPath = customPrefix.public || 'public/';
switch (level) {
case 'private':
return "private/" + credentials.identityId + "/";
return privatePath;
case 'protected':
return "protected/" + credentials.identityId + "/";
return protectedPath;
default:
return 'public/';
return publicPath;
}

@@ -346,0 +350,0 @@ };

{
"name": "aws-amplify",
"version": "0.3.0",
"version": "0.3.2",
"description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.",

@@ -36,4 +36,2 @@ "main": "./lib/index.js",

"@types/node": "^8.0.24",
"@types/paho-mqtt": "^1.0.3",
"@types/zen-observable": "^0.5.3",
"awesome-typescript-loader": "^3.2.2",

@@ -62,2 +60,5 @@ "babel-loader": "^7.1.2",

"dependencies": {
"@types/paho-mqtt": "^1.0.3",
"@types/zen-observable": "^0.5.3",
"amazon-cognito-auth-js": "^1.1.9",
"amazon-cognito-identity-js": "^2.0.0",

@@ -64,0 +65,0 @@ "aws-sdk": "2.198.0",

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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