How do I get to AccessToken and IdToken following successful Amazon Cognito Login from iOS

+1 vote

I have been using the following sample to introduce cognito login to my iOS application:

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.

What I am struggling to find is how I extract both the AccessToken and the IdToken.

In the android equivalent, the onSuccess method of the AuthenticationHandler has a CognitoUserSession argument which in turn has getIdToken() and 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?

Aug 28, 2018 in AWS by bug_seeker
• 14,970 points
252 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

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 
     } 
}
answered Aug 28, 2018 by Priyaj
• 56,120 points

Related Questions In AWS

0 votes
1 answer

How do I invoke another lambda async and pass context to it?

I tried several times trying to pass ...READ MORE

answered Apr 27, 2018 in AWS by Cloud gunner
• 4,240 points
991 views
0 votes
1 answer
0 votes
1 answer

How do i get the Elastic IP from running instance?

If yours is a linux ec2 instance ...READ MORE

answered Aug 29, 2018 in AWS by Archana
• 3,770 points
40 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How do I roll-back a message to Amazon MQ (AMQ) from Lambda?

It is apparently not possible using STOMP ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,120 points
67 views
0 votes
1 answer

How can I do Continuous data ingestion from on prem data sources to redshift

I can Recommend looking into AWS Schema ...READ MORE

answered Aug 8, 2018 in AWS by Priyaj
• 56,120 points
84 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.