【问题标题】:AWS Cognito Auth token - swiftAWS Cognito 身份验证令牌 - 快速
【发布时间】:2018-10-16 06:19:04
【问题描述】:

我已经使用 aws amplify 成功创建了 Cognito 用户池和身份池,并且能够使用记录的过程使用提供的 authUI 登录。登录后,我可以通过提供者响应检索 jwt 令牌....(以下未完成,因此请忽略任何语法错误)

AWSAuthUIViewController.presentViewController(
with: self.navigationController!, configuration: nil,
completionHandler: { (provider: AWSSignInProvider, error: Error?) in
    if error != nil {
       print("Error occurred: \(String(describing: error))")
    } else {
      // Sign in successful.
      print("sign in - token = \(provider.token())")
                                                
      var tokentask = provider.token()
      var output = tokentask.result
    }

})

然后我可以使用该令牌(输出)成功地针对 API 网关资源进行身份验证。我的问题是我无法在任何其他时间获得令牌。我找不到用于尝试检索该令牌的正确对象,或者找不到缓存该令牌的位置,因此我可以在应用程序的其他时间重用它。任何帮助将不胜感激!

【问题讨论】:

    标签: amazon-cognito


    【解决方案1】:

    我已经找到了最好的方法 -

    AWSCognitoUserPoolsSignInProvider.sharedInstance().getUserPool().token().continueWith { (AWSTask) -> Any? in
       if AWSTask.error == nil {
          print("Token \(String(describing: AWSTask.result))")
        }
            return nil
     }
    

    这将通过 awstask 返回令牌。

    【讨论】:

      猜你喜欢
      • 2020-08-30
      • 2016-04-11
      • 2018-01-29
      • 1970-01-01
      • 2019-07-20
      • 2016-06-25
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      相关资源
      最近更新 更多