Ed.
Ed.

Reputation: 3923

How can I access my User custom properties defined in my AWS Cognito User Pools?

I added a few custom properties in the User configuration off my AWS Cognito User Pool. I have my app in objective-c similar to the sample project CognitoYourUserPoolsSample. Everything works fine and I can sign-in/sign-up without any problem.

Though, I don't know how to access and set all the User custom attributes that I added in the User Pool config. I can access the default attributes values from the response object AWSCognitoIdentityProviderGetUserResponse for example. They are stored in the _userAttributes property (e.g. phone, email, etc.).

My questions are:

I get the following error when I try to sign-up with custom attributes using the same approach as the default attributes:

// add custom attributes
AWSCognitoIdentityUserAttributeType * subscriptionType = [AWSCognitoIdentityUserAttributeType new];
subscriptionType.name = @"subscriptionType";
subscriptionType.value = @"Premium";
[attributes addObject:subscriptionType];

Here is the error I get.

responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
{"__type":"NotAuthorizedException","message":"A client attempted to write unauthorized attribute"}

Thanks!

Upvotes: 1

Views: 2786

Answers (2)

evsam
evsam

Reputation: 1

As I found in the issue: Signup with custom attributes in Cognito user pools to set the value for custom attribute you must set a write permissions for it. Open Amazon Cognito Console -> YourPool -> General Settings -> App Clients -> Show Details -> Set attribute read and write permissions and activate checkboxes for your custom attributes.

Also in code attribute name should contain a prefix 'custom:' i.e. subscriptionType.name = @"custom:subscriptionType"; and those values are shown in AWS console.

Upvotes: 0

Yisha
Yisha

Reputation: 226

To answer your questions:

  1. Custom attributes are stored internally by Cognito, custom attributes can be seen from the response of a DescribeUserPool call.
  2. They should be set on pool creation from the Cognito console. They are not allowed to be set from a client, which is why you saw issues.

Thanks

Upvotes: 1

Related Questions