# JWT audience invalid when posting to controller with \[Authorize\]

**URL:** <https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766>\
**Category:** Get Help\
**Tags:** jwt, id\_token, aspnet-core\
**Created:** [July 3, 2018, 2:07pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766 "2018-07-03T14:07:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![airmaster](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@airmaster](https://community.auth0.com/u/airmaster)\
**Post date:** [July 3, 2018, 2:07pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/1 "2018-07-03T14:07:51Z")

</div>

Platform: C#, Visual Studio [ASP.NET](http://ASP.NET) 2.1 Core

I am trying to POST a form to a controller, and am using the AuthHttp service to make the post inside of a service:

> ```
> create(volunteer) {
> return this.authHttp.post(this.volunteerEndpoint + '/CreateVolunteer', volunteer)
> .map(result => result.json());
> }
> 
> ```

Inside of my **startup.cs** file, I have the standard code in ConfigureServices:

> ```
> services.AddAuthentication(options =>
> {
> options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
> options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
> 
> }).AddJwtBearer(options =>
> {
> options.Authority = "https://mydomain.auth0.com/";
> options.Audience = "https://api.mydomain.com/";
> });
> 
> ```

along with the app.UseAuthentication() call in Configure.

Inside of **auth.service.ts** , I initialize the authentication.

> ```
> auth0 = new auth0.WebAuth({
> clientID: AUTH_CONFIG.clientID,
> domain: 'auth.mydomain.tech',
> responseType: 'token id_token',
> audience: `https://${AUTH_CONFIG.domain}/userinfo`,
> redirectUri: AUTH_CONFIG.callbackURL,
> scope: 'openid email profile'
> });
> 
> ```

With the following variables

> export const AUTH\_CONFIG: AuthConfig = {  
> clientID: ‘xxxClientIDStringxxx’,  
> domain: ‘[mydomain.auth0.com](http://mydomain.auth0.com)’,  
> callbackURL: ‘[http://localhost:62659/](http://localhost:62659/)’  
> };

In the controller, I have post with the authorize tag

> ```
> [HttpPost("CreateVolunteer")]
> [Authorize]
> public async Task<IActionResult> CreateVolunteer([FromBody] VolunteerSaveResource volunteerResource)
> {
> if (!ModelState.IsValid) return BadRequest(ModelState);
> ---- code ----
> return Ok(result);
> }
> 
> ```

When I call the controller, I get the error from postman : WWW-Authenticate →Bearer error=“invalid\_token”, error\_description=“The audience is invalid”

I have read documentation, and I think the problem is that my the aut from the token doesn’t match the audience, but I think I have some fundamental misunderstanding of how to make that right. If I grab the HAR of the request, I see the bearer, and decoding it, I get aud equaling the xxxClientIDStringxxx as above.

So, is my problem in the startup.cs file, with the audience that I have specified? What is the relationship between the API and the Application? Do I need to somehow specify an audience there that is the same as the Application?

---

<div class="post-metadata">

**Author:** ![airmaster](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@airmaster](https://community.auth0.com/u/airmaster)\
**Post date:** [July 3, 2018, 9:00pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/2 "2018-07-03T21:00:12Z")

</div>

Matt was nice enough to assist me. Here is what worked.

The key link is here: [https://auth0.com/docs/quickstart/spa/angular2/03-calling-an-api](https://auth0.com/docs/quickstart/spa/angular2/03-calling-an-api)

**I needed to make sure**

1. that the audience in **startup.cs** (_options.Audience_) and **auth.service.ts** was exactly the same.
2. make sure that the authority in **startup.cs** (_options.Authority_) matches the one stored in “access\_token”, which you can verify at [http://jwt.io](http://jwt.io).

The problem then is that I needed to set the “token” field in local storage to the “access\_token”. I stored “idToken” then as “id\_token”, which contains the user personal information. “access\_token” doesn’t contain user information.

My confusion was due to the application Quick Start guide, showed:

> auth0 = new auth0.WebAuth({  
> clientID: 'xxClientIDxx,  
> domain: ‘[mydomain.auth0.com](http://mydomain.auth0.com)’,  
> responseType: ‘token id\_token’,  
> audience: ‘[https://mydomain.auth0.com/userinfo](https://mydomain.auth0.com/userinfo)’,  
> redirectUri: ‘[http://localhost:3000/callback](http://localhost:3000/callback)’,  
> scope: ‘openid’  
> });

This is really to grab user info, and I changed it as above, and a proper reading of the first link should have cleared it up for me. I think Matt indicated that I had to change it also because I was using a custom domain, but that was beyond me.

---

<div class="post-metadata">

**Author:** ![imsam67](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/imsam67/32/12846_2.png) [@imsam67](https://community.auth0.com/u/imsam67)\
**Post date:** [September 3, 2018, 10:30pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/3 "2018-09-03T22:30:23Z")

</div>

I’m having the same exact problem and keep reading your reply again and again for it to sink in but so far it’s not working.

Are you sending the id\_token or access\_token to the API when making a call from frontend client?

---

<div class="post-metadata">

**Author:** ![afuller](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/afuller/32/12751_2.png) [@afuller](https://community.auth0.com/u/afuller)\
**Post date:** [March 8, 2019, 9:02pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/4 "2019-03-08T21:02:16Z")

</div>

I’m having the same problem. I’m using the id\_token because when I try the access\_token it tells me it’s malformed. Have you figured this out?

---

<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:** [August 30, 2019, 11:05am UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/5 "2019-08-30T11:05:56Z")

</div>

Hey there!

Sorry for such huge delay in response! We’re doing our best in providing you with best developer support experience out there, but sometimes our bandwidth is not enough comparing to the number of incoming questions.

Wanted to reach out to know if you still require further assistance?

---

<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:** [September 3, 2019, 1:55pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/6 "2019-09-03T13:55:04Z")

</div>



---

<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 15, 2022, 11:41pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/7 "2022-09-15T23:41:49Z")

</div>

Here is an FAQ that addresses this error:

[https://community.auth0.com/t/audience-is-invalid-error/84588](https://community.auth0.com/t/audience-is-invalid-error/84588)

---

<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 15, 2022, 11:42pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/8 "2022-09-15T23:42:06Z")

</div>



---

<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 15, 2022, 11:42pm UTC](https://community.auth0.com/t/jwt-audience-invalid-when-posting-to-controller-with-authorize/12766/9 "2022-09-15T23:42:34Z")

</div>


