Auth0 Home Blog Docs

Invalid token on Authorization Extension



I’m currently having some issues regarding the authorization extension. I always get a “Invalid token” response.
What I want to do is set the role after user creation via api.
I’ll omit the code from the user creation, since it’s working.

//auth0ClientId -> My main app client id, the one I’m using for user signup
//auth0ClientSecret -> Secret from the app I’m using for user signup
//auth0AuthorizationAudience-> The audience from authorization-extension in the APIs page, which is urn:auth0-authz-api

const authorizationTokenData = {
grant_type: “client_credentials”,

//auth0Endpoint -> My tenant, the one I get from the domain of my app
const resultAuthorizationToken = await${'auth0Endpoint')}/oauth/token, data);

//auth0AuthorizationEndpoint -> The URL I get in the API section in the Authorization Extension page
//user.user_id -> the id of the user I’ve created. I get it in this format: auth0|HASH
const resultAuthorization = await axios.patch(${'auth0AuthorizationEndpoint')}/users/${user.user_id}/roles, [‘seller’], {
headers: {
Authorization: Bearer ${};

The response is:

statusCode: 401,
error: ‘Unauthorized’,
message: ‘Invalid token’,
attributes: { error: ‘Invalid token’

I’ve granted access to all scopes in the machine to machine section of the authorization extension api. I’ve also enabled client grant types on my app and authorization extension app.
I’m with this issue since yesterday. I tried with the same code from here

Any ideas?



Geez, after I posted this, I realized a typo. Instead of authorizationTokenData in the post for the token, I sent “data”. Sometimes you just need to see it from another point of view haha.

1 Like

Glad you were able to find it!

closed #4

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