I am trying to write a little CLI utility to auto-generate a ~/.netrc file and store the github oauth token inside.
I am able to get a new token from github when I run curl. This works:
curl -u 'my_username' -d '{"scopes":["repo"],"note":"Help example"}' \
https://api.github.com/authorizations
https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
I want to do the exact same thing, but with Superagent from my node app.
This does not work. I simply get a 403 response:
function getGitToken(user, pwd) {
console.log(user + "|" + pwd)
var url = "https://api.github.com/authorizations";
request
.post(url)
.auth(user, pwd)
//.send({"username": "#####"})
.send({"scopes":["repo"], "note":"Easy-netrc generated"}) //TODO: add support for shell prompt name
.end(function(res){
console.log(res);
console.log("res.body", res.body);
});
}
Shouldn't I be able to emulate what curl does? Am I missing certain headers? Any thoughts?
Github docs for reference:
https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
http://developer.github.com/v3/oauth/#create-a-new-authorization