Skip to content
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

Android get SIGNED_OUT_USER_POOLS_TOKENS_INVALID after 1 hour #815

Closed
jiafei1986 opened this issue Mar 27, 2019 · 7 comments
Closed

Android get SIGNED_OUT_USER_POOLS_TOKENS_INVALID after 1 hour #815

jiafei1986 opened this issue Mar 27, 2019 · 7 comments
Assignees
Labels
closing soon Issue will auto-close if there is no additional activity within 7 days. mobile client Issues with AWS Mobile's client-side Cognito wrapper question General question

Comments

@jiafei1986
Copy link

jiafei1986 commented Mar 27, 2019

Describe the bug
We are doing the login with the amplify sdk. so far we found an issue that the sdk will return SIGNED_OUT_USER_POOLS_TOKENS_INVALID after 1 hour. and from the document, it suggests user to log in again which is not expected for the user. it will also block the UI thread after that. the user cannot do anything after that.

To Reproduce
A code sample or steps:

AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString();
Your code

Which AWS service(s) are affected?
We use the id token to pass to our backend

Expected behavior

SDK should get the new idToken and it should not hit this error.
Another question is that i just checked aws code, it will send a HTTP call to refresh id and access token if these tokens expired. as we know android not allow to run network call on UI thread. does it mean I need to set a callback everywhere when i use this id token as i don't know what time the token expire?. because our backend API need the id token.

Screenshots
2019-03-26 16:15:51.617 25199-25199/com.expampe W/AWSMobileClient: signalTokensNotAvailable
2019-03-26 16:15:51.620 25199-25199/com.expampe W/AWSMobileClient: Tokens are invalid, please sign-in again.
java.lang.Exception: No cached session.
at com.amazonaws.mobile.client.AWSMobileClient$7$2.signalTokensNotAvailable(AWSMobileClient.java:1538)
at com.amazonaws.mobile.client.AWSMobileClient$7$2.onFailure(AWSMobileClient.java:1533)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getSession(CognitoUser.java:752)
at com.amazonaws.mobile.client.AWSMobileClient$7.run(AWSMobileClient.java:1500)
at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115)
at com.amazonaws.mobile.client.AWSMobileClient.getTokens(AWSMobileClient.java:1434)
at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:929)
at com.amazonaws.mobile.client.AWSMobileClient.waitForSignIn(AWSMobileClient.java:838)
at com.amazonaws.mobile.client.AWSMobileClient$7.run(AWSMobileClient.java:1450)
at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115)

2019-03-26 16:15:51.620 25199-25199/com.expampe D/AWSMobileClient: waitForSignIn: userState:SIGNED_OUT_USER_POOLS_TOKENS_INVALID
2019-03-26 16:15:51.621 25199-29008/com.expampe I/userState: need to login again
2019-03-26 16:15:51.639 25199-25199/com.expampe D/AWSMobileClient: Inspecting user state details
2019-03-26 16:15:51.689 25199-25199/com.expampe I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
2019-03-26 16:15:51.689 25199-25199/com.expampe I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
2019-03-26 16:15:51.691 25199-25199/com.expampe W/AWSMobileClient: signalTokensNotAvailable
2019-03-26 16:15:51.693 25199-25199/com.expampe W/AWSMobileClient: Tokens are invalid, please sign-in again.
java.lang.Exception: No cached session.
at com.amazonaws.mobile.client.AWSMobileClient$7$2.signalTokensNotAvailable(AWSMobileClient.java:1538)
at com.amazonaws.mobile.client.AWSMobileClient$7$2.onFailure(AWSMobileClient.java:1533)
at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getSession(CognitoUser.java:752)
at com.amazonaws.mobile.client.AWSMobileClient$7.run(AWSMobileClient.java:1500)
at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115)
at com.amazonaws.mobile.client.AWSMobileClient.getTokens(AWSMobileClient.java:1434)
at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:929)
at com.amazonaws.mobile.client.AWSMobileClient.waitForSignIn(AWSMobileClient.java:850)
at com.amazonaws.mobile.client.AWSMobileClient$7.run(AWSMobileClient.java:1450)
at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115)

Environment Information (please complete the following information):

  • AWS Android SDK Version: [e.g. 2.12.6]
  • Device: [e.g. Any device]
  • Android Version: [Any version]
  • Specific to simulators: [e.g. Yes]

Additional context
From our backend , they set the refresh token to 30 days.

@minbi minbi self-assigned this Mar 27, 2019
@minbi minbi added bug Something isn't working mobile client Issues with AWS Mobile's client-side Cognito wrapper labels Mar 27, 2019
@jiafei1986
Copy link
Author

By the way, we only use the SDK sign in API. the login UI is written by ourself.

@minbi
Copy link
Contributor

minbi commented Mar 28, 2019

Hi @jiafei1986 ,

I see that you are using the synchronous version of the method. Are you making the call from the main/UI thread? Can you try running it in a background thread? Or use the async version of the method.

AWSMobileClient.getInstance().getTokens(Callback)

@minbi minbi removed the bug Something isn't working label Mar 28, 2019
@jiafei1986
Copy link
Author

Hi @minbi
Yes, initially we found SDK provide us 2 methods, we use the one without callback. but we get issue as above, so we change to the second one which is async one. it seems ok now.

But we have to pass this idToken to many APIs of our backend. does it mean we need to wrap our business logic code inside the getTokens callback everywhere?

@minbi
Copy link
Contributor

minbi commented Mar 29, 2019

The AWSMobileClient.addUserStateListener(UserStateListener) is a way be notified the tokens have expired in a central location.

@jiafei1986
Copy link
Author

jiafei1986 commented Mar 29, 2019

@minbi Thank you for your quick reply. Yes, we have implemented that listener. what I am trying to ask is what is the correct way to get the tokens? For example, we have 10 APIs need this idToken, so we need to get token first and then pass them to our API. as you mentioned above. we should use AWSMobileClient.getInstance().getTokens(Callback), right?

@minbi
Copy link
Contributor

minbi commented Mar 29, 2019

we should use AWSMobileClient.getInstance().getTokens(Callback), right?

Yes.

as we know android not allow to run network call on UI thread. does it mean I need to set a callback everywhere when i use this id token as i don't know what time the token expire?.

This should handled by the async variant recommended above. It will create the network request on a background thread. Then, the listener will notify you if you need to sign in again OR if you wish the token request to fail call AWSMobileClient.releaseSignInWait()

@minbi minbi added question General question closing soon Issue will auto-close if there is no additional activity within 7 days. labels Apr 1, 2019
@minbi
Copy link
Contributor

minbi commented Apr 3, 2019

Hi,

We are closing this issue because there has been no activity. Please feel free to open a new issue if the problem persists. We ask this because closed issues are not actively monitored.

Thanks

@minbi minbi closed this as completed Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing soon Issue will auto-close if there is no additional activity within 7 days. mobile client Issues with AWS Mobile's client-side Cognito wrapper question General question
Projects
None yet
Development

No branches or pull requests

2 participants