# Can't get access token with nextjs-auth0 with the audience set

**URL:** <https://community.auth0.com/t/cant-get-access-token-with-nextjs-auth0-with-the-audience-set/116393>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [September 15, 2023, 10:49pm UTC](https://community.auth0.com/t/cant-get-access-token-with-nextjs-auth0-with-the-audience-set/116393 "2023-09-15T22:49:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diego.diaz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/diego.diaz/32/50918_2.png) [@diego.diaz](https://community.auth0.com/u/diego.diaz)\
**Post date:** [September 15, 2023, 10:49pm UTC](https://community.auth0.com/t/cant-get-access-token-with-nextjs-auth0-with-the-audience-set/116393/1 "2023-09-15T22:49:37Z")

</div>

I’m trying to use an access token generated by the `getAccessToken` function but for some reason its returning a jwt without a payload

Here’s my handler code

```auto
// app/api/auth/[auth0]/route.js
import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export const GET = handleAuth({
    login: handleLogin({
        authorizationParams: {
            audience: 'https://anonymized.us.auth0.com/userinfo', // or AUTH0_AUDIENCE
            // Add the `offline_access` scope to also get a Refresh Token
            scope: 'openid profile email offline_access read:products' // or AUTH0_SCOPE
        }
    })
});

```

And heres where I want to consume it

```auto
import { getAccessToken, getSession } from '@auth0/nextjs-auth0';

export async function POST(req) {
    const { accessToken } = await getAccessToken({
        scopes: ["offline_access"]
    });=
    const options = {
        headers: { Authorization: `Bearer ${accessToken}` },
        method: "POST"
    }
    const url = `${process.env.LMS_URL}/login_refresh`
    let loginResponse = await fetch(url, options)
    return loginResponse
}

```

For some reason the jwt has no payload, I also made sure that I was passing the audience when logging in

 ![image](https://global.discourse-cdn.com/auth0/original/3X/8/9/8942b8e08f7ed6aa04cd61e9a216b1f1aa877f2a.png)

sorry for the tags, I can’t seem to find the proper tags for the help board

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 16, 2023, 12:28am UTC](https://community.auth0.com/t/cant-get-access-token-with-nextjs-auth0-with-the-audience-set/116393/2 "2023-09-16T00:28:34Z")

</div>

Hey @diego.diaz !

> [@diego.diaz](#):
>
> ```auto
> // app/api/auth/[auth0]/route.js
> import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';
> 
> export const GET = handleAuth({
> login: handleLogin({
> authorizationParams: {
> audience: 'https://anonymized.us.auth0.com/userinfo', // or AUTH0_AUDIENCE
> // Add the `offline_access` scope to also get a Refresh Token
> scope: 'openid profile email offline_access read:products' // or AUTH0_SCOPE
> }
> })
> });
> 
> ```

You shouldn’t be passing the `/userinfo` url as an audience, it will automatically be added to access tokens. I believe with the current set up the authorization server is just ignoring the `audience` param altogether so you’re receiving an [opaque token](https://auth0.com/docs/secure/tokens/access-tokens#opaque-access-tokens), thus the empty payload.

You’ll want to pass in the identifier/audience of your [API you registered](https://auth0.com/docs/get-started/auth0-overview/set-up-apis) in Auth0 instead.

More on the audience param can be found here:

[https://community.auth0.com/t/what-is-the-audience/71414](https://community.auth0.com/t/what-is-the-audience/71414)

Aside from that, everything looks good!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 30, 2023, 12:29am UTC](https://community.auth0.com/t/cant-get-access-token-with-nextjs-auth0-with-the-audience-set/116393/4 "2023-09-30T00:29:24Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
