Aws-sdk-android: I get "No cached session error" after calling getToken() when user state is SIGNED_IN

Created on 19 Oct 2019  路  8Comments  路  Source: aws-amplify/aws-sdk-android

Describe the bug
At first when i login with Google HosteUI everything is good. but after close and open app. my userStateListener says that user is "SIGNED_IN" and i'm going to get call getTokens() method but it returns error "No Cached Session".

2019-10-19 14:38:49.108 12558-12660/hu.avicenna.android E/ApiClient: error in get token
    java.lang.Exception: No cached session.
        at com.amazonaws.mobile.client.AWSMobileClient$10.onFailure(AWSMobileClient.java:1648)
        at com.amazonaws.mobileconnectors.cognitoauth.AuthClient.getSession(AuthClient.java:182)
        at com.amazonaws.mobileconnectors.cognitoauth.Auth.getSession(Auth.java:674)
        at com.amazonaws.mobile.client.AWSMobileClient._getHostedUITokens(AWSMobileClient.java:1651)
        at com.amazonaws.mobile.client.AWSMobileClient.access$800(AWSMobileClient.java:163)
        at com.amazonaws.mobile.client.AWSMobileClient$9.run(AWSMobileClient.java:1573)
        at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.Exception: No cached session
        at com.amazonaws.mobileconnectors.cognitoauth.AuthClient.getSession(AuthClient.java:182)聽
        at com.amazonaws.mobileconnectors.cognitoauth.Auth.getSession(Auth.java:674)聽
        at com.amazonaws.mobile.client.AWSMobileClient._getHostedUITokens(AWSMobileClient.java:1651)聽
        at com.amazonaws.mobile.client.AWSMobileClient.access$800(AWSMobileClient.java:163)聽
        at com.amazonaws.mobile.client.AWSMobileClient$9.run(AWSMobileClient.java:1573)聽
        at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)聽
        at java.lang.Thread.run(Thread.java:764)聽

Environment Information (please complete the following information):

  • AWS Android SDK Version: 2.15.1
  • Device: OnePlus 5T
  • Android Version: 8.1
  • Specific to simulators: No
AWSMobileClient Bug Needs Info from Requester closing-soon-if-no-response

Most helpful comment

I also get the same error: AWSMobileClient: Tokens are invalid, please sign-in again. java.lang.Exception: No cached session. Are there any news about this topic?
I am using my own UI and the user state of my user is also: signedIn.
For the signIn i am using this method: AWSMobileClient.getInstance().signIn
Afterwards when calling:
Log.d("JWT: ", AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString());
I get the exception.

All 8 comments

@mohsenk We did some bug fixes to AWSMobileClient for Hosted UI in the versions later than 2.15.1. Can you upgrade to the latest, verify and let us know?

No i tried with 2.16.1 but i still get same error.

I tried with 2.16.3 but still get error

Log
2019-11-15 22:14:11.571 30109-30231/com.domain.awsdevicefram D/AppSyncSigV4SignerInterceptor: Signer Interceptor called 2019-11-15 22:14:11.736 30109-30231/com.domain.awsdevicefram D/AWSMobileClient: Inspecting user state details 2019-11-15 22:14:11.833 30109-30231/com.domain.awsdevicefram W/AWSMobileClient: signalTokensNotAvailable 2019-11-15 22:14:11.836 30109-30231/com.domain.awsdevicefram W/AWSMobileClient: Tokens are invalid, please sign-in again. java.lang.Exception: No cached session. at com.amazonaws.mobile.client.AWSMobileClient$9$1.signalTokensNotAvailable(AWSMobileClient.java:1619) at com.amazonaws.mobile.client.AWSMobileClient$9$1.getAuthenticationDetails(AWSMobileClient.java:1599) at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser.getSession(CognitoUser.java:778) at com.amazonaws.mobile.client.AWSMobileClient$9.run(AWSMobileClient.java:1581) at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115) at com.amazonaws.mobile.client.AWSMobileClient.getTokens(AWSMobileClient.java:1547) at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:1026) at com.amazonaws.mobile.client.AWSMobileClient.waitForSignIn(AWSMobileClient.java:905) at com.amazonaws.mobile.client.AWSMobileClient$9.run(AWSMobileClient.java:1563) at com.amazonaws.mobile.client.internal.InternalCallback.await(InternalCallback.java:115) at com.amazonaws.mobile.client.AWSMobileClient.getTokens(AWSMobileClient.java:1529) di.NetModule.lambda$provideAWSAppSyncClient$0(NetModule.java:64) at -$$Lambda$NetModule$GjhUnNi68GsP0WBWrhUoxWL48i8.getLatestAuthToken(Unknown Source:0) at com.amazonaws.mobileconnectors.appsync.sigv4.AppSyncSigV4SignerInterceptor.intercept(AppSyncSigV4SignerInterceptor.java:146) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at com.amazonaws.mobileconnectors.appsync.retry.RetryInterceptor.intercept(RetryInterceptor.java:40) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) di.NetModule.lambda$provideOkHttpClient$1(NetModule.java:125) di.-$$Lambda$NetModule$aqPRldCQlu7jMj9diZIkAYzMXkA.intercept(Unknown Source:0) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) 2019-11-15 22:14:11.836 30109-30231/com.domain.awsdevicefram D/AWSMobileClient: waitForSignIn: userState:SIGNED_OUT_USER_POOLS_TOKENS_INVALID

any new ? @kvasukib @mohsenk

I also get the same error: AWSMobileClient: Tokens are invalid, please sign-in again. java.lang.Exception: No cached session. Are there any news about this topic?
I am using my own UI and the user state of my user is also: signedIn.
For the signIn i am using this method: AWSMobileClient.getInstance().signIn
Afterwards when calling:
Log.d("JWT: ", AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString());
I get the exception.

Hi all,

It seems this issue is caused by running the non-async getTokens() method on the main UI thread. You can either run it on a background thread or run the version of getTokens that takes a callback:

AWSMobileClient.getInstance().getTokens(Callback)

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Hi all, just wanted to let you know I happened to come across this issue in my own testing and found this is the result of a bug on our end where once a user has signed in with Hosted UI, it permanently caches that which messes up getting tokens if you sign in with the regular sign in method or federatedSignIn method.

The workaround is to clear data for the app but we will be fixing this so it doesn't happen again.

Was this page helpful?
0 / 5 - 0 ratings