# 401, Bearer error="invalid\_token", The audience is invalid

**URL:** <https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [July 10, 2021, 1:41pm UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941 "2021-07-10T13:41:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvlasonjic](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bvlasonjic/32/30473_2.png) [@bvlasonjic](https://community.auth0.com/u/bvlasonjic)\
**Post date:** [July 10, 2021, 1:41pm UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941/1 "2021-07-10T13:41:15Z")

</div>

Hello,

I am developing a web application using asp .net core and React with auth0. So far, I’ve had no issues with setting up the spa-client and the api. However, I am facing the following issue when calling my api: “401, Bearer error=“invalid\_token”, The audience is invalid”.

I’ve used this guide to set up server authorization:

> **[Auth0 ASP.NET Core Web API SDK Quickstarts: Authorization](https://auth0.com/docs/quickstart/backend/aspnet-core-webapi/01-authorization)**
>
> This tutorial demonstrates how to add authorization to an ASP.NET Core Web API application using the standard JWT middleware.

I’ve tried following this guide in order to send the access token and test the authorization:

> **[Auth0 React SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api)**
>
> This tutorial demonstrates how to make API calls to the Auth0 Management API.

I’ve also tried reading through similar topics and none of the solutions have helped.

Here is the auth0 setup in my appsettings.json:  
“Auth0”: {  
“Domain”: “https://dev-\*\*\*\*\*\*\*\*.us.auth0.com/”,  
“Audience”: “[https://localhost:44350/api](https://localhost:44350/api)”  
},

Here is the setup in my index.js file  
 ![index](https://global.discourse-cdn.com/auth0/original/3X/7/0/7070a0b387c0b049fd6352fd067fd1bd1c158a69.png)

I am using axios to send my request. Here is how I acquired the token and created the authorization header:

const { getAccessTokenSilently } = useAuth0();  
const token = await getAccessTokenSilently();  
const axiosConfig = {  
headers: { Authorization: `Bearer ${token}` }  
};

When executing a put request, these are the headers:

 ![headers](https://global.discourse-cdn.com/auth0/original/3X/6/f/6f71710498d42468c78133173a11e21c65ec230c.png)

And this is the response:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/1/d1365730be8274c2e807815cb20ecf3600cec4e0.png)

The only thing that seems out of the ordinary is that there are two audiences inside of the token. I’m not sure why the ‘https://…/userinfo’ keeps getting added and whether that is the problem. If so, please provide me with an answer on how to fix this issue.

Sorry for the long message, I wanted to make sure I have provided all the required information. Please let me know if you need anything else.

Looking forward to the reply,  
Bojan

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [July 12, 2021, 4:48pm UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941/3 "2021-07-12T16:48:17Z")

</div>

Hi @bvlasonjic , welcome to the community!

The userinfo audience is added if you include `openid` in the scope of the authorize request.

- [Get Access Tokens](https://auth0.com/docs/tokens/access-tokens/get-access-tokens#multiple-audiences)

Unfortunately I found that the `openid` scope is always applied when using the React SDK, and it cannot be removed from the default scopes:

- [https://auth0.github.io/auth0-react/interfaces/auth0\_provider.auth0provideroptions.html#advancedoptions](https://auth0.github.io/auth0-react/interfaces/auth0_provider.auth0provideroptions.html#advancedoptions)

However, I did find this SO post that showed a potential workaround to allow more than one audience to be validated within the [ASP.NET](http://ASP.NET) core configuration:

- [c# - GetTokenAsync returns 2 audiences in ASP.NET Core 2.1 using auth0 - Stack Overflow](https://stackoverflow.com/questions/51799912/gettokenasync-returns-2-audiences-in-asp-net-core-2-1-using-auth0)

---

<div class="post-metadata">

**Author:** ![bvlasonjic](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bvlasonjic/32/30473_2.png) [@bvlasonjic](https://community.auth0.com/u/bvlasonjic)\
**Post date:** [July 13, 2021, 8:29am UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941/4 "2021-07-13T08:29:00Z")

</div>

Thank you for the quick reply @sgo !

Thank you for the provided information. After spending hours of hitting my head against a wall, I decided it would be easier to post a question here. Should I have kept hitting my head a little longer it probably would have occurred to me to google out something for those 2 audiences and I would have probably found that post.

Either way, thank you very much, the workaround within the asp .net core configuration solved the problem. Hopefully, this post will help someone else as well.

Keep up the good work and best of luck to you!

---

<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:** [July 13, 2021, 8:50am UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941/5 "2021-07-13T08:50:39Z")

</div>

Perfect! Glad to hear that!

---

<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:** [July 28, 2021, 8:51am UTC](https://community.auth0.com/t/401-bearer-error-invalid-token-the-audience-is-invalid/65941/6 "2021-07-28T08:51:22Z")

</div>

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