# InvalidTokenError: Invalid Compact JWS

**URL:** <https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [May 10, 2023, 10:53am UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607 "2023-05-10T10:53:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thisisdjfresh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thisisdjfresh/32/46018_2.png) [@thisisdjfresh](https://community.auth0.com/u/thisisdjfresh)\
**Post date:** [May 10, 2023, 10:53am UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607/1 "2023-05-10T10:53:19Z")

</div>

Hi there, ive followed the docs and have set this up previously but struggling with this:

Im using auth0 on my front end and backend, but there seems to be a problem, im getting this error: InvalidTokenError: Invalid Compact JWS

node\_modules/express-oauth2-jwt-bearer/dist/index.js:403:24 {  
status: 401,  
statusCode: 401,  
headers: {  
‘WWW-Authenticate’: ‘Bearer realm=“api”, error=“invalid\_token”, error\_description=“Invalid Compact JWS”’  
},  
code: ‘invalid\_token’  
}

Here is the api check: const jwtCheck = auth({  
audience: ‘h t t p s://myurl.com’,  
issuerBaseURL: ‘[https://me.eu.auth0.com/](https://me.eu.auth0.com/)’,  
tokenSigningAlg: ‘RS256’,  
});

auth provider in index.js \<Auth0Provider  
domain=“[me.eu.auth0.com](http://me.eu.auth0.com)”  
clientId={{MY CLIENT ID}}  
redirectUri={window.location.origin}  
audience=“h t t p s://myurl.com”  
\>

And the front end getting the token and making the request const authLink = setContext(async (\_, { headers }) =\> {  
const token = await getAccessTokenSilently();  
return {  
headers: {  
…headers,  
Authorization: `Bearer ${token}`,  
},  
};  
});

const client = new ApolloClient({  
link: authLink.concat(httpLink),  
cache: new InMemoryCache(),  
});

The token im sending is identical to the one the API is recieving

Can anyone please help?

---

<div class="post-metadata">

**Author:** ![thisisdjfresh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thisisdjfresh/32/46018_2.png) [@thisisdjfresh](https://community.auth0.com/u/thisisdjfresh)\
**Post date:** [May 10, 2023, 12:56pm UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607/2 "2023-05-10T12:56:30Z")

</div>

To add to this it appears that the access token is a JWE not a JWT token though there is nowhere i can set this and i havent changed any oauth settings so this should i believe default to JWT?

---

<div class="post-metadata">

**Author:** ![ramandeep](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ramandeep/32/47127_2.png) [@ramandeep](https://community.auth0.com/u/ramandeep)\
**Post date:** [December 12, 2023, 5:22pm UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607/3 "2023-12-12T17:22:33Z")

</div>

Did you manage to resolve this issue, I’m experiencing something similar.

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [February 17, 2025, 9:43pm UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607/4 "2025-02-17T21:43:05Z")

</div>

Hi @thisisdjfresh

Welcome to the Auth- Community!

I am sorry about the late reply to your inquiry.

When you login to Auth0 and don’t specify an **audience** , you will get an [opaque access token](https://auth0.com/docs/secure/tokens/access-tokens#opaque-access-tokens). It looks like a regular JWT, but actually it’s a self contained encrypted JWT. The only way to validate an opaque token is to call the server that issued the token, in this case the `/userinfo` endpoint.

In order to get an [JWT](https://auth0.com/docs/secure/tokens/access-tokens#jwt-access-tokens). You need to [create a custom api](https://auth0.com/docs/get-started/auth0-overview/set-up-apis). Then use this as the `audience` in your react app to login:

```auto
<Auth0Provider
      domain="YOUR_AUTH0_DOMAIN"
      clientId="YOUR_AUTH0_CLIENT_ID"
      redirectUri={window.location.origin}
      audience="YOUR_API_IDENTIFIER"

```

This will provide you a JWT when you call the `getAccessTokenSilently()` method.

Then you can specify the same API as the audience in your api:

```auto
const jwtCheck = auth({
  issuerBaseURL: "https://<DOMAIN>", 
  audience: "YOUR_API_IDENTIFIER",
});

```

Hope this is helpful to the issue that you were facing.

If you have any other questions, feel free to leave a reply or post again on the community!

Kind Regards,  
Nik

---

<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:** [March 3, 2025, 9:44pm UTC](https://community.auth0.com/t/invalidtokenerror-invalid-compact-jws/106607/6 "2025-03-03T21:44:09Z")

</div>

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