[英]Turn my curl POST into NodeJS OAuth2 Token reques
我有两个卷曲字符串,它们首先执行OAuth2-Token-Request,然后从API加载数据。 现在,我想将其包含在node.js插件中,因此我需要在插件中执行此操作。
卷曲:
curl -X POST -d 'grant_type=password&client_id=8d3c1664-05ae-47e4-bcdb-477489590aa4&client_secret=4f771f6f-5c10-4104-bbc6-3333f5b11bf9&username=email&password=password' https://api.hello.is/v1/oauth2/token
Test.js:
var request = require('request');
request({
url: 'https://api.hello.is/v1/oauth2/token',
mehtod: "POST",
auth: {
username: 'email',
password: 'password'
},
form: {
'grant_type': 'password',
'client_id': '8d3c1664-05ae-47e4-bcdb-477489590aa4',
'client_secret': '4f771f6f-5c10-4104-bbc6-3333f5b11bf9'
}
}, function(err, res) {
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token)
});
问题是,我得到的唯一信息是: { code: 405, message: 'Method not allowed' }
而CURL给了我正确的access_token。
有人可以帮忙吗? 谢谢!!
也许尝试:
var request = require('request');
request({
url: 'https://api.hello.is/v1/oauth2/token',
mehtod: "POST",
form: {
username: 'email',
password: 'password',
grant_type: 'password',
client_id: '8d3c1664-05ae-47e4-bcdb-477489590aa4',
client_secret: '4f771f6f-5c10-4104-bbc6-3333f5b11bf9'
}
}, function(err, res) {
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.