User Access Token by Username and Password

I am trying to fetch a user access token on a node application (not an express app) by providing the username and password by doing something like so:

const options = { method: 'POST',
  url: 'https://MY_DOMAIN/oauth/token',
  headers: { 'content-type': 'application/x-www-form-urlencoded' },
  form:
   { grant_type: 'password',
     username: MY_USERNAME,
     password: MY_PASSWORD,
     audience: MY_API_IDENTIFIER,
     scope: MY_SCOPE,
     client_id: MY_YOUR_CLIENT_ID,
     client_secret: MY_CLIENT_SECRE
   }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

However I keep getting the following error:

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

What am I missing? Any help will be much appreciated.

Does it work when you do a cURL command in the terminal with the same data, as shown on the right side of Authentication API Explorer ?

Yes, same response :frowning:

Hi

I’m having a similar issue. Did you ever resolve it?

Regards

Richard