我已经在Cognito中创建了一个用户池,称为“仅允许管理员创建用户”。现在,我希望从我的react应用程序中添加用户,但是我不了解要调用哪个API来添加用户并首次强制更改密码。
此外,AWS Amplify是否向我们提供了在创建用户作为管理员时使用的任何API。
答案 0 :(得分:0)
使用AdminCreateUser API创建用户。 AWS amplify具有以下演示代码,用于对需要更改密码的管理员创建的用户进行身份验证:
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
// User authentication was successful
},
onFailure: function(err) {
// User authentication was not successful
},
mfaRequired: function(codeDeliveryDetails) {
// MFA is required to complete user authentication.
// Get the code from user and call
cognitoUser.sendMFACode(mfaCode, this)
},
newPasswordRequired: function(userAttributes, requiredAttributes) {
// User was signed up by an admin and must provide new
// password and required attributes, if any, to complete
// authentication.
// the api doesn't accept this field back
delete userAttributes.email_verified;
// Get these details and call
cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this);
}
});