Using Custom Attributes in Amazon Cognito User Pool.
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 :
- User Pool
- Identity Pool
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. Your users can also sign in through social identity providers like Facebook or Amazon, and through SAML identity providers
Identity pools, on the other hand, lets you create unique identities for your users and federate them with identity providers(Facebook/Google).
Cognito User Pool providers you with a lot of built-in attributes like name, phone number, email, etc.
But at times we need to add certain other values with regards to users… In my case, I used a custom attribute to keep a tab on which user is added to which group.
You could add custom attributes while creating a user pool or you could even edit the user pool to add custom attributes later.
I assume that you have a user pool created.
Adding custom attributes to your user pool :
- Select your user pool.
- On the left-hand side select Attributes as follows :
3. Scroll down to find an option for adding custom attributes as :
4. Click on add custom attribute to add one as follows:
You need to specify the following details:
- Type (The datatype of the attribute . You can select either as a string or int)
- Name
- Min length
- Max length
- Mutable (If you wish to allow the user to change the value of a custom attribute after the value has been provided by the user, select Mutable)
To add another custom attribute you could click on “Add another attribute” and Save Changes later.
I could very easily do this but didn’t know how to make it accessible and easily wasted an hour or so on the same.
So make sure to set permissions for your custom attributes as follows:
- Select App Client from the left-hand side as :
2. Click on “Set Attribute read and write permissions”, it would show up as :
3. Make sure to select your custom attribute in readable/writable attributes according to your needs, in my case its “custom:example_field”.
The custom attributes in AWS begin with a “custom:” prefix.
That’s it… Now it's available for you to use…
Please get in touch in case of any queries.
Thanks.