Node.js 获取访问令牌 [英] Node.js obtain access token

查看:33
本文介绍了Node.js 获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been given the following documentation (https://autovit.zendesk.com/hc/ro/articles/214077685-Obtinere-token-acces) and I want to call this api to get the access token for subsequent requests.

我不明白你怎么可以有多个参数

I do not understand how you can multiple parameters

-u 79: 70f8c636a503d50ac6c411597b4cc402

我收到的帖子请求是:我们能帮你什么吗?经销商合作伙伴 API Autovit

The post request I have been given is: How can we help? dealers partners 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,任何帮助将不胜感激.

I will use the request npm module and know that I have to do the following code, but I am not sure how to pass the client_id (in this case 79) and the client_secret, any help would be much appreciated.

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

以下文档 link 我可以看到客户端 ID和秘密是参数.所以也许我可以使用作为 json field1 参数如下???:

Following documentation link I can see that the client id and secret are parameters. So maybe I could use the as the json field1 parameters as below??? :

//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 选项用于基本身份验证.您可以将其作为基本 {auth_hash}"包含在 URL 或授权标头中.

The -u option is for Basic authentication. You can include it in the URL or in the Authorization header as "Basic {auth_hash}".

本文以一个例子展示了每一个 - https://www.haykranen.nl/2011/06/21/basic-http-authentication-in-node-js-using-the-request-module/

This article shows each in an example - https://www.haykranen.nl/2011/06/21/basic-http-authentication-in-node-js-using-the-request-module/

这篇关于Node.js 获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆