1

I am using AWS cognito API to create User in pool. User is being created successfully in Pool. Following is the code for that . But this code create user with FORCE_CHANGE_PASSWORD state but I want to create user in UNCONFIRMED state. Can someone help me on this?

AdminCreateUserRequest cognitoRequest =
        new AdminCreateUserRequest().withUserPoolId(id)
                .withUsername(r.getEmail())
                .withTemporaryPassword(r.getPassword().trim())
                .withUserAttributes(new AttributeType().withName(Constants.EMAIL).withValue(r.getEmail().trim()))
                .withUserAttributes(new AttributeType().withName(Constants.EMAI_VERIFIED).withValue("false"))
                .withUserAttributes(new AttributeType().withName(Constants.GIVEN_NAME).withValue(r.getFirstName().trim()))
                .withUserAttributes(new AttributeType().withName(Constants.FAMILY_NAME).withValue(r.getLastName().trim()));
keepmoving
  • 1,813
  • 8
  • 34
  • 74
  • Does this answer your question? [How to change User Status FORCE\_CHANGE\_PASSWORD?](https://stackoverflow.com/questions/40287012/how-to-change-user-status-force-change-password) – D Malan Apr 19 '20 at 18:07
  • I think you might have to call `adminSetUserPassword` with the permanent flag (as in [this answer](https://stackoverflow.com/a/56948249/3486675), but there are some other solutions in the linked question above too. The `adminCreateUser` [docs](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminCreateUser.html) say "In either case, the user will be in the FORCE_CHANGE_PASSWORD state until they sign in and change their password," so I don't think it would be possible to do this all with only one API call. – D Malan Apr 19 '20 at 18:09
  • is it true, boto3.client('cognito-idp') works different , because when I am using this py script then it creating user in UNCONFIRMED and I am expecting same behavior with java api. – keepmoving Apr 19 '20 at 18:46
  • Sounds like it, but you can check in the source code. – D Malan Apr 19 '20 at 18:48
  • I think AWS is not bias in terms of technology, it feature that AWS support for all tech clients. – keepmoving Apr 19 '20 at 19:07

1 Answers1

1

You can use SignUpRequest to create user with unconfirmed status

SignUpRequest request = new SignUpRequest().withClientId(clientId)
                .withUsername(userSignUpRequest.getUsername()).withPassword(userSignUpRequest.getPassword())
                .withUserAttributes(emailAttr, groupAttr);
        return cognitoClient.signUp(request)

After signup, user will get code on the email mentioned during signup.You can confirm user signup using different request taking code from user as input.

chetan mahajan
  • 723
  • 7
  • 9