amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

Refresh token using expired token - SessionExpiredException handling

Open gauravdangi opened this issue 5 years ago • 5 comments

Describe the bug I am getting SessionExpiredException (Session expired could not fetch user sub) when a user's session is expired while fetching the user's Auth session await Amplify.Auth.fetchAuthSession(options: CognitoSessionOptions(getAWSCredentials: true));

Now I would like to refresh the token once it is expired without asking the user to re-login. So there should be a method using with we can use the previously expired token to sign-in the user back to the application. Otherwise, we'd have to store the user's username and password in the shared preference in order to auto-login and I'm not very sure if I should store the password in the shared preference.

How can we solve this problem? Is there any way I can get the new session so that users do not have to sign in manually?

Expected behavior Should be able to auto-login once the session is expired

Platform Amplify Flutter current supports iOS and Android. This issue is reproducible in : [.] Android [.] iOS

gauravdangi avatar Mar 28 '21 09:03 gauravdangi

Guys, I'm really sorry, but this is not a feature-request. This is a bug. 'Session-refresh' is a must-have functionality for all current auth services and cognito can't force me to store user credits :( It will be a very challenging to pass the security check for the app storing credits in a raw format :(

AndyGUI avatar Jun 07 '21 14:06 AndyGUI

@AndreyGuitar @gauravdangi Apologies- I misunderstood the issue when marking it as a feature request. When this issue says 'refresh the token', do you mean the refresh token itself, or the access and id tokens? The latter should automatically refresh provided that the refresh token is still valid. You are seeing a refresh token that is still valid, but access and id tokens fail to update?

haverchuck avatar Jun 15 '21 17:06 haverchuck

@gauravdangi or @AndreyGuitar would you mind providing some more info on the behavior you are experiencing versus the behavior you are expecting? If you can include reproduction instructions that would be great. It sounds like you may be experiencing a bug, and I would like to reproduce it so that we can look into a fix.

If the refresh token is still valid, the access and ID token should automatically refresh. If you are seeing different behavior, that sounds like a bug. Once the refresh token is expired, there is no way to refresh it without re-authenticating the user (for example, with username/password). Cognito allows the refresh token to be set to expire anywhere between 60 minutes and 3650 days, and the access/ID tokens can be set to expire anywhere between 5 minutes and 1 day.

Jordan-Nelson avatar Aug 11 '21 21:08 Jordan-Nelson

@gauravdangi or @AndreyGuitar would you mind providing some more info on the behavior you are experiencing versus the behavior you are expecting? If you can include reproduction instructions that would be great. It sounds like you may be experiencing a bug, and I would like to reproduce it so that we can look into a fix.

If the refresh token is still valid, the access and ID token should automatically refresh. If you are seeing different behavior, that sounds like a bug. Once the refresh token is expired, there is no way to refresh it without re-authenticating the user (for example, with username/password). Cognito allows the refresh token to be set to expire anywhere between 60 minutes and 3650 days, and the access/ID tokens can be set to expire anywhere between 5 minutes and 1 day.

Hi @gauravdangi or @AndreyGuitar - I am just following up on this. If you are still experiencing an issue, please provide the info requested above.

Jordan-Nelson avatar Aug 26 '21 14:08 Jordan-Nelson

Hey @gauravdangi @AndreyGuitar

I am closing this issue for now as we didn't hear from you We can reopen it if you are still facing the issue and when you provide details

Regards Mo

mo-malaka avatar Sep 07 '21 15:09 mo-malaka