[英]How do I get to AccessToken and IdToken following successful Amazon Cognito Login from iOS
I have been using the following sample to introduce cognito login to my iOS application: 我一直在使用以下示例将cognito登录引入我的iOS应用程序:
https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample
This is working well and I am at the point where I have a AWSCognitoIdentityUserPool
object which I can call the currentUser()
method to access the user. 这工作得很好,现在我拥有一个AWSCognitoIdentityUserPool
对象,可以调用currentUser()
方法来访问用户。
What I am struggling to find is how I extract both the AccessToken
and the IdToken
. 我正在努力寻找的是如何提取AccessToken
和IdToken
。
In the android equivalent, the onSuccess
method of the AuthenticationHandler
has a CognitoUserSession
argument which in turn has getIdToken()
and getAccessToken()
. 在android中, AuthenticationHandler
的onSuccess
方法具有CognitoUserSession
参数,该参数又具有getIdToken()
和getAccessToken()
。
Frustratingly, I see them output as the AuthenticationResult
in json format in the output window, but I just don't know how to access them programatically? 令人沮丧的是,我在输出窗口中看到它们以json格式作为AuthenticationResult
输出,但我只是不知道如何以编程方式访问它们?
Figured it out now: 现在想通了:
func getSession(){
self.user?.getSession().continueOnSuccessWith { (getSessionTask) -> AnyObject? in
DispatchQueue.main.async(execute: {
let getSessionResult = getSessionTask.result
self.idToken = getSessionResult?.idToken?.tokenString
self.accessToken = getSessionResult?.accessToken?.tokenString
})
return nil
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.