Skip to content

Nextjs get id token#344

Open
TharakaUJ wants to merge 2 commits intoasgardeo:mainfrom
TharakaUJ:nextjs-get-id-token
Open

Nextjs get id token#344
TharakaUJ wants to merge 2 commits intoasgardeo:mainfrom
TharakaUJ:nextjs-get-id-token

Conversation

@TharakaUJ
Copy link
Contributor

Purpose

This PR introduces getIdToken API and exposes the following token-related APIs via the Next.js SDK context for parity with the React SDK:

  • getDecodedIdToken
  • getIdToken
  • getAccessToken
  • exchangeToken

This allows Next.js applications to access both raw and decoded tokens and perform token exchange using the same API surface as React.

Related Issues

Related PRs

Checklist

  • Followed the CONTRIBUTING guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided. (Add links if there are any)

Security checks

@TharakaUJ TharakaUJ force-pushed the nextjs-get-id-token branch from 858a7c5 to 3115040 Compare February 1, 2026 12:26
@TharakaUJ
Copy link
Contributor Author

I haven't still test the code in action, I'll attach a screenshot once I'm done and open the PR.

Copy link
Contributor Author

@TharakaUJ TharakaUJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package is building fine now, but I noticed that the Next.js SDK has a separate server-side provider under packages/nextjs/src/server.

For now, to avoid build failures, I wired these methods through the existing client implementation.

I'm wondering whether I should follow the same pattern as in signIn, signOut etc. and create some implementation in packages/nextjs/src/server/actions.

@brionmario any advice?

@brionmario
Copy link
Member

Hey @TharakaUJ,

Thanks a lot for the PR.

In the Next.js SDK, since we have a server side, token handling is done at the server level.
Have a look at https://github.com/asgardeo/javascript/blob/main/packages/nextjs/src/server/actions/getAccessToken.ts.
We can follow the same way.

@TharakaUJ
Copy link
Contributor Author

TharakaUJ commented Feb 20, 2026

I’ve made some updates to the last commit.

I adjusted the return types of a few interfaces to include undefined where necessary, to keep the types aligned and avoid inconsistencies.

For the server action APIs, I followed the same pattern used in getAccessToken.

Since the sessionPayload currently only contains accessToken and sessionId, retrieving the idToken and decodedIdToken directly from it wasn’t possible. Therefore, I used the client instance to obtain those values.

I’ve attached screenshots demonstrating how getAccessToken, getIdToken, and getDecodedIdToken are working.

I still need to verify the exchangeToken API behavior, I’ll update once that’s confirmed. In the meantime, please let me know if any changes are required.

Thank you!

260221_02-15-31 260221_02-14-54
@TharakaUJ TharakaUJ marked this pull request as ready for review February 20, 2026 21:12
expose getIdToken, getDecodedIdToken, getAccessToken, and exchangeToken methods through AsgardeoContext in the Next.js SDK.
@asgardeo-github-bot
Copy link

⚠️ No Changeset found

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.

If these changes should result in a version bump, you need to add a changeset.

Refer Release Documentation to learn how to add a changeset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants