我正在尝试编写一个小 CLI 实用程序来自动生成 ~/.netrc 文件并将 github oauth 令牌存储在其中。
运行 curl 时,我可以从 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。
这不起作用。我只是得到一个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);
});
}
我不应该能够模仿 curl 的作用吗?我错过了某些标题吗?有什么想法吗?
Github 文档供参考:
https ://help.github.com/articles/creating-an-oauth-token-for-command-line-use
http://developer.github.com/v3/oauth/#create-a -新授权