3

When successfully logged in into the cognito user pool, I can retrieve access token and id token from the callback function as

onSuccess: function (result) {
    var accesstoken = result.getAccessToken().getJwtToken()
    var idToken = result.idToken.jwtToken
}

But how can I retrieve the refresh token? And how can I get a new token using this refresh token. I didnot find any clear answers.

Manoj Acharya
  • 1,331
  • 2
  • 15
  • 27

1 Answers1

4

You can use result.getRefreshToken().getToken() for that. The success callback takes CognitoUserSession object i.e. result as a parameter which exposes getRefreshToken method to retrieve refresh token.

Refer this link for Cognito JavaScript SDK documentation -

https://github.com/aws/aws-amplify/tree/master/packages/amazon-cognito-identity-js

Not sure if I clearly understand your second question, but Use case 32 in above link might help you in dealing with it.

  • Thank you for that. Since the idToken expires every 1 hour, I want to use the Refresh Token to request for a new token whenever the idToken expires. Now I have got the refresh token from getRefreshToken, how can I initiate the process using Javascript? – Manoj Acharya May 04 '18 at 19:54
  • Oh ok. I think the Use Case 32 in the above link then fits perfectly for this purpose. It has code in JS for that, you can use that as it is. – Siddhesh Salgaonkar May 04 '18 at 20:01
  • Just what I needed!! Thanks a lot! – Manoj Acharya May 04 '18 at 20:03