Should I use AWS Cognito "username" or "sub" (uid) to store in the database?

I have an authenticated user in the AWS Cognito service and you want to store its unique identifier in the database. Should I store the user's username (his phone number) or his "sub" (this is his uid)? All Amazon API functions, such as AdminGetUser , use the "username" parameter, but not sub / uid.

But I also read that article , and the author said: "Always generate a policy by the value of" sub "and not" username "because the username is redefined. Sub is the UUID for a user who is never reassigned to another user."

So, now I doubt that I should use as the unique identifier of the user - "username" or "under"

Thank.

+4
source share
3 answers

You must use the attribute sub. In fact, if a user with a username Ericodeletes his account, the new user may use the same username later, and the mapping will be incorrect ...

The username is always required to register the user and cannot be changed after the user is created.

However

The username must be unique within the user pool. The username can be reused, but only after it is deleted and is no longer used.

Update

sub as ID username as. username AdminGetUser.

username , , , " ", username .

+3

, , , , .

, API-, , / .

0

( ) Cognito , sub , cognito , - , aws , username uuid prefered_username .

javascript AWS.CognitoIdentityServiceProvider.ListUser, .

0

Source: https://habr.com/ru/post/1652972/


All Articles