How to Get an Access Token with a Different Audience During the Login - NextJS - Auth0

Overview

When using the getAccessToken function, sometimes the need to pass the audience might arise, but it seems that this cannot be dynamically added, like in auth0-react. It appears to be stuck with the single audience that was provided after the user logs in.

This article clarifies whether there is a way to use getAccessToken to get an access token with a different audience than what was used on the original login.
 

Applies To

  • Access Token
  • NextJS - Auth0
  • getAccessToken

Solution

The function getAccessToken uses the refresh grant - so the audience cannot be updated on the access token using this. It is needed to log in again to get an access token for a new audience (which can be done using the SDK).

One of our engineers has implemented a workaround for a similar requirement, available here.

However, please note that this code is just to be used as an example and should be tested thoroughly before being put into production.

Recommended content

No recommended content found...