Skip to content

Auth refresh token not working #3111

@AlexGianq

Description

@AlexGianq

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

Authentication

Gradle script dependencies

// Put output below this line
    def amplifyVersion = '2.29.1'
    implementation "com.amplifyframework:aws-auth-cognito:$amplifyVersion"
    implementation "com.amplifyframework:rxbindings:$amplifyVersion"

Environment information

# Put output below this line
(not relevant)

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

When proceeding to RxAmplify.Auth.fetchAuthSession(), the session that is obtained after a refreshToken always fails, with a specific error:

SessionExpiredException{message=Your session has expired., cause=NotAuthorizedException(message=SecretHash does not match for the client: <redacted>), recoverySuggestion=Please sign in and reattempt the operation.}

I put a debug breakpoint at FetchAuthSessionCognitoActions.refreshUserPoolTokensAction, and it appears that the hashed username is signedInData.username. I was surprised that we hash this piece of data instead of signedInData.userId, so at debug runtime I switched the value to signedInData.userId and suddenly, refreshToken flow started working.

I have no understanding of cognito's internal mechanisms and expectations, so I might not help understand why things does not work as expected. So if you have an explanation, please provide it to me because I've been struggling for hours trying to figure out why this flow does not work.

Reproduction steps (if applicable)

  1. Configure a Identity pool with USER_SRP_AUTH (email login + password flow), and a 1-hour ID token expiration, and a 1-day refresh token expiration
  2. sign in or sign up
  3. wait for 1 hour

Current behaviour: when RxAmplify.Auth.fetchAuthSession() is called, the resulting AWSCognitoAuthSession contains a session with an error (SecretHash does not match for the client: ...), and the id token is absent from the session.

Expected behaviour: when RxAmplify.Auth.fetchAuthSession() is called, the resulting AWSCognitoAuthSession should be active and refreshed with a new idToken

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


Configuration File

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    authRelated to the Auth category/pluginsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions