Swift AWS Cognito错误:未设置身份验证委托

时间:2018-11-19 12:08:04

标签: swift amazon-web-services amazon-cognito aws-mobilehub

我正在迅速开发一个应用程序,并且使用AWS移动服务进行身份验证,并使用AWS Lambda进行一些后端处理。我一切正常,有一天(离开应用程序一个月左右),它开始抛出此错误:

 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"

它正在杀死我,因为它已经起作用了。可能会发生什么变化?

在appDelegate中,我有:

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)
    }

它实际上在我进行任何调用之前就引发了错误,所以我认为以上几行可能触发了问题?

要登录,请在主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
        }

登录后,我会检索用户名。

有什么提示吗?我遵循了其他帖子中的一些说明,但是它们没有用,而且最让我感到不安的是它还在用!

预先感谢

2 个答案:

答案 0 :(得分:0)

因此,不是100%确定发生了什么,但是据我了解,用户池中用户的凭据存在问题。我重设了密码,然后一切又恢复正常了!

我有人需要更多细节,只是问一下,如果有人更好地理解了,请告诉我。

答案 1 :(得分:0)

我认为这意味着您的刷新令牌已过期。

相关问题