Ananth
Ananth

Reputation: 1998

How to get access token in AWS Cognito if using Browser based Javascript SDK?

I currently use this (roundabout) way to find access token. What is the correct way to get it in browser JS ?

var cognitoUser = userPool.getCurrentUser();
var tempKey = "CognitoIdentityServiceProvider."+_config.cognito.userPoolClientId;
var LastAuthUserTemp = cognitoUser["storage"][tempKey+".LastAuthUser"];     
var AccessToken = cognitoUser["storage"][tempKey+"."+LastAuthUserTemp+".accessToken"];

Upvotes: 1

Views: 1864

Answers (1)

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

Once you get the session (call getSession() method), you can get the json web token via session.getIdToken().getJwtToken()

Here I am assuming your Cognito User Pool is configured to use jwt.

Upvotes: 1

Related Questions