-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent/Incorrect behavior when fetching auth session without internet access #760
Comments
@flutteresbolivia Is this on Android or iOS? And is the refresh token actually valid? |
android with Flutter 2.0,6. About the token is that the phone is mostly without internet. |
@flutteresbolivia What is the expected behavior, exactly? A network exception? |
That the session does not expire and you can continue working with the local data of the phone, if you cannot find the internet. |
@flutteresbolivia Are you attempting to work in a signed out state, with guest credentials from an identity pool? Or are you trying to use Datastore for offline functionality? |
Hi @flutteresbolivia Following up on this. If you are still experiencing an issue, please provide the info requested above. Regards |
Hey @flutteresbolivia I am closing this issue for now as we didn't hear from you Regards |
Please reopen this issue. Right now, I cannot differentiate between a session really expiring (for which I would want to force a sign out) versus a network issue. |
I have the same issue, even if I do Amplify.Auth.signOut(), the next time the exception is always SessionExpiredException instead of SignedOutException. |
Of course we would like that when there is no internet it does not return SessionExpiredException If not more like a network error, it is difficult for me to control, please fix it |
Hello all - Apologies for the late update. It looks like this fell off our radar. It sounds like Auth APIs are throwing SessionExpiredException when there is no network, even if the session has not actually expired. I can attempt to reproduce this. Are you seeing this on both iOS and Android, or just on one particular platform? |
I am using the version 0.3.2 of the amplify plugin Android
iOS
|
@gianmarcocalbi - can you share the code that results in those errors as well as any steps to reproduce them? I am not able to reproduce this with the following code: CognitoAuthSession res = await Amplify.Auth.fetchAuthSession(
options: CognitoSessionOptions(getAWSCredentials: true),
); I have attempted the following:
From what I can see, there is an inconsistency between iOS and Android in the response when the network is offline and the session token has expired. However, I don't see a SessionExpiredException in either case. This isn't a fix for the reported issue, but I want to note that Cognito set defaults session/refresh token expiration, and that these can be customized. I believe the defaults are 60 minutes for session token, and 30 days for refresh token. If you expect your users to be offline frequently and/or for long periods of time, you may want to consider adjusting the default session token expiration. |
I have tried to replicate using the v0.4.1 and following your steps and
If I understand well, from your explanation, the issue is that
As you mentioned, iOS and Android behavior should be consistent, and in my opinion the exception should be more specific than |
Now, after 1h, I have just launched the app on Android still with the phone in airplane mode (network off), and fetchAuthSession gave me
|
I agree, we can mark this as a bug for a) the inconsistency, and b) the generic error opposed to a specific and helpful error
What is your refresh token expiration? I believe the lowest Cognito allows is 60 minutes. If you happen to have it set to 60 minutes, I think this would be expected since at this point your session and refresh token would have expired. If your refresh token is much higher, I wouldn't expect the behavior you are seeing. |
For the test I did:
|
@gianmarcocalbi - Okay, I am not sure what would be different between 5+ minutes and 1 hour. I'll see if I can reproduce this. |
I am going to attempt to repro the exception you have seen after 1 hour, but regardless I am going to mark this as a bug and a platform discrepancy. Expected behavior: On iOS and Android there should be consistent behavior and helpful/specific error messages when the following code is run without internet access in the following scenarios:
Amplify.Auth.fetchAuthSession(
options: CognitoSessionOptions(getAWSCredentials: true),
); Current Behavior:
Edit: I was able to reproduce the SessionExpired exception on Android after 1 hour with session token expiration of 5 min and refresh token expiration of 30 days. I have updated the current behavior above. |
Do you know anything about this functionality? |
Once this issue is fixed, what's the longest time an authenticated user can stay offline and rely on the DataStore without getting kicked out: is it determined by the session token max expiration of 36 hours, id/access token max expiration time of 1 day, or is it something else? Can an app for a low-tech fishing boat in Indonesia that stays out in the sea for a week have the authenticated experience longer than 36 hours? |
my application works many times offline, that is, international roads or routes without internet, it is an uber of trucks. Most drivers are offline without internet for up to 3 to 5 days. |
This issue has been addressed in as of v1.0.0-next.4 (developer-preview) of amplify_auth_cognito. Fixing this required making breaking changes to fetchAuthSession. Prior to the changes, fetchAuthSession would throw an exception if User Pool tokens OR AWS credentials were expired. This led to unexpected behavior since AWS credentials expire after 1 hour while User Pool tokens may be valid for a much longer period. With the updates, fetchAuthSession will not throw when User Pool tokens or AWS credentials are expired. Instead, the object returned will contain a userPoolTokenResult and a awsCredentialsResult. When accessing the |
This issue has been addressed in v1.0.0 of Amplify Flutter, which is now stable. See #760 (comment) for the changes made related to this issue. This release also includes web and desktop support for Auth, API, Analytics, and Storage. You can see the list of new features and bug fixes in the release notes, and see more details on how to migrate in the upgrade guide. |
my application is about an uber truck, where most of the road is OFFLINE.
but when he wants to make an offline request he skips that error.
Does anyone know how to apply it for offline mode?
error:
SessionExpiredException(message: Your session has expired., recoverySuggestion: Please sign in and reattempt the operation., underlyingException: null)
code:
CognitoAuthSession res = await Amplify.Auth.fetchAuthSession(options: CognitoSessionOptions(getAWSCredentials: true));
The text was updated successfully, but these errors were encountered: