use*_*776 5 swift swift3 aws-cognito
看过类似的SO问题,这些问题没有帮助我解决问题。
我在我们的iOS应用中使用AWS Cognito用户池。我们能够成功创建并登录用户。但是大约一小时后访问令牌不可用,我从AWS Cognito文档中了解到iOS SDK自动刷新(也在此处提到)并在不可用时获取令牌,但是我看不到这种行为。以下代码显示了我如何尝试获取访问令牌。
使用iOS SDK AWSCognitoIdentityProvider 2.6.7
请建议我如何解决该问题。
let mySession = self.pool.currentUser()?.getSession()
guard let accessToken = mySession?.result?.accessToken?.tokenString as? String else {
print("Unable to obtain access token")
self.handleSignOut() // Signing out the user since there is no access token
return
}
Run Code Online (Sandbox Code Playgroud)
小智 3
getSession()返回一个 AWSTask。
您必须tokenString在回调中访问 。
以下代码对我有用:
self.pool.currentUser()?.getSession().continueWith { task in
if task.error == nil {
let session = task.result! as AWSCognitoIdentityUserSession
guard let accessToken = session.idToken?.tokenString; as? String else {
print("Unable to obtain access token")
self.handleSignOut() // Signing out the user since there is no access token
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2047 次 |
| 最近记录: |