Looked at similar SO questions which didn't help me resolve the issue.
I am using AWS Cognito User Pools in our iOS App. We are able to successfully create and login the user. However after about an Hr the access token is not available, I understand from AWS Cognito documentation that the iOS SDK automatically refreshes (also mentioned here) and obtains the token when it is not available, however I don't see this behaviour. The below code shows how I am trying to obtain the access token.
Using iOS SDK AWSCognitoIdentityProvider 2.6.7
Please advice how I can resolve the issue.
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
}
getSession()
returns an AWSTask.
You have to access the tokenString
in the callback.
The following code works for me:
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With