Skip to content

Document how to get encoded access token #5023

Open
@Glydric

Description

@Glydric

Description

I was developing an application in dart when I found out that the jwt value i was getting printing directly
let ses = await Amplify.Auth.fetchAuthSession() safePrint(ses);
is different that the one obtained using
final tokens = ses.toJson()["userPoolTokens"] as CognitoUserPoolTokens; safePrint(tokens.accessToken.encode().toString());
that should be used to extract the user pool token.

I found out that the signature is equal, but using the second method it was someway reformatting the token and obtain a different base 64 value. that is instead wrong
Indeed the first can be verified with jwt.io, while the latter is impossible to verify.
This is a real problem as I seen from previous issues that I'm not the only one that founds out this problem. but maybe I just discovered this difference.
I just discovered this on an iPhone 15 with ios 17.5, build using flutter 3.19.5 and dart 3.3.3 on macos 14.5

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

let ses = await Amplify.Auth.fetchAuthSession()
safePrint(ses); // Correct accessToken jwt
final tokens = ses.toJson()["userPoolTokens"] as CognitoUserPoolTokens;
safePrint(tokens.accessToken.encode().toString()); // Wrong accessToken jwt

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.19.5

Amplify Flutter Version

2.1.0

Deployment Method

Custom Pipeline

Schema

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationImprovements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes).authIssues related to the Auth Categoryfeature-requestA request for a new feature or an enhancement to an existing API or category.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions