Swift AWS Cognito error: Authentication delegate not set

663 views Asked by At

I am developing an app in swift, and I use AWS mobile services for authentication and AWS Lambda to do some backend processing. I had everything working fine, and one day (after leaving the app for a month or so), it started throwing this error:

 GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set" UserInfo {NSLocalizedDescription=Authentication delegate not set}]
 Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set"

It's killing me, because it was already working. What could have changed?

In appDelegate, I have:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        // Uncomment to turn on logging, look for "Welcome to AWS!" to confirm success
        AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
        AWSDDLog.sharedInstance.logLevel = .error

        // Instantiate AWSMobileClient to get AWS user credentials
        return AWSMobileClient.sharedInstance().interceptApplication(application, didFinishLaunchingWithOptions:launchOptions)
    }

It actually throws the error before I make any invocation, so I think the lines above may be triggering the problem?

To login, I do the following, in my main viewController:

override func viewDidLoad() {
        super.viewDidLoad()

        if !AWSSignInManager.sharedInstance().isLoggedIn {
            presentAuthUIViewController()
        }
        else{
            getCredentials()
        } 
        ...
        }

func presentAuthUIViewController() {
        let config = AWSAuthUIConfiguration()
        config.enableUserPoolsUI = true
        config.backgroundColor = UIColor.white
        config.logoImage = #imageLiteral(resourceName: "logoQ")
        config.isBackgroundColorFullScreen = true
        config.canCancel = true

        AWSAuthUIViewController.presentViewController(
            with: self.navigationController!,
            configuration: config, completionHandler: { (provider: 
            AWSSignInProvider, error: Error?) in
                if error == nil {
                    self.getCredentials()
                } else {
                    // end user faced error while loggin in, take any required action here.
                }
        })
    }

    func getCredentials() {
        let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
        let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "id",
                                                                            clientSecret: "secret",
                                                                            poolId: "id")
        AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "key")
        let pool = AWSCognitoIdentityUserPool(forKey: "key")
        if let username = pool.currentUser()?.username {
            userName = username
        }

It loggs in, and I retrieve the user name.

Any tips? I followed some of the instructions in other posts but they didn't work, plus what most disconcerts me is that it was working!

Thanks in advance

2

There are 2 answers

0
Danf On BEST ANSWER

So, not 100% sure of what was going on, but as I understand it there was a problem with the credentials for the user in the user pool. I reset the password and all started working fine again!

If anyone needs more details just ask, and if anyone understands this better let me know..

0
Jon Vogel On

I think this means that your refresh token expired.