Node.js中的OAuth1.0标头 [英] OAuth1.0 header in Node.js

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

问题描述

我一直在使用 API 通过使用OAuth1.0的邮递员成功. 现在,我正在构建一个调用此API的API,但是在尝试设置OAuth1.0的javascript中的等效项时遇到了麻烦. 标题看起来像这样:

I've been using an API via postman that uses OAuth1.0, successfully. Now I'm building an API that calls this API but I'm having trouble when trying to set up the equivalent in javascript of the OAuth1.0. The header looks like this:

'Authorization': 'OAuth oauth_consumer_key="XXX",oauth_token="XXX",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1559312415",oauth_nonce="XXX",oauth_version="1.0",oauth_signature="XXX"'

我的问题与 oauth_nonce oauth_signature 有关. 我可以用来生成这两个参数的哈希函数是什么.
另外,我正在使用 AXIOS 进行请求.
谢谢您的宝贵时间.

My problem is related to oauth_nonce and oauth_signature. What are the hash function that I can use to generate those 2 parameters.
Also, I'm using AXIOS for the request.
Thanks for your time.

推荐答案

我能够解决此问题,而不是通过编码哈希函数,而是通过使用如何使用OAuth 1.0调用API?

I was able to solve this issue, not by coding the hash funciont but by doing the request with Request as you can follow with this thread : How to call the API using OAuth 1.0?

事实是我正在使用 Axios ,但我没有找到解决方法,一个OAuth1.0. 使用请求",您可以使用:

The fact is I was using Axios and I wasn't finding a solution to how to make an OAuth1.0 with it. With Request, you can make it by using:

    request.get('https://api.twitter.com/1.1/users/show.json', {
  oauth:{
    consumer_key:'...',
    consumer_secret:'...',
    token:'...',
    token_secret:'...'
  }}, function (err, res, body) {})

如我所链接的帖子所述.

as said by the post that I linked.

这篇关于Node.js中的OAuth1.0标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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