Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito error: Authentication delegate not set

I am developing an iOS app in Swift using XCode 7.3. The app communicates with a DynamoDB database, allowing the user to read and write data. Recently, I updated my pods, which include AWSDynamoDB, AWSCognito, AWSCognitoIdentityProvider, and other AWS pods. I also set up a new user pool according to the instructions on this page:

http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

As part of following these instructions, I put the following code in the AppDelegate class's didFinishLaunchingWithOptions method:

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
    let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId:APP_CLIENT_ID, clientSecret: appSecret, poolId: USER_POOL_ID)
    AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: USER_POOL_NAME)
    let pool = AWSCognitoIdentityUserPool(forKey:USER_POOL_NAME)
    let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: IDENTITY_POOL_ID, identityProviderManager:pool)
    let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)
    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

I got the value for IDENTITY_POOL_ID by navigating starting from the AWS console to Cognito, Federated Identities, the identity pool I created while following the instructions, "Edit Identity Pool", and then copying the string shown next to "identity pool ID". I obtained the value for APP_CLIENT_ID by expanding "Authentication Providers" on the same page and selecting the "Cognito" tab. For USER_POOL_NAME, I used the "identity pool name" on this page, and for USER_POOL_ID I used the "user pool ID" value listed under "Authentication Providers". I am unclear as to whether I set these values correctly, since I wasn't entirely sure which values the developer guide was saying I should use.

After updating the pods and making these changes, when I run the app, I see the error:

[Error] AWSCredentialsProvider.m line:569 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.345 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set" UserInfo={NSLocalizedDescription=Authentication delegate not set}]

It is also now impossible to access the DynamoDB data, though the app does still launch. I suspect part of the problem is that my DynamoDB database is not in USEast, but I'm unsure whether this would actually result in this error. I have tried to look up possible causes for this error in addition to changing the code in AppDelegate, but the error remains the same. What are some likely causes I can investigate? If it makes a difference, I am trying to allow the app to authorize the user in addition to restoring the DynamoDB functionality, and I would like to accomplish both in the process of fixing this issue.

like image 442
user3726962 Avatar asked Jun 06 '16 20:06

user3726962


People also ask

How do I set up authentication in Cognito?

Go to AWS Cognito service and click “Manage Identity Pools”. 2. Enter “Identity pool name”, expand the “Authentication providers” section and select “Cognito” tab. This is where the Cognito authentication provider will be registered with the Identity pool.

How do you authenticate on Amazon Cognito?

Configure the external provider in the Amazon Cognito console. Choose Manage Identity Pools from the Amazon Cognito console home page : Choose the name of the identity pool where you want to enable Login with Amazon as an external provider. The Dashboard page for your identity pool appears.

What is SRP authentication Cognito?

Built-in authentication flow and challenges Amazon Cognito contains built-in AuthFlow and ChallengeName values so that a standard authentication flow can validate a user name and password through the Secure Remote Password (SRP) protocol. The AWS SDKs have built-in support for these flows with Amazon Cognito.


1 Answers

It looks like the issue you are having comes up when trying to have a user sign up or log in. In your sample code you do not set the pool.delegate value. This line should be in your AppDelegate

pool.delegate = self

This should also implement AWSCognitoIdentityInteractiveAuthenticationDelegate

This Blog post should assist you in getting started: https://mobile.awsblog.com/post/TxGNH1AUKDRZDH/Announcing-Your-User-Pools-in-Amazon-Cognito

The sample application might also be helpful https://github.com/awslabs/aws-sdk-ios-samples/blob/75ada5b6283b7c04c1214b2e1e0a6394377e3f2b/CognitoYourUserPools-Sample/Objective-C/CognitoYourUserPoolsSample/AppDelegate.h

like image 145
Mark Mercurio Avatar answered Oct 07 '22 16:10

Mark Mercurio