76

I'm using the JavaScript SDK for AWS Cognito, and there are a couple of custom attributes that I just can't seem to save to and can't see why.

The problem attributes are mutable string fields as follows:

custom: role
custom: recruitingrole
custom: title

Other custom fields in the same request seem to update OK. Specifically, these ones seem to work:

custom:division
custom:linkedin
custom:location
custom:bio

When I submit via the SDK, this is returned:

{"__type":"NotAuthorizedException","message":"A client attempted to write unauthorized attribute"}

Here is the data that is sent, as show in the Chrome developer console network output:

{
    "AccessToken": "",
    "UserAttributes": [{
        "Name": "name",
        "Value": "Steve Austin"
    }, {
        "Name": "custom:company",
        "Value": "OSI"
    }, {
        "Name": "custom:division",
        "Value": "Bionics"
    }, {
        "Name": "custom:recruitingrole",
        "Value": "other"
    }, {
        "Name": "custom:linkedin",
        "Value": "http://www.linkedin.com"
    }, {
        "Name": "custom:location",
        "Value": "Mexico City, Mexico City, Mexico"
    }, {
        "Name": "custom:bio",
        "Value": "A man barely alive."
    }]
}

Can anyone suggest why I can't save to these attributes?

thanks

Duke Dougal
  • 24,359
  • 31
  • 91
  • 123

9 Answers9

165

Of course the answer became clear the moment I finished posting on StackOverflow.

The problem was that I had not set permissions for these attributes in the app associated with the user pool. The documentation should make this requirement clear where it discusses custom attributes.

enter image description here

Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
  • 3
    Glad to see you found the answer to your question. The doc for this feature is here: http://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-attribute-permissions-and-scopes I can see that it calls out the permissions/scope on attributes, and the error which you were receiving. If there's any specific edit you think should be made, or if there's something that could be added to make it more helpful/easier to read I'd encourage you to submit feedback using the button on the bottom right of the page. :) – Rob Devereux May 17 '17 at 10:14
  • @robDevereux I did as you suggested but along the way got various warnings Your connection is not secure The owner of docs-feedback.aws.amazon.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website. Learn more… Report errors like this to help Mozilla identify and block malicious sites – Duke Dougal May 17 '17 at 10:39
  • Wow! Thanks for highlighting this to me, I really appreciate it! And I'm sorry for the experience you've had, I'll make sure that the docs team are aware of this issue. – Rob Devereux May 17 '17 at 10:47
  • Hi, I've gotten in touch with the docs team and they've resolved the issue. – Rob Devereux May 18 '17 at 08:34
  • So I must be the only person in recent times who has commented on the documentation through that form :-) – Duke Dougal May 18 '17 at 10:00
  • Well, it looks like you were the first person to discover AND report it to us for sure :). It was a fairly new issue when you found it! Kudos :) – Rob Devereux May 18 '17 at 10:05
  • 21
    Above mentioned documentation still does not make it clear where you can set attribute permissions. I have found it to be in the General settings -> App clients -> Show details -> Set attribute read and write permissions link – mvandillen Dec 15 '17 at 14:12
  • 10
    I am unclear how these settings are supposed to be set. I have every box checked and it still doesn't work. – eignhpants Apr 28 '18 at 14:16
  • 1
    Would it be possible to get a more detailed error message. Like, which attribute is causing the issue? – Brian Takita Jul 08 '19 at 23:53
86

Just highlighting the answer from @mvandillen:

General settings -> App clients -> Show details -> Set attribute read and write permissions link

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
Martin Rázus
  • 4,615
  • 5
  • 30
  • 33
22

For anyone that stumbles upon this question:

Like the others suggested, you should enable the writable attributes. But if that doesn't work, make sure you use the custom: prefix:

await Auth.signUp({
      username: email,
      password: password,
      attributes: {
        'custom:firstName': firstName,
        'custom:lastName': lastName,
        'custom:countryCode': countryCode
      }
    })
Christiaan Maks
  • 3,248
  • 3
  • 23
  • 27
2

In my case the issue was in accessing variable with incorrect name. To sum up my steps were following.

  1. Add attribute: General settings -> Attributes -> Add custom attribute link

  2. Ensure you set read/write permissions: General settings -> App clients -> Show details -> Set attributes permissions link

  3. Do not forget to access you variable with correct name. For example if your variable named 'foo' you should get it as 'custom:foo' like below.

enter image description here

Elmatsidis Paul
  • 385
  • 1
  • 7
  • 19
2

To fix this error, you need to make sure that your app has permission to write the custom attribute that you're trying to write. You can do this by checking the permissions for the attribute and the app client in the Cognito user pool console.

Here are the steps to fix the error:

  1. Go to the Cognito user pool console.
  2. Click on the User Pools tab.
  3. Select the user pool that you're having problems with.
  4. Click on the App integration tab.
  5. Click on the App clients section.
  6. Select the app client that you're using.
  7. Click on the Attribute read and write permissions section.
  8. Make sure that the checkbox next to the attribute that you're trying to write is checked.
  9. If the checkbox is not checked, then check it and save your changes.

Once you've done this, you should be able to write the custom attribute without getting the error.

1

I would just like to add to the list regarding Android and Amplify's Auth lib. Along with enabling custom roles as specified above via AWS Console (General settings -> App clients -> Show details -> Set attribute read and write permissions link) you need to specify that the custom role under AuthUserAttributeKey.custom() has the string custom: prepended to your custom field. My assumption was that this would be excluded given the function call name. A little misleading but I hope this helps someone else out there.

TLDR;

Changed this:

AuthUserAttributeKey.custom("role");

to:

AuthUserAttributeKey.custom("custom:role");
Trayson Keli'i
  • 313
  • 2
  • 8
0

Using Amazon.Extensions.CognitoAuthentication in ASP.NET Core, you have to add:

var user = _pool.GetUser(model.Email)
user.Attributes.Add("name", model.Name);

Here name is the custom attribute

Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
0

My case is a bit different. I am using Amplify angular component and I don't have any custom attributes (standard email login type).

It turns out that the key of the sign-up fields is case-sensitive. For the uppercase 'Email' key, I will see the error. Below is the sign-up configurations

emailSignUpConfig = {
        header: 'Sign up header',
        hideAllDefaults: true,
        defaultCountryCode: '1',
        signUpFields: [
            {
                label: 'Email',
                key: 'email', //the email should be in lower case
                required: true,
                displayOrder: 1,
                type: 'string',
            },
            {
                label: 'Password',
                key: 'password',
                required: true,
                displayOrder: 2,
                type: 'password',
            },
        ],
    };
steamfood
  • 474
  • 3
  • 10
0

After enabling writeable attributes, this is what works for me

    const user = {
     username:this.username,
     password:this.password,     
      attributes:{
      email:this.email,
      'custom:field1': this.field1,
      'custom:field2': this.field2,
      'custom:field3': this.field3
     }
   }


             OR



   const user = {
     username:this.username,
     password:this.password,
     email:this.email,
      attributes:{
      'custom:field1': this.field1,
      'custom:field2': this.field2,
      'custom:field3': this.field3
     }
   }
Jemil Oyebisi
  • 633
  • 8
  • 10