Get user attributes AWS Amplify iOS SDK

cognito get user attributes
aws cognito update user attributes
amplify update user attributes
awsmobileclient get user attributes
aws-amplify forgot password
aws cognito edit user attributes
cognito user pool custom attributes cloudformation
aws-amplify logout

I'm building an iOS app with the SDK Amplify so I have my users registered on AWS.

I already have my sign in/sign up flow working but the problem is that with the newest version of the SDK I have absolutely no idea of how can I get attributes of a registered user like his family name, email address etc...

With this new SDK everything seems to work around the AWSMobileClientclass but I see nothing from this class that can help me to get what I want.

The official documentation is anemic and doesn't cover or even point to my use case.

If somebody can give me some hint or even some good ressources I'll be very thankful!

Hi YoanGJ and future guests,

Based on your comment you were looking for some sample code.

    AWSMobileClient.sharedInstance().getUserAttributes { (attributes, error) in
            if let attributes = attributes {
                XCTAssertTrue(attributes.count == 3, "Expected 3 attributes for user.")
                XCTAssertTrue(attributes["email_verified"] == "false", "Email should not be verified.")
            }else if let error = error {
                XCTFail("Received un-expected error: \(error.localizedDescription)")
            }
            getAttrExpectation.fulfill()
}

This excerpt shows how you could call getUserAttributes and it comes from the integration tests found here.

Ability to update a user attribute through Amplify iOS SDK , Within the Amplify AWSMobileClient iOS SDK unit tests I see an example for how to retrieve user attributes: aws-sdk-ios/AWSAuthSDK/Tests/  Amplify iOS is a collection of open-source client libraries that provides interfaces for specific use cases across many of the AWS services. Amplify iOS is the recommended way to build native iOS applications powered by AWS. You can also use the low-level AWS Mobile SDK for iOS with Amplify iOS if the use case you are trying to build is not

The method was missing from the initial release and has since been added. You can use the getUserAttributes with the following API in the latest SDK version 2.8.x:

public func getUserAttributes(completionHandler: @escaping (([String: String]?, Error?) -> Void))

You can find the source code here:

https://github.com/aws-amplify/aws-sdk-ios/blob/master/AWSAuthSDK/Sources/AWSMobileClient/AWSMobileClientExtensions.swift#L532

Thanks, Rohan

AWS Amplify adds support for custom attributes in Amazon Cognito , With the latest AWS Amplify release, we've added the ability to store and retrieve custom attributes in your Amazon Cognito user pool. In those cases, it notifies your app via the user state listener, which you can use to request your user to login again. The larger problem here is that the sign in/get credentials/respond to state changes interactions, while much simplified from the old Cognito SDK, is still confusing.

For a note:

Make sure you did configure attribute read and write permission accordingly in your Cognito user pool App client to access your user attributes using getUserAttributes.

To configure attributes read and write permissions in user pool,

User pool -> General settings -> App clients -> Choose your app client -> Show details -> Set attribute read and write permissions

Thanks!

Configuring User Pool Attributes - Amazon Cognito, You get a set of default attributes, called "standard attributes," with all user pools. the AdminUpdateUserAttributes API or the admin-update-user-attributes CLI  Install Amplify CLI. Before we get started, we are going to be using the AWS Amplify CLI which is part of the AWS Amplify Toolchain . $ npm install -g @aws-amplify/cli $ amplify configure. This is a one-time install. Check out the Get Started tutorial for more details. Initialize cloud backend from local project folder using Amplify CLI

Integrating Amazon Cognito With Web and Mobile Apps, When new users discover your app, or when existing users return to it, their first Cognito API to, for example, create new users in your user pool, retrieve user pool with your web or mobile app, use the SDKs and libraries that the AWS Amplify high-level SDKs and libraries for web and mobile platforms, including iOS,  To get started with the AWS SDK for iOS, check out the Developer Guide for iOS. You can set up the SDK and start building a new project, or you integrate the SDK in an existing project. You can set up the SDK and start building a new project, or you integrate the SDK in an existing project.

Authentication - Overview - Amplify Docs, You must always make an explicit signOut() call for a user to be signed out of a session. Note: Credentials are stored in the Xcode keychain. This is an encrypted​  AWS Amplify is a development platform for building secure, scalable mobile and web applications. It makes it easy for you to authenticate users, securely store data and user metadata, authorize selective access to data, integrate machine learning, analyze application metrics, and execute server-side code.

How To Do Authentication using AWS Amplify in iOS, "AWS Amplify Authentication module provides Authentication APIs and building In the Finder, drag awsconfiguration.json into Xcode under the top Project This manages the users' session for auth tasks like automatic  @daannijkamp Do you happen to know how to get the user for a given request in AWS Amplify? (See #3440 for full context). Thank you, if you do (or anyone else does). I use amazon-cognito-identity-js directly instead of using Amplify. You can grab user data from the JWS tokens. I pass in the tokens with each request and verify in the lambda

Comments
  • Thanks for this example and this ressource
  • Great @donkon Thanks for this snippet. 🙏
  • You're right, my pods were not updated. But with the 2.8.x version, when I try to call getUserAttributes the placeholder asks me to provide an instance of AWSMobileClient but no mention of the completionHandler... Do you have some exemples of implementation please?