Giter VIP home page Giter VIP logo

Comments (8)

tylerjroach avatar tylerjroach commented on August 15, 2024 1

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.

Andrew0000 avatar Andrew0000 commented on August 15, 2024

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.

tylerjroach avatar tylerjroach commented on August 15, 2024

"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.

tylerjroach avatar tylerjroach commented on August 15, 2024

To answer your other question about awsconfiguration.json, the Amplify CLI still creates this file, alongside amplifyconfiguration.json.

from aws-sdk-android.

Andrew0000 avatar Andrew0000 commented on August 15, 2024

"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.

tylerjroach avatar tylerjroach commented on August 15, 2024

@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.

Andrew0000 avatar Andrew0000 commented on August 15, 2024

Thank you, this looks like a possible solution.
I'll try this migration.

from aws-sdk-android.

Andrew0000 avatar Andrew0000 commented on August 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.