Solving the Cognito Attributes Required Error


Borislav Hadzhiev

Last updated: Apr 21, 2021


Photo from Unsplash

Why we get the Cognito Attributes Required Error #

When using OAuth with AWS Cognito and Amplify I got the following error:

attributes required error

When you have users register with OAuth providers, you can enable attribute mappings, i.e. Google account last_name attribute to be mapped to Cognito's last_name attribute.

There's an attribute preferred_username, and when you map it using Google as OAuth provider it works fine:

this.identityProviderGoogle = new cognito.UserPoolIdentityProviderGoogle( this, 'userpool-identity-provider-google', { // other stuff.. attributeMapping: { preferredUsername: {attributeName: 'email'}, }, }, );

However, when I did the same using Facebook as an OAuth provider:

this.identityProviderFacebook = new cognito.UserPoolIdentityProviderFacebook( this, 'userpool-identity-provider-facebook', { // ... other stuff attributeMapping: { preferredUsername: cognito.ProviderAttribute.FACEBOOK_EMAIL, }, }, );

I got the Error: errordescription=attributes+required&error=invalid_request.

It seems to me like the mapping for Facebook is bugged and it causes the error in the screenshot.

How to solve the Cognito Attributes Required Error #

At the time of writing the only solution is to remove the attribute mapping and the stack deployment succeeds.

Hopefully the preferred_username attribute mapping gets fixed and doesn't throw a confusing error in the future.

Further Reading #

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.