I am getting an Unauthorized error with HTTP status 401 when calling https://my-tenant.au.auth0.com/oauth/token from a rule. I have checked that I am using the correct tenant name in URL, client_id and client_secret and get a successful response when I call the endpoint using curl locally.
Is there anything wrong with this request syntax, otherwise what else could be going wrong??
Code in rule:
var request = require("request");
var options_for_token_request = { method: 'POST',
url: "https://my-tenant.au.auth0.com/oauth/token",
body: '{"client_id":" ","client_secret":" ","audience":"urn:auth0-authz-api","grant_type":"client_credentials"}',
contentType: 'application/json' };
request(options_for_token_request, function (error, response, body) {
if (error) { throw new Error(error); }
console.log(response.statusCode);
console.log(body);
});