理解使用oauth的复杂curl命令
我有以下curl命令(删除公司的具体细节):
curl -v -u "user:password" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=annonymised:mycompany:params:oauth:grant-type:apiKey&apikey=myAPI Key" "myendpoint goes here"
我是CURL的新手,正在尝试使用nodejs的'request'模块将其转换为请求(请记住,我实际上使用的是用户名/密码而不是API密钥)。 我在“表单”参数中放什么? 目前我有:
form: { "params": "oauth","grant_type": "password", "username": username, "password": password },
但因为我不能读取上面的curl请求,我正在努力知道什么是缺less的(我重复一下,我使用用户名/密码,而不是API密钥)。 任何人都可以帮助这个请。
你的curl
命令将会:
- 使用用户名和密码
password
HTTP基本authentication - 发布一个表单(头文件中的
Content-Type
设置为application/x-www-form-urlencoded
) - 在请求的正文中使用两个URL编码的参数:
-
grant_type
参数设置为值为annonymised:mycompany:params:oauth:grant-type:apiKey
- 并将
apikey
参数设置为myAPI Key
-
- 到您称为
myendpoint goes here
的URL端点myendpoint goes here
。
使用node.js
的request
模块 ,基于HTTP Auth和表单发布的示例 , node.js
等效项如下所示:
var request = require('request'); request.post('myendpoint goes here').auth('user', 'password').form({ grant_type: 'annonymised:mycompany:params:oauth:grant-type:apiKey', apikey: 'myAPI Key' });