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

@adastradev/user-management-sdk

Package Overview
Dependencies
Maintainers
27
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adastradev/user-management-sdk - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1-beta.1601664922669

2

dist/AuthManager.d.ts

@@ -16,3 +16,3 @@ import { ICognitoUserPoolLocator } from './ICognitoUserPoolLocator';

constructor(locator: ICognitoUserPoolLocator, region: string);
signIn: (email: string, password: string, newPassword?: string) => Promise<CognitoUserSession>;
signIn(email: string, password: string, newPassword?: string): Promise<CognitoUserSession>;
getAndSetEnvironmentCredentials(): Promise<any>;

@@ -19,0 +19,0 @@ getCognitoCredentials(): Promise<any>;

@@ -61,92 +61,2 @@ "use strict";

function AuthManager(locator, region) {
var _this = this;
this.signIn = function (email, password, newPassword) {
if (newPassword === void 0) { newPassword = ''; }
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var _a, error_1, userPool, authenticationData, userData, authenticationDetails, that;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
// get the pool data from the response
console.log("Signing into AWS Cognito");
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
_a = this;
return [4 /*yield*/, this.locator.getPoolForUsername(email)];
case 2:
_a.poolData = _b.sent();
this.authenticatorURI = "cognito-idp." + this.region + ".amazonaws.com/" + this.poolData.UserPoolId;
return [3 /*break*/, 4];
case 3:
error_1 = _b.sent();
return [2 /*return*/, reject(error_1)];
case 4:
userPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.poolData);
authenticationData = {
Password: password,
Username: email.toLowerCase()
};
userData = {
Pool: userPool,
Username: email.toLowerCase()
};
authenticationDetails = new amazon_cognito_identity_js_1.AuthenticationDetails(authenticationData);
// authenticate user to in Cognito user pool
this.cognitoUser = new amazon_cognito_identity_js_1.CognitoUser(userData);
that = this;
this.cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
that.cognitoUserSession = result;
return resolve(result);
},
onFailure: function (err) {
return reject(err);
},
mfaRequired: function (codeDeliveryDetails) {
return reject(Error('Multi-factor auth is not currently supported'));
},
newPasswordRequired: function (userAttributes, requiredAttributes) {
if (newPassword) {
// User was signed up by an admin and must provide new
// password and required attributes
// These attributes are not mutable and should be removed from map.
delete userAttributes.email_verified;
delete userAttributes['custom:tenant_id'];
that.cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, {
onFailure: function (err) {
return reject(err);
},
onSuccess: function (result) {
that.cognitoUserSession = result;
return resolve(result);
}
});
}
else {
return reject(Error('New password is required for the user'));
}
}
});
return [2 /*return*/];
}
});
}); });
};
this.buildCognitoIdentityCredentials = function (tokens) {
var _a;
return new global_1.CognitoIdentityCredentials({
IdentityPoolId: _this.poolData.IdentityPoolId,
Logins: (_a = {},
_a[_this.authenticatorURI] = tokens.idToken.getJwtToken(),
_a)
});
};
this.getTokens = function (session) {
return {
accessToken: session.getAccessToken(),
idToken: session.getIdToken(),
refreshToken: session.getRefreshToken()
};
};
this.locator = locator;

@@ -159,2 +69,76 @@ this.region = region;

}
AuthManager.prototype.signIn = function (email, password, newPassword) {
var _this = this;
if (newPassword === void 0) { newPassword = ''; }
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
var _a, error_1, userPool, authenticationData, userData, authenticationDetails, that;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
// get the pool data from the response
console.log("Signing into AWS Cognito");
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
_a = this;
return [4 /*yield*/, this.locator.getPoolForUsername(email)];
case 2:
_a.poolData = _b.sent();
this.authenticatorURI = "cognito-idp." + this.region + ".amazonaws.com/" + this.poolData.UserPoolId;
return [3 /*break*/, 4];
case 3:
error_1 = _b.sent();
return [2 /*return*/, reject(error_1)];
case 4:
userPool = new amazon_cognito_identity_js_1.CognitoUserPool(this.poolData);
authenticationData = {
Password: password,
Username: email.toLowerCase()
};
userData = {
Pool: userPool,
Username: email.toLowerCase()
};
authenticationDetails = new amazon_cognito_identity_js_1.AuthenticationDetails(authenticationData);
// authenticate user to in Cognito user pool
this.cognitoUser = new amazon_cognito_identity_js_1.CognitoUser(userData);
that = this;
this.cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
that.cognitoUserSession = result;
return resolve(result);
},
onFailure: function (err) {
return reject(err);
},
mfaRequired: function (codeDeliveryDetails) {
return reject(Error('Multi-factor auth is not currently supported'));
},
newPasswordRequired: function (userAttributes, requiredAttributes) {
if (newPassword) {
// User was signed up by an admin and must provide new
// password and required attributes
// These attributes are not mutable and should be removed from map.
delete userAttributes.email_verified;
delete userAttributes['custom:tenant_id'];
that.cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, {
onFailure: function (err) {
return reject(err);
},
onSuccess: function (result) {
that.cognitoUserSession = result;
return resolve(result);
}
});
}
else {
return reject(Error('New password is required for the user'));
}
}
});
return [2 /*return*/];
}
});
}); });
};
AuthManager.prototype.getAndSetEnvironmentCredentials = function () {

@@ -205,2 +189,18 @@ return __awaiter(this, void 0, void 0, function () {

};
AuthManager.prototype.buildCognitoIdentityCredentials = function (tokens) {
var _a;
return new global_1.CognitoIdentityCredentials({
IdentityPoolId: this.poolData.IdentityPoolId,
Logins: (_a = {},
_a[this.authenticatorURI] = tokens.idToken.getJwtToken(),
_a)
});
};
AuthManager.prototype.getTokens = function (session) {
return {
accessToken: session.getAccessToken(),
idToken: session.getIdToken(),
refreshToken: session.getRefreshToken()
};
};
return AuthManager;

@@ -207,0 +207,0 @@ }());

{
"name": "@adastradev/user-management-sdk",
"version": "2.4.0",
"version": "2.4.1-beta.1601664922669",
"description": "Astra user management SDK for JavaScript in the browser and Node.js",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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