black-bits / laravel-cognito-auth

MIT License
89 stars 51 forks source link

Support username attributes use phone_number #21

Closed eric0324 closed 4 years ago

eric0324 commented 5 years ago

My application use the phone number and e-mail as the login account at the same time.

How can I control which one is my username?

aprzywara commented 5 years ago

I'm not sure if you are talking about the username in your cognito user pool or in your local DB?

Here is how AWS handles it on their end:

To implement option 2 in your app

Call the CreateUserPool API to create your user pool. Set the UserNameAttributes parameter to phone_number, email, or phone_number | email.

Call the SignUp API and pass an email address or phone number in the username parameter of the API. This API does the following:

If the username string is in valid email format, the user pool automatically populates the email attribute of the user with the username value.

If the username string is in valid phone number format, the user pool automatically populates the phone_number attribute of the user with the username value.

If the username string format is not in email or phone number format, the SignUp API throws an exception.

The SignUp API generates a persistent UUID for your user, and uses it as the immutable username attribute internally. This UUID has the same value as the sub claim in the user identity token.

If the username string contains an email address or phone number that is already in use, the SignUp API throws an exception.

You can use an email address or phone number as an alias in place of the username in all APIs except the ListUsers API. When you call ListUsers, you can search by the email or phone_number attribute; if you search by username, you must supply the actual username, not an alias.

See these docs for more details: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases-settings-option-2

Does this answer your question?

aprzywara commented 4 years ago

Question seems to be answered.