# Invalid token: "The audience' is invalid"

**URL:** <https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307>\
**Category:** Get Help\
**Tags:** dotnet-core, audience, nextjs, auth0\
**Created:** [December 21, 2021, 10:56pm UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307 "2021-12-21T22:56:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rizwan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rizwan/32/13599_2.png) [@rizwan](https://community.auth0.com/u/rizwan)\
**Post date:** [December 21, 2021, 10:56pm UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307/1 "2021-12-21T22:56:14Z")

</div>

Hi,

I’ve created a nextjs front end and c# backend following the following guides and managed to get both working successfully:

> **[Using Next.js and Auth0 with Supabase](https://auth0.com/blog/using-nextjs-and-auth0-with-supabase/)**
>
> Learn how to integrate Auth0 authentication with database storage and row-level security authorization in Supabase.

> **[Authorization for ASP.NET Web APIs](https://auth0.com/blog/aspnet-web-api-authorization/)**
>
> How to enable authorization for ASP.NET Web APIs by limiting access to their endpoints through Auth0 authentication and authorization ser...

I’m now trying to wire them up to get the nextjs app to call the api backend.

The api has been setup with the following in the appsettings.json

```auto
"Auth0": {
    "Domain": "myapp.eu.auth0.com",
    "Audience": "https://api.myapp.com"
  }

```

In the nextjs app I have also added the following to the .env.local (the audience values are the same)

```auto
AUTH0_AUDIENCE=https://api.myapp.com
AUTH0_SCOPE=openid profile email

```

and successfully able to login using

```auto
#pages/api/auth/[...auth0].js

import { handleAuth } from '@auth0/nextjs-auth0';

export default handleAuth();

```

The issue comes when trying to call the api with the token. When calling the api with `session.idToken` it returns with an error of` Bearer error="invalid_token",error_description="The audience '<client id>' is invalid"` where is the client id of the app and not audience which I expected. When looking at the token in [https://jwt.io](https://jwt.io) the `aud` value is indeed the client id and not the expected audience.

Is there some missing config or extra steps required?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![thomas.osborn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thomas.osborn/32/22282_2.png) [@thomas.osborn](https://community.auth0.com/u/thomas.osborn)\
**Post date:** [December 21, 2021, 11:03pm UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307/2 "2021-12-21T23:03:28Z")

</div>

Hi!

You are using the ID token, not the access token. ID tokens are consumed by the client, but access tokens are consumed by the API. If you’re getting back a full JWT access token, you should pass that into the API.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![rizwan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rizwan/32/13599_2.png) [@rizwan](https://community.auth0.com/u/rizwan)\
**Post date:** [December 21, 2021, 11:12pm UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307/3 "2021-12-21T23:12:17Z")

</div>

thanks for the quick reply, that fixed it!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2021, 11:27am UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307/4 "2021-12-22T11:27:35Z")

</div>

Teamwork makes the dreamwork!

---

<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:** [January 6, 2022, 11:27am UTC](https://community.auth0.com/t/invalid-token-the-audience-is-invalid/75307/5 "2022-01-06T11:27:37Z")

</div>

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