2

我在 Cognito 中创建了一个用户池作为 'Only allow administrators to create users' 。现在我希望从我的反应应用程序中添加用户,但我无法理解调用哪些 API 来添加用户并第一次强制更改密码。

此外,AWS Amplify 是否为我们提供了在以管理员身份创建用户时使用的任何 API。

4

1 回答 1

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);
    }
});
于 2019-02-22T06:36:20.057 回答