title: AWS Cognito Refresh Tokens: how to use them exactly?
body: <p>I have an app that obtains 3 tokens from the AWS Cognito User Pool TOKEN endpoint using Authorization Code Flow. It receives an ID_TOKEN an ACCESS_TOKEN and a REFRESH_TOKEN.</p>
  
  <p>The app uses the ID_TOKEN to obtain <code>CognitoAWSCredentials</code> on an Identity Pool:</p>
  
  <pre><code>var credentials = new CognitoAWSCredentials(IdentityPoolId, Region);
  credentials.AddLogin("cognito-idp.&lt;region&gt;.amazonaws.com/&lt;UserPoolId&gt;", ID_TOKEN);
  </code></pre>
  
  <p>After some time the credentials stop working, and calling any method on a AWS Client throws <code>NotAuthorizedException</code>, as would be expected, the tokens expire after 1 hour. </p>
  
  <p>It was my understanding that when a token expires, one can use the TOKEN endpoint again and pass the REFRESH_TOKEN to get back new tokens. That's useful, if it can be avoided, I'd rather not sign out the app user and force them to go through the OAUTH authentication flow again.</p>
  
  <p>So I've tried to refresh the token, HTTP POST to <code>/oauth2/token</code>, same request header as when I first obtained the tokens, but slightly different request body
  <code>?grant_type=refresh_token&amp;client_id=xxx&amp;refresh_token=xxx</code></p>
  
  <p>and I get back an ID_TOKEN and ACCESS_TOKEN but no REFRESH_TOKEN.</p>
  
  <p><strong>1-</strong> Is that expected? Does that mean the same REFRESH_TOKEN is used after 2 hours to refresh a second time? Or is that a subtle clue the TOKEN endpoint is giving me that something went wrong with refreshing (a better clue would have been for the endpoint to return an error...)</p>
  
  <p><strong>2-</strong> The new ID_TOKEN when examined carefully, is identical to the old ID_TOKEN. Is that expected, why didn't the TOKEN endpoint return a new ID_TOKEN? (When I use that new ID_TOKEN to create new CognitoAWSCredentials, I get credentials that are useless. They throw exceptions the first time I access any AWS Client. Indeed they are already expired since the new ID_TOKEN is the old one.)</p>
  
  <p><strong>3-</strong> Should I be using the ACCESS_TOKEN instead of the ID_TOKEN, and how would I get CognitoAWSCredentials using an ACCESS_TOKEN?</p>
  
  <p><strong>4-</strong> <code>CognitoAWSCredentials</code> are actually <code>RefreshingAWSCredentials</code>, do those actually automatically refresh, how?</p>