【问题标题】:Angular 2 - Create user in a group AWS cognitoAngular 2 - 在组 AWS cognito 中创建用户
【发布时间】:2018-07-28 02:34:47
【问题描述】:

我正在将用户注册到用户池(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
      }
  });

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 非常感谢您的宝贵回答。我更新了问题和我的代码。响应为 "{"__type":"AccessDeniedException","Message":"User: arn:aws:sts:::assumed-role/unauthenticated_user/CognitoIdentityCredentials 无权执行:cognito-idp:AdminCreateUser on资源”
    • 您在哪里运行此代码,EC2 实例或 Lambda 或本地?如果它的前两个检查附加到它们的 IAM 角色,它是否在策略中包含必要的权限。如果是本地,请检查用户政策。
    • 在本地运行。请建议需要为 IAM 角色附加哪些政策。
    猜你喜欢
    • 2017-10-12
    • 1970-01-01
    • 2021-09-04
    • 2019-07-07
    • 2019-08-09
    • 2019-09-04
    • 2017-12-03
    • 2021-12-03
    • 2020-09-11
    相关资源
    最近更新 更多