So I have this working using the following with requests:
async getToken() {
var body={
"client_id":clientId,
"client_secret":clientSecret,
"audience":"https://staging-site.auth0.com/api/v2/",
"grant_type":"client_credentials"
};
const grab=request.post({
"headers":{
"content-type": "application/json"
},
"url" : `${baseAuth0ApiUrl}/oauth/token`,
"json":body
});
let token=await grab;
};
This worked fine, however as part of a recent refactor I have been asked to phase out requests in favor of axios. Unfortunately I can’t seem to get the equivalent request to work:
async** getToken() {
let data={
"client_id":clientId,
"client_secret":clientSecret,
"audience":"https://staging-site.auth0.com/api/v2/",
"grant_type":"client_credentials"
};
let headers={
"content-type": "application/json"
};
let url = `${baseAuth0ApiUrl}/oauth/token`;
try {
const token = axios.post(url, {"headers":headers,"data":data});
let tokenParsed= await token;
return `${tokenParsed.data.token_type} ${tokenParsed.data.access_token}`;
}
catch (error){
console.error(error);
console.log("Token request failed!");
return false ;
}
}
I get a data: { error: 'access_denied', error_description: 'Unauthorized' }
from the axios call, can anyone tell me what it is I am doing wrong?