Reputation: 189
I can connect to aws user pool using aws-android-sdk. I can get standard attributes such as e-mail, given name etc... but IMPOSSIBLE to get a custom attribute. Here is the function used:
GetDetailsHandler detailsHandler = new GetDetailsHandler() {
@Override
public void onSuccess(CognitoUserDetails cognitoUserDetails) {
// Extract user details
}
@Override
public void onFailure(Exception exception) {
}
};
Upvotes: 4
Views: 14477
Reputation: 583
I had to enable my custom attribute under the App Client registration > Attribute read and write permissions
Upvotes: 0
Reputation: 85
I had troubles reading/writing custom attributes until i deleted the user pool and created the attributes when creating a new pool (rather than doing it after as I did for the original pool).
Upvotes: 0
Reputation: 113
You must mark the custom attribute as readable. See below: https://forums.aws.amazon.com/thread.jspa?threadID=248330
Upvotes: 2
Reputation: 327
Adding to @Sergey Kovalev
cognitoUserDetails
has CognitoUserAttributes
and CognitoUserSettings
cognitoUserDetails.getAttributes(); // returns UserAttributes
cognitoUserDetails.getSettings(); //returns UserSettings
You have to call getAttributes() once again to get the Hash Mapped attributes values.
To retrieve custom:preferred_name
use the following code.
Map mDetails = cognitoUserDetails.getAttributes().getAttributes();
String name = mDetails.get("custom:preferred_name").toString();
Check the AWS User Pools Console > Pool Details to get clarity on the attribute names.
Required attributes name, phone_number
Alias attributes preferred_username
Custom attributes custom:company, custom:location
I have used this in Android.
Upvotes: 4
Reputation: 5751
Basically, with Cognito on an authenticated user (CognitoUser object) you can call the methods for retrieving (getUserAttributes) and updating attributes (updateAttributes). Note that if you defined a custom attribute such as preferred_name for example, you need to reference such as below when using it:
custom:preferred_name
Upvotes: 0
Reputation: 9411
You should use getAttributes()
of CognitoUserAttributes
class to get user attributes.
Take a look at documentation http://docs.aws.amazon.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUserAttributes.html
and source code
Upvotes: 0