I tried to use the automatic code for Node.js to Get Management API Access Tokens for Production as shown in https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-access-tokens-for-production.
///////////////////////////////////////////////////////////
var axios = require("axios").default;
var options = {
method: 'POST',
url: 'https://my-apps.us.auth0.com/oauth/token',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
grant_type: 'client_credentials',
client_id: 'my-client-id',
client_secret: 'my-client-secret',
audience: 'https://my-apps.us.auth0.com/api/v2/'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
///////////////////////////////////////////////////////////
When I run this code, I get âError: Request failed with status code 401â. and it points to the line console.error(error);
it says: undefined.
Then I decided to test this request using python to check if I was passing the wrong data and in python I was able to retrieve the access token. The python code:
######################
import requests
payload = {
'grant_type': 'client_credentials',
'client_id': 'my-client-id',
'client_secret': 'my-client-secret',
'audience': 'https://my-apps.us.auth0.com/api/v2/'
}
response = requests.post(url='https://my-apps.us.auth0.com/oauth/token',
headers={'content-type': 'application/x-www-form-urlencoded'},
data=payload).json()
print(response)
##################
Iâm not used to javascript, so is there a known problem with axios or Node.js? Should I import or install some module or dependency? I need to use this in javascriptâŠ