节点JS使用oauth2请求令牌不起作用

时间:2016-07-01 19:01:08

标签: javascript node.js request oauth2

我无法通过使用简单的“请求”来取回令牌。用于oauth令牌认证的npm模块。

var request = require('request');

var payload = {
    'grant_type': "password",
    'username': user,
    'password': pass,
    'client_id': client_id,
    'client_secret': client_secret,
    'scope' : "internal"
};

var options = {
    method: 'POST',
    url: host,
    headers: {
        //'accept': "application/json",
        'content-type': "application/x-www-form-urlencoded"
    },
    form: JSON.stringify(payload)
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        var info = JSON.parse(body);
        console.log(info);
    } else {
        console.log(error);
        //console.log(response.statusCode);
    }
}

request(options, callback);

取回以下错误:

 Error: getaddrinfo ENOTFOUND www.rest.synthesio.com www.rest.synthesio.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)


code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'www.rest.synthesio.com',
  host: 'www.rest.synthesio.com',
  port: 443 }

知道我为什么会收到ENOTFOUND错误?不确定为什么它没有追加完整的网址。

以下是网址的两部分:

hosturl:'https://www.rest.synthesio.com/' tokenPath:security/v1/oauth/token

请帮忙。我尝试了一切!!!

1 个答案:

答案 0 :(得分:0)

哇......愚蠢的错误。我使用https://www.rest.synthesio.com代替https://rest.synthesio.com

感谢你们的帮助!