【问题标题】:Swift AWS Cognito error: Authentication delegate not setSwift AWS Cognito 错误:未设置身份验证委托
【发布时间】:2019-04-21 19:04:10
【问题描述】:

我正在快速开发一个应用程序,我使用 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)
    }

在我进行任何调用之前它实际上会抛出错误,所以我认为上面的行可能会触发问题?

要登录,我在主视图控制器中执行以下操作:

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
        }

它登录,我检索用户名。

有什么建议吗?我按照其他帖子中的一些说明进行操作,但它们不起作用,而且最让我感到不安的是它起作用了!

提前致谢

【问题讨论】:

  • 我尝试在 appDelegate 中添加 pool.delegate = self 和相应的扩展,但还是不行

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    因此,不能 100% 确定发生了什么,但据我了解,用户池中用户的凭据存在问题。我重置了密码,一切又开始正常工作了!

    如果有人需要更多详细信息,请询问,如果有人更好地理解这一点,请告诉我..

    【讨论】:

      猜你喜欢
      • 2016-10-06
      • 2016-12-11
      • 2018-01-29
      • 2016-06-25
      • 1970-01-01
      • 2018-05-08
      • 2017-01-02
      • 2018-05-22
      • 2015-04-15
      相关资源
      最近更新 更多