Comments (8)
I'm not sure if there is a use case where you would want expired tokens, but this is the reason that fetchAuthSession is async.
- If the auth tokens are not expired, fetchAuthSession will immediately provide the cached tokens in the callback.
- If the auth tokens are expired (or soon to be expired), it will make the network call to refresh the tokens and provide the new valid tokens.
If you want to use these values synchronously, you can always grab the tokens and then cache them to be used synchronously instead.
You can also look into using our Kotlin Coroutines support which would help you write async code in a cleaner way. https://docs.amplify.aws/android/start/project-setup/kotlin-coroutines/
from aws-sdk-android.
awsconfiguration.json
probably contains redundant elements, I was experimenting trying to solve the error.
Because there is no clear way to get a valid awsconfiguration.json
from AWS, which is also a point to improve (or please tell me if the way exists)
Here the word exists
means the value is masked:
{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "exists",
"AppClientId": "exists",
"AppId": "exists",
"Region": "exists"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "exists",
"AppClientId": "exists",
"AppId": "exists",
"Region": "exists"
}
},
"PinpointAnalytics": {
"PoolId": "exists",
"AppClientId": "exists",
"AppId": "exists",
"Region": "exists"
}
}
from aws-sdk-android.
"but there is no more such functionality in the latest versions."
@Andrew0000 Can you clarify what version of Amplify you are using? The above statement gives me the impression you may have updated to Amplify v2.
Amplify v2 and AWS Android SDK are not compatible with each other. See this guide on compatibility. https://docs.amplify.aws/android/sdk/configuration/amplify-compatibility/
from aws-sdk-android.
To answer your other question about awsconfiguration.json, the Amplify CLI still creates this file, alongside amplifyconfiguration.json.
from aws-sdk-android.
"but there is no more such functionality in the latest versions."
@Andrew0000 Can you clarify what version of Amplify you are using? The above statement gives me the impression you may have updated to Amplify v2.
Amplify v2 and AWS Android SDK are not compatible with each other. See this guide on compatibility. https://docs.amplify.aws/android/sdk/configuration/amplify-compatibility/
The code I provided worked on 1.x.x
I migrated to 2.x.x
It doesn't work.
So I try to find how to solve my need (get access and id tokens).
Just a real life case.
To answer your other question about awsconfiguration.json, the Amplify CLI still creates this file, alongside amplifyconfiguration.json.
It's absolutely inconvenient (and causes questions) to use CLI for such a basic thing like the android library setup.
from aws-sdk-android.
@Andrew0000 I'm not currently sure what your usage, but it is likely that you can entirely remove the AWS Android SDK and use Amplify only.
Amplify can get tokens by calling:
Amplify.Auth.fetchAuthSession(
{
val awsSession = it as AWSCognitoAuthSession
val userPoolToken = awsSession.userPoolTokensResult.value?.idToken
awsSession.awsCredentialsResult.value?.let { awsCredentials ->
awsCredentials.accessKeyId
awsCredentials.secretAccessKey
}
val identityId = awsSession.identityIdResult.value
},
{}
)
See here for more info: https://docs.amplify.aws/android/build-a-backend/auth/accessing-credentials/
from aws-sdk-android.
Thank you, this looks like a possible solution.
I'll try this migration.
from aws-sdk-android.
@tylerjroach By the way, Amplify.Auth.fetchAuthSession
seem asynchronous. Is there a way to just get tokens synchronously like it was earlier? The motivation is to eliminate a possible additional delay.
from aws-sdk-android.
Related Issues (20)
- Consumer proguard rules are too broad HOT 1
- My Device cannot get get/accepted or update/accepted, but same account in other devices is OK. HOT 1
- Pinpoint Analytics causes crash - SQLiteReadOnlyDatabaseException: attempt to write a readonly database HOT 7
- Should I expose Identity pool ID in my android app's source code? HOT 3
- Session issue : No cached session HOT 10
- Crash: java.lang.SecurityException Package android does not belong to 10347 HOT 3
- aws-translate - Need TranslateText function text field accept array HOT 1
- TransferWorkerObserver$attachObserverForPendingTransfer$1.invokeSuspend (API 25)
- Play mp4 file using aws kinesis HOT 3
- AuthClient: launchCustomTabs issue, 1 line called twice. HOT 8
- Duplicate AWS Chime SDK locations? HOT 2
- Broken Lambda Documentation Link HOT 3
- License clarification HOT 3
- Hi, does aws-sdk-android 2.73.0 support JDK17 and JDK21? HOT 1
- Error during SignIn - null object reference HOT 5
- Create Thing: Unauthenticated access is not supported for this identity pool. HOT 8
- Create Thing: Unauthenticated access is not supported for this identity pool. HOT 1
- Fatal Exception: java.lang.OutOfMemoryError HOT 6
- [Android 14+] InvalidForegroundServiceTypeException HOT 9
- libconscrypt_jni.so is not 16kb aligned for Android HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-android.