in source/aws-connect-vm-serverless/src/service/cognito.service.js [48:84]
adminCreateUser(email, firstName, lastName, roles, removeExisting=false, temporaryPassword=null) {
let params = {
UserPoolId: this.userPoolId,
Username: email,
DesiredDeliveryMediums: ["EMAIL"],
ForceAliasCreation: false,
UserAttributes: [
{ Name: 'given_name', Value: firstName },
{ Name: 'family_name', Value: lastName},
{ Name: 'email', Value: email },
{ Name: 'email_verified', Value: "true" },
]
};
if (temporaryPassword) {
params["TemporaryPassword"] = temporaryPassword;
}
return this.getCognitoUser(email)
.then(result => {
let actions;
if (result && removeExisting) {
actions = this.adminDeleteUser(email)
.then(() => this.identityServiceProvider.adminCreateUser(params).promise());
} else {
actions = this.identityServiceProvider.adminCreateUser(params).promise()
}
return actions
.then(() => Promise.all(
roles.split(",").map(role => this.identityServiceProvider.adminAddUserToGroup({
GroupName: role,
UserPoolId: this.userPoolId,
Username: email
}).promise())));
});
}