简体   繁体   English

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

[英]Node JS requesting token using oauth2 not working

I am unable to get back a token by using the simple 'request' npm module for oauth token authentication. 我无法通过使用简单的'request'npm模块进行oauth令牌身份验证来找回令牌。

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);

Getting back the following error: 找回以下错误:

 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 }

Any idea why am I getting a ENOTFOUND error? 知道为什么我会收到ENOTFOUND错误吗? Not sure why it's not appending the full URL either. 不知道为什么也没有附加完整的URL。

These are the two parts of the URL: 这是URL的两个部分:

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

Please help. 请帮忙。 I tried everything!!! 我尝试了一切!!!

Wow.... dumb mistake. 哇....愚蠢的错误。 I used https://www.rest.synthesio.com instead of https://rest.synthesio.com 我使用https://www.rest.synthesio.com而不是https://rest.synthesio.com

Thanks for the help nonetheless guys! 谢谢你们的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM