Oauth request

API Discussion
Hi, trying to connect to new API, stuck on the oauth request.

I'd like to make a HTTP request in my node.js app
var wowtoken = {
url: "cant write this in post?",
headers: {"client_id": config.wow_clientid, "client_secret": config.wow_secret},
data: {"grant_type": "client_credentials"}
};
request.post(wowtoken, function(err, response, body){
if(err) {return console.log("oauth error");}
else {
//console.log things
...

This does not work and returns an unauthorized error:
Body = {"error":"unauthorized","error_description":"An Authentication object was not found in the SecurityContext"}

However posting a CURL works no worries
curl -u xxxxxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyy -d grant_type=client_credentials cantwritethisURLinpost]

Code also works if I don't user "headers" and "data" in my wowtoken variable and instead just use a combined URL var wowtoken = {
url: `cantwritethisURLinpost?client_id=${config.wow_clientid}&client_secret=${config.wow_secret}&grant_type=client_credentials`
};


Could someone kindly explain to a newbie how to correctly write this CURL as a http post request using headers?
Assuming you're using https://github.com/request/request there are a few ways to do it. Here's one way that matches your curl request:
var wowtoken = {
url: 'https://us.battle.net/oauth/token',
auth: {
user: config.wow_clientid,
pass: config.wow_secret,
}
data: {grant_type: 'client_credentials'}
}

Join the Conversation

Return to Forum