Access_denied", "Unauthorized" While attempting to get API Auth Token

Hello,

I have a React application and a .NET Core Web API, both registered and secured with Auth0.

I have had no issues getting the React app wired up to Auth0, and can log my test users in without issue.

When trying to get an auth token for the API however, I keep getting an error:

{error: "access_denied", error_description: "Unauthorized"}

The POST request is based on the code provided in the Auth0 dashboard, under the “test” tab for my API.

My steps are:

  1. Log in user to React app
  2. Execute an axios call to request an auth token for the API
  3. Attach this token as an Authentication header for API requests.
  4. Winning!

However, I’m currently not winning, and being blocked at step 2. Here’s the code that makes the request for the token.

I am a JS/React rookie so, it’s likely I’ve made a mistake:

export async function getApiAuthToken() {
  var result;
  await axios({
method: "post",
url: "https://aimanager.us.auth0.com/oauth/token",
headers: { "content-type": "application/json" },
body:
  '{"client_id":"<MY_CLIENT_ID","client_secret":"<MY_SECRET>","audience":"<MY_AUDIENCE>","grant_type":"client_credentials"}',
  })
.then((response) => (result = response))
.catch(handleError);
  return result;
}

Hi @dmorin,

Welcome to the Community!

It looks like you are trying to use the client credentials grant in your react, single page app. This is not allowed.

What are you trying to do specifically?

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