Angular 2 - 在AWS cognito组中创建用户

时间:2018-02-17 08:24:37

标签: angular amazon-web-services amazon-cognito

我正在将用户注册到userpool(AWS Congito)。如何创建分配给组的用户。我使用以下代码创建用户,我想创建并将其分配给组。

    this.userPool = new AWSCognito.CognitoUserPool(this.poolData);
    this.attribute = {
        Name: 'email',
        Value: this.email
    };

    this.attributeEmail = new AWSCognito.CognitoUserAttribute(this.attribute);
    this.attributeList = [];
    this.attributeList.push(this.attributeEmail);

    this.userPool.signUp(this.username, this.password, this.attributeList, null, function(err, result) {
        if (err) {
            console.log(err);
            return;
        }
    });

我导入了AWS并连接到Cognito Admin SDK。被叫用户创建方法:

更新了代码

  AWS.config.region = '<region>;
  AWS.config.credentials = new AWS.CognitoIdentityCredentials({
      IdentityPoolId: '<identity_poll_id>'
  });
  this.params = {
      UserPoolId: '<user_poll_id>',
      /* required */
      Username: this.username,
      /* required */
      DesiredDeliveryMediums: [
          'SMS'
      ],
      ForceAliasCreation: true,
      MessageAction: 'RESEND',
      TemporaryPassword: this.password,
      UserAttributes: [{
              Name: 'email',
              /* required */
              Value: this.email
          },
          /* more items */
      ],
      ValidationData: [{
              Name: 'email',
              /* required */
              Value: this.email
          },
          /* more items */
      ]
  };
  this.cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
  this.cognitoidentityserviceprovider.adminCreateUser(this.params, function(err, data) {
      if (err) {
          console.log(err, err.stack); // an error occurred
      } else {
          console.log(data); // successful response
      }
  });

1 个答案:

答案 0 :(得分:0)

您需要使用Cognito Admin SDK方法创建用户并添加到组中。