我正在嘗試編寫一個小的CLI實用程序來自動生成〜/ .netrc文件並在其中存儲github oauth令牌。Superagent調用發出Github宣誓令牌在node.js中失敗應用
當我運行卷曲時,我能夠從github獲得新的令牌。 這工作:
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
我想要做同樣的事情,但Superagent從我節點應用程序。
This does not work。我只是得到403響應:
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);
});
}
我不應該能夠模擬做什麼捲曲?我是否缺少某些標題?有什麼想法嗎?
Github的文檔以供參考:
https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
http://developer.github.com/v3/oauth/#create-a-new-authorization