【发布时间】: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