-
Notifications
You must be signed in to change notification settings - Fork 549
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
Cognito Unable to cache Credentials #3450
Comments
Are you only using aws-sdk-android, or also using Amplify? If you are using MobileClient for Auth, you would should pass the MobileClient instance directly into the mqtt manager. |
I'm using aws-sdk-android only |
As mentioned by Tyler you need to use: |
Why is it necessary to use AWSMobileClient? Why to add one more dependency just for the sake of getting caching working? |
If you already have a method of fetching AWS Credentials, you may want to just implement your own Credentials Provider with a cache (aws-amplify/amplify-android#2400 (comment)). As far as the CognitoCachingCredentialsProvider not working as expecting for you, please enable logging on that file to help debug what may be working incorrectly. You can post the log here, but be careful to omit any credentials.
|
Hi @tylerjroach thank you for understanding my concern. Pasting logs below:
|
What I am not seeing in those logs is : Line 481 in 6ee1aa7
We should see this log when getCredentials is called to fetch the credentials. I'm also not seeing: Line 639 in 6ee1aa7
This is what would save the fetched credentials. Can you try creating your CognitoCachingCredentialsProvider and then manually calling getCredentials to see if either of these show in the logs for you? If you know how to set breakpoints inside CognitoCachingCredentialsProvider, it would also be helpful to follow the path being taken when |
Hi @tylerjroach , I tried running this code : But I'm not able to see logs you are requesting.
|
@vikrantuk Were you able to find a solution? Is this still an issue for you? |
How to enable caching for CognitoCachingCredentialsProvider?
I'm using com.amazonaws:aws-android-sdk-iot
Code snippets:
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider( appContext, COGNITO_POOL_ID, MY_REGION );
AWSIotMqttManager mqttManager = new AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT);
mqttManager.connect(credentialsProvider, callback);
Logs:
2023-11-03 01:30:38.332 24968-27053 AWSKeyValueStore I Detected Android API Level = 29
2023-11-03 01:30:38.332 24968-27053 AWSKeyValueStore I Creating the AWSKeyValueStore with key for sharedPreferencesForData = com.amazonaws.android.auth
2023-11-03 01:30:38.332 24968-27053 CognitoCachingCredentia D Loading credentials from SharedPreferences
2023-11-03 01:30:38.333 24968-27053 CognitoCachingCredentia D No valid credentials found in SharedPreferences
2023-11-03 01:30:38.336 24968-27054 AWSIotMqttManager D MQTT broker: a1sfow6qlhnw5d-ats.iot.ap-south-1.amazonaws.com:443
2023-11-03 01:30:38.357 24968-27054 AWSIotMqttManager D ready to do mqtt connect
2023-11-03 01:30:38.357 24968-27054 AWSIotMqttManager I metrics collection is enabled, username: ?SDK=Android&Version=2.22.6
2023-11-03 01:30:38.357 24968-27054 AWSIotMqttManager I resetting reconnect attempt and retry time
2023-11-03 01:30:38.357 24968-27054 AWSIotMqttManager D Setting up Callback for MqttClient
2023-11-03 01:30:38.357 24968-27054 MQTT D Status = Connecting
2023-11-03 01:30:38.408 24968-24968 System.out I Setting reference for amount text
2023-11-03 01:30:38.408 24968-24968 System.out I Setting reference for ui messages.
2023-11-03 01:30:38.869 24968-27061 AWSIotMqttManager I onSuccess: mqtt connection is successful.
2023-11-03 01:30:38.869 24968-27061 MQTT D Status = Connected
Environment:
Device Information:
The text was updated successfully, but these errors were encountered: