amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
986 stars 453 forks source link

Missing required parameter REFRESH_TOKEN #130

Open newtriks opened 8 years ago

newtriks commented 8 years ago

When I get the current user from local cache i.e. user = userPool.getCurrentUser(), I then attempt to get a session using user.getSession().

This is throwing the following error in response to a POST request to https://cognito-idp.eu-west-1.amazonaws.com/:

{"__type":"InvalidParameterException","message":"Missing required parameter REFRESH_TOKEN"}

Digging in the debugger it results from aws-cognito-sdk.js:1280 where the httpRequestBody looks like: "{"ClientId":"my_client_id","AuthFlow":"REFRESH_TOKEN_AUTH","AuthParameters":{"REFRESH_TOKEN":"","DEVICE_KEY":"my_device_key"}}" which is called by the getSession request in amazon-cognito-identity.js.

So, it appears the session has expired and requires renewing but how do I do this ideally without it throwing errors in the console by making this HTTP request which has a possibility of failing?

Should I by default renew the session prior to making this call?

itrestian commented 8 years ago

The flow you describe should be correct. There was a small issue in the past where doing multiple calls to refreshSession would overwrite the refresh token with an empty value even if there was no refresh token retrieved (calling refreshSession doesn't retrieve a new refresh token, it only retrieves an access token and an id token). This was fixed in the following pull request so it should work now unless it's a different problem.

https://github.com/aws/amazon-cognito-identity-js/commit/470da21a16be5afaab2cfc6698278dd7bef5b013#diff-26892805fc0b4c2b37c713f88295be13

itrestian commented 7 years ago

Hi, does this issue still occur?

newtriks commented 7 years ago

Sorry, this was a POC and I completed it a while back, AFAIK the issue persisted.