Solving the Cognito Attributes Required Error

avatar

Borislav Hadzhiev

Wed Apr 21 20211 min read

Updated on Wed Apr 21 2021

To solve the AWS Cognito & Amplify error - attributes+required &error=invalid_request we have to remove the `preferred_username` attribute mapping.

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 #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee