Access token from React app not valid on Custom API

Hello !

I’m new here, so I think my problem should be simple to fix but I really don’t understand what is going on.

I followed tutorials to create a NestJs API, now I’m creating my front-end using React with auth0-react.

Once I’m login, the Access Token I got by using the getAccessTokenSilently() function seem to not be valid for my Custom API (401 Unauthorize). (edit: I send it has a Bearer token etc, everything seem fine on this side)

When I use the /oauth/token route to get a token, the token is valid on the Custom API so I think the probleme must come from some configuration or something I’ve missed.

So, Auth0 side I’ve :

  • Front-react : the Application
  • Back-nest : the API

I’ve nothing more to add right now, I’ve no special config or anything …
If you have any question, I will be glad to answer you !

Thanks for reading this, and thanks in advance to thoses that are gonna try to solve my mistery !

EDIT :

TOPIC CLOSE, I found my answer right after writing this post … I was searching since too long lol
I was missing the audience parameter in my react app.

In addition, your client application must ensure that it performs an authorization request that states that it wants to receive an access token suitable to your API. It can do this by including an audience parameter where the value is the identifier you configured previously for the API.

1 Like

Hi @xeewi ,

Welcome to the Auth0 Community!

Glad that you have resolved this issue and appreciate you sharing the solution with us! :pray:

1 Like