Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const https = require("https");
const url = require("url");
const AWS = require('aws-sdk');
const cognitoidentity = new AWS.CognitoIdentity();
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
const SUCCESS = 'SUCCESS';
const FAILED = 'FAILED';
const UNKNOWN = {
Error: 'Unknown operation'
};
const requestTypes = [
'Create',
'Update',
'Delete'
];
// Some field are encoded as strings in CloudFormation, e.g. "true" and
// "false", so we need to convert them back to the proper type
function tr(val) {
switch (typeof val) {
case "string":
"use strict";
const aws = require('aws-sdk');
const config = require('../config');
const utils = require('../utils');
const common = {
UserPoolId: process.env.USER_POOL_ID
};
const _identity = new aws.CognitoIdentityServiceProvider(Object.assign({}, common));
const identity = new Proxy({}, {
get: (obj, prop) => utils.mkPromise(_identity[prop].bind(_identity))
});
module.exports = {
// userPool,
identity,
_identity,
common,
};
getUserPoolConfigInfo(function(err, poolinfo) {
if (err) {
console.log(err);
return cb({code: 502, message: "Failed to process forgot request."}, null);
}
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
let _password = generatedSecurePassword();
let params = {
ClientId: process.env.USER_POOL_CLIENT_ID,
Username: userId
};
cognitoidentityserviceprovider.forgotPassword(params, function(err, data) {
if (err) {
if (err.code === 'NotAuthorizedException') {
let params = {
UserPoolId: poolinfo,
Username: userId,
DesiredDeliveryMediums: ['EMAIL'],
MessageAction: 'RESEND',
TemporaryPassword: _password,
UserAttributes: []
};
"Description": "Imported from AD",
"LastModifiedDate": "",
"CreationDate": ""
});
}
return cb(null, _result);
}
});
} else {
let params = {
UserPoolId: process.env.USER_POOL_ID,
Username: userId
};
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(cognitoConfig);
cognitoidentityserviceprovider.adminListGroupsForUser(params, function(err, data) {
if (err) {
console.log(err);
return cb({code: 502, message: `Failed to list the groups that the user belongs to.`}, null);
}
return cb(null, data);
});
}
};
this._getUserPoolConfigInfo().then((poolinfo) => {
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
let params = {
UserPoolId: poolinfo,
Username: userId
};
cognitoidentityserviceprovider.adminDisableUser(params, function (err, data) {
if (err) {
Logger.error(Logger.levels.INFO, err.message);
Logger.error(Logger.levels.INFO, 'Error occurred while attempting to disable a user.');
throw err;
}
resolve(data);
});
}).catch((err) => {
public constructor(
protected session: Session,
cognito = new CognitoIdentityServiceProvider({
apiVersion: "2016-04-18"
})
) {
super(cognito)
}
exports.handler = async (event, context, callback) => {
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' });
const adminEmails = ["dabit3@gmail.com", "jennifer@gmail.com"]
if (adminEmails.indexOf(event.request.userAttributes.email) === -1) {
callback(null, event)
}
const groupParams = {
GroupName: process.env.GROUP,
UserPoolId: event.userPoolId,
};
const addUserParams = {
GroupName: process.env.GROUP,
UserPoolId: event.userPoolId,
Username: event.userName,
exports.handler = function(event, context) {
LOGGER.log('DEBUG',`REQUEST RECEIVED: ${JSON.stringify(event,null,2)}`);
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
const es = new AWS.ES();
let responseData = {};
if (event.RequestType == "Delete" || event.RequestType == "Update" ) {
sendResponse(event, context, "SUCCESS", responseData);
}
else if (event.RequestType == "Create") {
if (event.ResourceProperties.Resource === "UUID") {
responseData = {UUID: uuid.v4()};
sendResponse(event, context, "SUCCESS", responseData);
}
else {
let params = {
DomainName: event.ResourceProperties.Domain,
module.exports.destroy = function () {
if (userPoolId) {
const cognitoIdentityServiceProvider = new aws.CognitoIdentityServiceProvider({ region: awsRegion });
return cognitoIdentityServiceProvider.deleteUserPool({ UserPoolId: userPoolId }).promise();
}
};
}
//fake that auth succeeded to lambda's w/o principal id
let policy = new AuthPolicy("", awsAccountId, apiOptions);
policy.allowAllMethods();
context.succeed(policy.build());
return;
} else {
return cb("Unauthorized");
}
} else {
logger.info(JSON.stringify(payload));
//Valid token. Generate the API Gateway policy for the user
//Always generate the policy on value of 'sub' claim and not for 'username' because username is reassignable
//sub is UUID for a user which is never reassigned to another user.
const cognito = new AWS.CognitoIdentityServiceProvider({
apiVersion: '2016-04-19',
region: config.REGION
});
var params = {
AccessToken: token
};
cognito.getUser(params, (err, data) => {
if (err) {
logger.error(`cognito.getUser error: ${JSON.stringify(err)}`);
return cb("Unauthorized");
} else {
logger.info(`success with cognito.getUser: ${JSON.stringify(data)}`);
let emailAddress = _.find(data.UserAttributes, {
"Name": "email"