【问题标题】:Understanding complex curl command that uses oauth了解使用 oauth 的复杂 curl 命令
【发布时间】:2017-10-23 14:26:33
【问题描述】:

我有以下 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'参数中放了什么?目前我有:

form: { "params": "oauth","grant_type": "password", "username": username, "password": password }, 

但由于我无法阅读上述 curl 请求,我很难知道缺少什么(我再说一遍,我使用的是用户名/密码而不是 API 密钥)。谁能帮忙解决这个问题。

【问题讨论】:

  • 你试过curl -u user:password吗?
  • 它们不是真正的用户名/密码。我的问题是如何阅读 curl 命令,特别是在“表单”对象中放入什么(我的错误尝试在问题中)。我不确定你是如何回答我的问题的......具体来说,如何从“grant-type =”转换为请求的“form”部分
  • 我正在寻找有关如何阅读 curl 的知识,目的是了解在“表单”部分中放入什么

标签: node.js curl oauth


【解决方案1】:

您的curl 命令将:

  • 使用HTTP Basic authentication 和用户名user 和密码password
  • 到POST一个表单(标题字段Content-Type设置为application/x-www-form-urlencoded)
  • 在请求正文中使用 URL 编码的两个参数:
    • grant_type 参数设置为值 annonymised:mycompany:params:oauth:grant-type:apiKey
    • 和apikey 参数设置为myAPI Key
  • 到您调用的 URL 端点 myendpoint goes here。

在node.js 中使用request module,基于example for HTTP Auth 和form posting,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'
});

【讨论】:

  • 酷,告诉我进展如何。
  • 这是一个非常有帮助的解释——谢谢。我让它工作了一个我在我们的文档中找到了正确的参数......
  • 不客气,我很乐意为您提供帮助。但是,感谢 StackOverflow 上的某个人提供有用答案的最佳方式是 upvote 它。它还通过提供某些答案有用的提示(甚至在阅读之前)来帮助后来寻找问题答案的其他人。我在您的个人资料上看到您并没有真正投票(赞成或反对),但您确实应该。它不花钱,而且可以帮助他人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 2018-03-08
  • 1970-01-01
  • 1970-01-01
  • 2017-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多