将我的 curl POST 转换为 Node JS OAuth2 Token 请求

Turn my curl POST into NodeJS OAuth2 Token reques

我有两个 curl 字符串,它们首先执行 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)
});