Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cognito - signup request doesn't use the given username but a UUID

Not sure what is missing, but when I use the signup request, a user is created in my cognito user pool with a UUID user name (actually the sub attribute value) and not the email.

val signup = new SignUpRequest()
  .withUsername(user.email)  // <- cognito ignore this, and use a UUID for username
  .withClientId(clientId)
  .withSecretHash(secret)
  .withPassword(user.password)
  .withUserAttributes(List(email, givenName, familyName))

Looking in the documentation a UUID is used when the value of the email is not valid.

The email I use looks similar to this: [email protected] (which is a valid email)

BTW, when I use the AdminCreateUserRequest api, it get created with the email as the username as expected.

val createUser =
  new AdminCreateUserRequest()
    .withUsername(user.email)
    .withUserPoolId(cognitoUserPoolId)
    .withUserAttributes(attributes)

client.adminCreateUser(createUser)

Edit: Now with snapshots:

This is using the signup api - image

And this is using the create user api:

image

Only the sign up doesn't work, What did I miss?

like image 788
Tomer Avatar asked Jul 23 '17 14:07

Tomer


People also ask

Is username unique in Cognito?

The username must be unique within a user pool. A username can be reused, but only after it has been deleted and is no longer in use. If your application does not require a username, you do not need to ask users to provide one. Your app can create a unique username for users in the background.

When calling the signup operation username Cannot be of email format since user pool is configured for email alias?

By that error message, it looks like it's failing because you have email as an alias but have also set given it as your username. I think to get around this, you could either use some temporary, throw away username at first or un-check it as an alias and just use it as both username and an attribute.

Can Cognito username be changed?

The user name is a fixed value that users can't change. If you mark an attribute as an alias, users can sign in with that attribute in place of the user name. You can mark the email address, phone number, and preferred username attributes as aliases.

How do I authenticate a Cognito user?

AWS Cognito User Pool will send verification code by email or sms and the user enters the code to get verified with the User Pool. User enters username and password and logs in with Cognito User Pool in which case a token will be provided by Cognito upon successful login.


1 Answers

You should look at this: http://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases-settings-option-2

If you are using option 2, with the SignUp call, the username is replaced with a sub.

like image 182
Ionut Trestian Avatar answered Sep 24 '22 18:09

Ionut Trestian