Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search amazon cognito users by custom attribute

I'm developing a react native app which uses aws-amplify to interact with amazon cognito. In my use case, I need to ensure value of a custom attribute is unique across all accounts. aws-amplify does not seem to have an API which allows me to search across all accounts by a custom attribute. How can I do this?

like image 301
wseubr Avatar asked Nov 14 '18 04:11

wseubr


People also ask

How do I change the attributes of an Amazon Cognito user pool after creation?

Short description. You can't change standard user pool attributes after a user pool is created. Instead, create a new user pool with the attributes that you want to require for user registration. Then, migrate existing users to the new user pool by using an AWS Lambda function as a user migration trigger.

How do I change user attributes in Cognito?

To update a cognito user's attributes use the admin-update-user-attributes command, specifying the user-pool-id , username and user-attributes parameters.

Are custom attributes searchable in Amazon Cognito?

status (called Enabled in the Console) (case-sensitive) Custom attributes are not searchable. For more information, see Searching for Users Using the ListUsers API and Examples of Using the ListUsers API in the Amazon Cognito Developer Guide .

What is Cognito in AWS?

AWS Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. Cognito has two main parts to it : A User Pool acts as a user directory in Cognito. With a user pool, your users can sign in to your web or mobile app through Amazon Cognito.

How do I Capture SAML values in Amazon Cognito?

Sign in to the Amazon Cognito console . In the navigation pane, choose Manage your User Pools, and choose the user pool you want to edit. Choose the Attribute mapping tab. Choose the SAML tab. Select the Capture box for all attributes for which you want to capture values.

How do I view user information in AWS Cognito?

From the Amazon Cognito home page in the AWS Management Console, choose Manage your user identities . Choose your user pool from the Your User Pools page. Choose User and Groups to view user information.


2 Answers

Unfortunately you simply can't using Cognito alone:

https://docs.aws.amazon.com/cognito/latest/developerguide/how-to-manage-user-accounts.html#cognito-user-pools-searching-for-users-using-listusers-api

Custom attributes are not searchable. This is because only indexed attributes are searchable, and custom attributes cannot be indexed.

Your only option will be to keep your own database relating the user to the attribute value, and enforce uniqueness there. For example in DynamoDB you would record the user's sub (unique Cognito identity) and the value of the custom attribute as sort/partition keys accordingly, ensure that normal cognito clients could only read the custom attribute, and provide your own API (lambda + api-gateway) to attempt to add/update the table and use the cognito Admin API to update the 'read-only' custom attribute on the user.

like image 85
thomasmichaelwallace Avatar answered Nov 01 '22 16:11

thomasmichaelwallace


That's correct you can't search custom attribute. Why can't you use one of standard attribute of AWS Cognito to be populated same as custom attribute. Just a thought. Then you can search also to check it uniqueness.

Standard attributes:

username (case-sensitive)

email

phone_number

name

given_name

family_name

preferred_username

cognito:user_status (called Status in the Console) (case-insensitive)

status (called Enabled in the Console) (case-sensitive)

sub

like image 33
tarunM Avatar answered Nov 01 '22 15:11

tarunM