Skip to content
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

IAM Graphql call always returns expired Session Credentials after 1 hr #13223

Open
3 tasks done
asp3 opened this issue Apr 8, 2024 · 1 comment
Open
3 tasks done

IAM Graphql call always returns expired Session Credentials after 1 hr #13223

asp3 opened this issue Apr 8, 2024 · 1 comment
Assignees
Labels
GraphQL Related to GraphQL API issues pending-response Issue is pending response from the issue requestor to-be-reproduced Used in order for Amplify to reproduce said issue

Comments

@asp3
Copy link

asp3 commented Apr 8, 2024

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

Authentication, GraphQL API

Amplify Version

v6

Amplify Categories

auth, api

Backend

None

Environment information


  System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 520.42 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.6.1 - ~/.nvm/versions/node/v20.6.1/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v20.6.1/bin/npm
    Watchman: 2024.01.22.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 114.1.52.130
    Chrome: 123.0.6312.107
    Safari: 17.4.1
  npmPackages:
    @knowt/eslint-config: * => 0.0.0 
    dotenv-cli: latest => 7.4.1 
    husky: ^8.0.0 => 8.0.3 
    lint-staged: ^12.4.0 => 12.5.0 
    prettier: ^2.7.1 => 2.8.8 
    turbo: ^1.10.12 => 1.13.2 
  npmGlobalPackages:
    @aws-amplify/cli: 12.10.1
    amplify: 0.0.11
    appcenter-cli: 2.14.0
    corepack: 0.19.0
    eas-cli: 5.4.0
    eslint: 8.56.0
    expo-cli: 6.3.10
    npm-check: 6.0.1
    npm: 9.8.1
    ts-node: 10.9.2
    vercel: 33.5.4

Describe the bug

On Dev, after bumping the version to 4.0.27, it seems like all my unauthorized calls are returning "ExpiredTokenException"
image

I checked the fetchAuthSession call, and even when calling with forceRefresh, the token did not update, and the Expiration at (await fetchAuthSession({ forceRefresh: true })).credentials.Expiration was always in the past. The only way to fix this seems to be to rm -rf .next and restart the server, which caused the new session credentials to get created. However, this will likely lead to a problem in production if tokens expire after that long and never get refreshed. We are using identity pool access and it has been working on our live site (as of 4 days ago, on 4.0.21).

Expected behavior

I expect session tokens get refreshed automatically. We chose IAM instead of API KEY as the unauth authorization mode since we would not have to worry about expiries.

Reproduction steps

  1. create a simple graphql API
  2. clear next folder, run yarn, and make an unauth API call, and log the session. you will see an expiration time
  3. wait 1 hr (which seems to be the expiration time) and make another call, and get an "ExpiredTokenException"
    Turn on ConsoleLogger.LOG_LEVEL = "INFO", and see that the log
[INFO] 13:35.744 CognitoCredentialsProvider - returning stored credentials as they neither past TTL nor expired.

is printed beforehand, and we see the call for ExpiredTokenException right afterwards.

image

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@asp3 asp3 added the pending-triage Issue is pending triage label Apr 8, 2024
@asp3 asp3 changed the title IAM API call always returns expired Session Credentials IAM Graphql call always returns expired Session Credentials after 1 hr Apr 8, 2024
@cwomack cwomack added the GraphQL Related to GraphQL API issues label Apr 9, 2024
@chrisbonifacio chrisbonifacio self-assigned this Apr 9, 2024
@chrisbonifacio chrisbonifacio added the to-be-reproduced Used in order for Amplify to reproduce said issue label Apr 9, 2024
@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Apr 24, 2024

Hi @asp3 👋 thanks for raising this issue.

In order for us to accurately reproduce the issue, can you specify what package you're referring to with the version of 4.0.27? Is that the aws-amplify package?

I ask because the code you shared seems more like the current API in v6 and the issue description mentions v6.

@chrisbonifacio chrisbonifacio added pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL Related to GraphQL API issues pending-response Issue is pending response from the issue requestor to-be-reproduced Used in order for Amplify to reproduce said issue
Projects
None yet
Development

No branches or pull requests

3 participants