furaiev / amazon-cognito-identity-dart-2

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
187 stars 114 forks source link

SECRET_HASH header is not added in refreshSession #199

Closed yeejingt95 closed 2 years ago

yeejingt95 commented 2 years ago

Pull request #198: Moving SECRET_HASH assignment out from unrelated condition block

Summary

Issue

SECRET_HASH header is not added in refreshSession.

Cause

The step is enclosed by one if block, and it is unnecessary.

Fix

Move the SECRET_HASH header insertion out of the block, like how it is done in other methods.

Details:

If the Cognito App Client has set up a client secret, a SECRET_HASH header will be required to refresh the token.

One possible scenario will be:

  1. User login to the app, Cognito returns Access Token, ID Token, Refresh Token.
  2. App stored all tokens and username on the device (e.g. shared_preferences).
  3. User closes the app and opens the app again after the access token or ID token is expired.
  4. App attempts to generate new tokens with stored username and refresh token.
  5. New tokens are generated and replace expired tokens.

So in step 4, my app failed to refresh the session because the secret hash is not added to the headers. Current logic has one condition check before adding SECRET_HASH, which is unnecessary.

furaiev commented 2 years ago

Closed via #198