Aws-sdk-android: AWSMobileClient getTokens is slow to return new token

Created on 19 Aug 2020  路  9Comments  路  Source: aws-amplify/aws-sdk-android

Describe the bug
I'm creating @TrekSoft as you requested.
When calling AWSMobileClient.getInstance().getTokens() On an initialized AWSMobileClient with a signed in user, it takes about 5-12s to return the new fresh token.
I'm using this call to retrieve the JWT token with AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString() to be able to make an authenticated API call. Issue already has been mentioned in #1722

To Reproduce

Using following dependencies:

Steps:

  1. Wait 1h until token expire or clear data
  2. AWSMobileClient.getInstance().initialize()
  3. AWSMobileClient.getInstance().getTokens()

Which AWS service(s) are affected?
AWS Cognito
Android SDK 2.16.6, Android SDK 2.16.12, Android SDK 2.17.1 ,Android SDK 2.18.0

Expected behavior
Token should be retrieved faster (in 0.5-2 s max)

Environment Information (please complete the following information):
AWS Android SDK Version: 2.18.0, 2.16.12, 2.17.1, 2.16.6
Device: Samsung Galaxy s8 +
Android Version: Android 9.0
Specific to simulators: No

Device: Oneplus 7t pro
Android Version: Android 10
Specific to simulators: No

Device:Honor Play
Android Version: Android 9
Specific to simulators: No

AWSMobileClient Bug

All 9 comments

Perfect - thanks for creating this - I'll get right on it.

@TrekSoft any update please

Sorry - crazy couple weeks so no progress yet. Will keep you posted as we get this work scheduled.

@tyjaon - you mention an alternative to waiting the one hour was clearing data. Clearing data for the whole app signs the user out so was wondering what type of clear data you were referring to.

@TrekSoft I didn't test it but you could open CognitoIdentityProvier.pref as probably normal preferences and remove/edit token in order to refresh it. Also in #1204 zubairzahoor have provided description :

If you call getTokens() from a separate thread or async, it will fetch you the new tokens (access, id and refresh)

AWSMobileClient.getInstance().getTokens(new` Callback<Tokens>() {
         @Override
         public void onResult(Tokens result) {
             String AccessToken = result.getAccessToken().getTokenString();
             //Use AccessToken Here
         }

         @Override
         public void onError(Exception e) {
             Log.e("Err", e.getMessage());
         }
     });

I have tried the second method but at least for me it didn't work, but maybe you will figure something out.

Alright, I tried it yesterday after the token expired and it was coming back in about 600ms. Are you able to replicate this on an emulator? With a fresh, simple project on the latest SDK?

I will try and I will let you know.

@TrekSoft You can close the ticket the time of refresh token was mistakenly diagnose by me. Token is refreshing in 1s time. The true cause of delay was in lambda execution. So thank you for help and I'm sorry for a waste of your time

Not at all! Appreciate you digging into this and finding the root cause since this may be confusing for other customers as well.

Was this page helpful?
0 / 5 - 0 ratings