3

When I update the cognito users' email attribute via the updateAttribute or adminUpdateAttribute API, email_verified will be set to false. So I'd like to set email_verified to true programitically.

My understanding is that it should use GetUserAttributeVerificationCode and VerifyUserAttribute API to set email_verified to true, but I don't want users to enter verification code. https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_GetUserAttributeVerificationCode.html https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_VerifyUserAttribute.html

As far as I see below, it seems impossible.
https://forums.aws.amazon.com/thread.jspa?messageID=782609

questionasker
  • 2,536
  • 12
  • 55
  • 119
R.yama
  • 41
  • 1
  • 5

4 Answers4

1

Yes, it's possible using UpdateUserAttributes. Per the docs:

In your call to AdminCreateUser, you can set the email_verified attribute to True, and you can set the phone_number_verified attribute to True. (You can also do this by calling AdminUpdateUserAttributes.)

  • email: The email address of the user to whom the message that contains the code and username will be sent. Required if the email_verified attribute is set to True, or if "EMAIL" is specified in the DesiredDeliveryMediums parameter.
ffxsam
  • 26,428
  • 32
  • 94
  • 144
1

In addition to the answer of @ffxsam, here is the working code:

CognitoIdentityProviderClient client = CognitoIdentityProviderClient.builder().build();

client.adminUpdateUserAttributes(AdminUpdateUserAttributesRequest.builder()
    .userPoolId(getUserPoolId())
    .username(username)
    .userAttributes(AttributeType.builder()
        .name("email")
        .value(updatedInfo.getEmail())
        .build(),
        AttributeType.builder()
        .name("email_verified")
        .value("True")
        .build())
    .build());
Hannes Schneidermayer
  • 4,729
  • 2
  • 28
  • 32
0

Using UpdateUserAttributes API, it is possible.

R.yama
  • 41
  • 1
  • 5
0

Use the AWS CLI to update a Cognito User's "email_verified" attribute to true:

aws cognito-idp admin-update-user-attributes --user-pool-id ENTER_POOL_ID --username ENTER_USERNAME --user-attributes '[{"Name": "email_verified", "Value": "true"}]'

Resource: AWS Forum

Mike Dubs
  • 609
  • 8
  • 11