Node.js获取访问令牌

我已经得到了以下文档( https://autovit.zendesk.com/hc/ro/articles/214077685-Obtinere-token-acces ),我想调用这个API来获取访问令牌为后续请求。

我不明白你如何可以多个参数

-u 79: 70f8c636a503d50ac6c411597b4cc402 

我提出的要求是:我们如何提供帮助? 经销商合作伙伴API Autovit

 POST https://ssl.autovit.ro/api/open/oauth/token/ -X POST -H "Accept: application / json" -u 79: 70f8c636a503d50ac6c411597b4cc402 [client_id and client_secret] -d "username = test24 @ test. pl " [username dealer Autovit] -d" password = 123456789 " [Autovit user password] -d" grant_type = password " 

[]中的代码是提供者的注释

我将使用请求npm模块,并知道我必须做下面的代码, 但我不知道如何通过client_id(在这种情况下79)和client_secret ,任何帮助将不胜感激。

 request({ url: 'https://ssl.autovit.ro/api/open/oauth/token/', method: 'POST', auth: { user: 'test24 @ test. pl', pass: '123456789' }, form: { 'grant_type': 'password' } }, function(err, res) { var json = JSON.parse(res.body); console.log("Access Token:", json.access_token); }); 

下面的文档链接,我可以看到,客户端ID和密码是参数。 所以也许我可以使用下面的json field1参数? :

 //Load the request module var request = require('request'); //Lets configure and request request({ url: 'https://modulus.io/contact/demo', //URL to hit qs: {from: 'blog example', time: +new Date()}, //Query string data method: 'POST', //Lets post the following key/values as form json: { field1: 'data', field2: 'data' } }, function(error, response, body){ if(error) { console.log(error); } else { console.log(response.statusCode, body); } }); 

-u选项用于基本身份validation。 您可以将其作为“基本{auth_hash}”包含在URL中或授权标头中。

这篇文章显示了每个例子 – https://www.haykranen.nl/2011/06/21/basic-http-authentication-in-node-js-using-the-request-module/