- Newest
- Most votes
- Most comments
Hi,
Like you said the adminAddUserToGroup API call only accepts GroupName, Username, UserPoolId as parameters, which assumes that the group, the user, and user pool are already created, and of course this call is used to add a user to a specific group. This API call can be made by an AWS Lambda function that can be triggered when the user is created (post-confirmation trigger), and then user can be added to the specific group belonging to the specified user pool. In order to create a user, you can use this call: AdminCreateUser which is as follows:
cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
This call takes the following required parameters and other parameters:
UserPoolId: 'STRING_VALUE', /* required */
Username: 'STRING_VALUE', /* required */
You can find more information here.
In terms of validation, cognito will manage that. The user will be in the FORCE_CHANGE_PASSWORD state until they sign in and change their password.
Bear in mind that AdminCreateUser requires developer credentials.
answered 4 years ago
You cannot do this in a single call as your post suggests. Assuming your User Pool is set up, adding a user to a group is a two-step process:
- Create the user (either via
signUpAPI call oradminCreateUsercall) - Assign the user to a group via
adminAddUserToGroup(this assumes the group is already created and you know theGroupName)
The Username is the same value that gets returned in the Username field of a call like listUsers. It is also a required input parameter to both signUp and adminCreateUser.
As far as validating the invitation with the verification link -- Cognito will take care of this for you when users sign up. It will immediately sign up/create the user but the user will not be able to log in until they confirm their account via the link emailed to them. You can view the documentation for Signing up and confirming user accounts for more information.
Relevant content
asked 4 years ago
