# Changing audience field for JWT authentication response

**URL:** <https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [January 26, 2023, 7:13pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052 "2023-01-26T19:13:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nolanl13](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolanl13/32/42929_2.png) [@nolanl13](https://community.auth0.com/u/nolanl13)\
**Post date:** [January 26, 2023, 7:13pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/1 "2023-01-26T19:13:12Z")

</div>

No matter what I do the “aud” feild of my JWT for my client application returns as my Client ID, I have no idea why? I’ve even set the default audience to the name of my API.

If anyone can help me it would be so greatly appreciated.

---

<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:** [January 26, 2023, 10:41pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/3 "2023-01-26T22:41:04Z")

</div>

Hey there @nolanl13 welcome to the community!

> [@nolanl13](#):
>
> No matter what I do the “aud” feild of my JWT for my client application returns as my Client ID, I have no idea why? I’ve even set the default audience to the name of my API.

Which SDK are you using and how exactly are you getting the token? Feel free to share any config related code you think may help.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![nolanl13](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolanl13/32/42929_2.png) [@nolanl13](https://community.auth0.com/u/nolanl13)\
**Post date:** [January 27, 2023, 11:12am UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/4 "2023-01-27T11:12:53Z")

</div>

Hey, thank you so much for your response. I’ve been super stuck on this for a couple of days.  
So I am using Nestjs and to build a backend service, but need to fake a client authentication flow so I can test properly and create users in a separate DB etc.

I have an application set up with the basic login project you guys provide (regular web app with node.js), and I have a separate API configured to protect routes in my backend.

What I am currently doing is logging the user in using the sample -login project, going into he network tab and retrieving the response “access token” after successful login. I am then trying to use this token to send a cURL request to auth0 to exchange it for an API access token, but I keep getting this error: `{"error":"invalid_grant","error_description":"Invalid authorization code"}%`  
When I decode the JWT the ‘aud’ is set to the value of the Client\_ID and not to the value of the API identifier which is what I think the problem may be.?

here is my set-up code for the Client project in the server.js file.

```auto
const config = {
  authRequired: false,
  auth0Logout: true,
  secret: process.env.SECRET,
  baseURL: "http://localhost:8080",
  clientID: process.env.CLIENT_ID,
  issuerBaseURL: process.env.ISSUER_BASE_URL,
  clientSecret: process.env.CLIENT_SECRET,
};

...

app.use(
  auth({
    ...config,
    authorizationParams: {
      response_type: "code id_token",
      audience: process.env.AUTH0_AUDIENCE,
    },
  })
);

```

this AUTH0\_AUDIENCE is set to the value of my API identifier not to the name of the client id.  
but shows up differently in the jwt token. I don’t know if that’s actually what the issue is? but its very confusing.

any hints or ideas would be very greatly appreciated 🙂

---

<div class="post-metadata">

**Author:** ![nolanl13](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolanl13/32/42929_2.png) [@nolanl13](https://community.auth0.com/u/nolanl13)\
**Post date:** [January 27, 2023, 2:10pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/5 "2023-01-27T14:10:55Z")

</div>

my response has been detailed above, forgot to make it a reply 🙂

---

<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:** [January 27, 2023, 10:10pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/6 "2023-01-27T22:10:20Z")

</div>

Hey @nolanl13 no problem, happy to help where I can!

> [@nolanl13](#):
>
> What I am currently doing is logging the user in using the sample -login project, going into he network tab and retrieving the response “access token” after successful login.

Do you mind sharing the example sample you’re working with? There’s definitely something off but it’s hard for me to tell without looking at the sample itself. It looks to be using a hybrid flow which given the `response_type`.

FWIW it’s worth it might be easier to user one of our SPA samples, [react](https://github.com/auth0-samples/auth0-react-samples/tree/master/Sample-01) for example. I know with that sample you’ll get an access token with the correct audience configured. You can just extract the access token from the “preview” of the `/token` call in the network tab without having to make any extra manual call:

 ![Screen Shot 2023-01-27 at 2.04.18 PM](https://global.discourse-cdn.com/auth0/original/3X/8/1/81d2da1d25f1a5a39a884bb30d09c27700a7408a.png)

Keep us posted!

---

<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:** [December 22, 2023, 11:54pm UTC](https://community.auth0.com/t/changing-audience-field-for-jwt-authentication-response/99052/7 "2023-12-22T23:54:32Z")

</div>

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