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
• 15,520 points
2,063 views

1 answer to this question.

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
• 58,090 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,670 points
6,115 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
• 4,170 points
1,525 views
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
• 58,090 points
1,066 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
• 58,090 points
1,566 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP