AWS Cognitio Swift 3 Identity not found

2.2k views Asked by At

I followed the mobile hub introductions to setup my AWSCognito in app, when I try to call the signing, as suggested by aws. It says Identity not found. The Identity is in the user pool I can see it in the backend also marked as verified. Why is this error given?

Code:

func handleLoginWithSignInProvider(signInProvider: AWSSignInProvider) {
        AWSIdentityManager.defaultIdentityManager().loginWithSign(signInProvider, completionHandler:
            {(result: Any?, error: Error?) -> Void in
                if error == nil {
                    /* Handle successful login. */
                    print("success")
                }
                print("Login with signin provider result = \(result), error = \(error)")
        })
    }

The error:

GetCredentialsForIdentity failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=Identity 'eu-west-1:xxxxxxx' not found.}] AWSiOSSDK v2.4.16 [Error] AWSCredentialsProvider.m line:577 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.353 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=Identity 'eu-west-1:937fe0c4-974b-4f77-a835-425e1d9d9e00' not found.}] Login with signin provider result = nil, error = Optional(Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=Identity 'eu-west-1:xxxxxxxxx' not found.})

3

There are 3 answers

0
AudioBubble On

For others that is facing similar issue with JS, you can clear the content from the Developer Console in Application > Local Storage, find the Identity Pool UserID for the USER that is causing error and delete it from the storage.

Restart and try again. It should work.

0
Jeff Bailey On

By 'I can see it in the backend', do you mean in the Cognito identity browser? I took the identity id from your message and I can't find it stored in the Cognito data store. How are you verifying that it exists?

Try to clear your credentials provider and try again, some weird metadata may have gotten stuck inside.

0
Joshua Wolff On

It looks like the Identity Pool ID for the user was not found. This is different from not finding the user pool ID, which is the ID for your entire user pool. The ID that's missing seems to be the ID for the user's device itself.

This might have happened if you want to Cognito > Federated Identities and manually deleted an identity ID. There is no way of retrieving it, so you must do the following:

If you're running this on the simulator and want a quick fix, click Hardware > Erase All Content and Settings. Beware that doing that will do the obvious, but it will also force the SDK to get you a new identity ID.

If you're running this on a mobile device or want a better fix, you still have to force the SDK to get a new identity ID. Do this by clearing the Keychain. Then call getIdentityId to get a new ID - here's why that works:

"Get/retrieve the identity id for this provider. If an identity id is already set on this provider, no remote call is made and the identity will be returned as a result of the AWSTask (the identityId is also available as a property). If no identityId is set on this provider, one will be retrieved from the service"

Seeing that you're using swift, here's how you can do that:

if error == nil {
   print("success")
} else {
   if let errorDescription = error?.localizedDescription {
       if errorDescription == "The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 10.)" {
           let credentialsProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.USEast1, identityPoolId: "yourIdentityPoolId")
           credentialsProvider.clearKeychain()
           credentialsProvider.getIdentityId()
       }
   }
}

For more information, check out this useful AWS thread:

https://forums.aws.amazon.com/thread.jspa?threadID=249749

Also, check out the AWS documentation on the AWSCredentialsProvider:

http://aws.github.io/aws-sdk-ios/docs/reference//Classes/AWSCognitoCredentialsProvider.html#//api/name/clearKeychain

And that does the trick! Worked for me when I had the same issue. Good luck! Feel free to message me if you have any issues with this approach, or in general.