-
Notifications
You must be signed in to change notification settings - Fork 550
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
AWSMobileCLient getTokens returns Exception: No cached session. #1469
Comments
Hey, 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:
|
Hi,
here the corresponding code, where the exception is thrown.
I do not understand why the AWS SDK calls the method AWSMobileClient._getHostedUITokens, even if I don't use the HostedUi in this Login flow. |
Gotcha - yeah are you calling it after a successful callback from the AWSMobileClient initialize though? |
My initialization is done in my starting activity as following:
I have retried everything with a completeley new emulator and the problem did not appear then. |
Ok gotcha - thanks for the update! |
Hey @TobiS97 - just wanted to let you know I happened to come across this issue in my own testing and found you are 100% right and it is 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. We will be fixing this. |
What version would fix this issue? I'm hitting that problem at the moment. |
Looks like it's in 2.16.10 or later - any reason you can't just use the latest version? |
@TrekSoft my bad, I've been hitting that problem somehow else. Might not be interesting, but it happened when:
I'm calling signOut between the first 2 steps now. Not sure if it's a bug, just letting you know here :) |
Hmm gotcha - and this was with signing in with Hosted UI for both users? |
Nope, as far as I know (I've never used these SDKs many times, I'm part of a project). |
Got it - what I'm asking is, how did you sign in the users? What method were you calling to do it? |
I used this one:
|
Hmm, ok - and can you post the specific error you're getting with the stack trace? |
|
Alright thanks - we'll look into this. Since it sounds like you're not blocked by it for now we'll keep it as a lower priority item but does sound like something we'll want to ultimately address. |
Any news on this issue ? I believe it's related to this one aws-amplify/amplify-android#873. |
+1 Any updates on this issue? |
+1 I'm having exactly the same error. |
When I tired to send the IdToken to api using below code but AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString() gives below error when token expires.
2022-09-16 16:41:08.584 4737-4782/ W/AWSMobileClient: signalTokensNotAvailable I need to send the activeIdToken whenever the api call happens. Please help me out. |
The error message suggests that either user is not signed in or refresh token is expired. In both cases, the user must login again to get the tokens. |
I've found the issue. If you have device tracking enabled, then you must pass the users device key in the AuthParameters (which I was not doing). I read through the description of device tracking, as https://aws.amazon.com/blogs/mobile/tracking-and-remembering-devices-using-amazon-cognito-your-user-pools and it didn't seem applicable for my use-case so I simply turned it off (User Pool > Devices. Please send the device key in authParameters to make it work incase you enabled device tracking and that should resolve your issues |
Closing this issue as the issue has been resolved. |
State your question
I followed the Tutorial on https://aws-amplify.github.io/docs/sdk/android/authentication. After a sucessfully calling the signIn Method from the AWSMobileCLient as stated in the tutorial, I get back the message "Tokens are invalid, please sign-in again. Exception: No chached session."
The userState of my user is logged in.
The essential code:
Here the stacktrace of the exception:
It is weird that the getTokens() call delegates the logic to a _getHostedUITokens() method, even if I don't use the hosted ui in this setup. I only use the hosted UI when clicking a login with FB button.
Which AWS Services are you utilizing?
I am using the Amplify Android SDK for authenticating my users.
Version: 2.16.+ (aws-android-sdk-mobile-client, com.amazonaws:aws-android-sdk-cognitoauth, ...)
Environment(please complete the following information):
Device Information (please complete the following information):
The text was updated successfully, but these errors were encountered: