簡體   English   中英

將我的curl POST轉換為NodeJS OAuth2令牌要求

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM