【问题标题】:How to send the OAuth request in Node如何在 Node 中发送 OAuth 请求
【发布时间】:2012-10-04 02:51:09
【问题描述】:

我想访问 node.js 中的 WS REST API。我有oauth_consumer_keyoauth_token 以及API 端点。 oauth_signature_method 是 HMAC-SHA1。

如何在 Node 中发送 OAuth 请求?

是否有生成请求标头的模块/库?我期望的是这样的功能:

var httprequest = createRequest(url, method, consumer_key, token);

  • 2012 年 10 月 14 日更新。添加解决方案。

我正在使用下面的代码。

var OAuth = require('oauth').OAuth;

consumer = new OAuth('http://term.ie/oauth/example/request_token.php',
                    'http://term.ie/oauth/example/access_token.php',
                    'key', 'secret', '1.0',
                    null, 'HMAC-SHA1');

// Get the request token                    
consumer.getOAuthRequestToken(function(err, oauth_token, oauth_token_secret, results ){
    console.log('==>Get the request token');
    console.log(arguments);
});


// Get the authorized access_token with the un-authorized one.
consumer.getOAuthAccessToken('requestkey', 'requestsecret', function (err, oauth_token, oauth_token_secret, results){
    console.log('==>Get the access token');
    console.log(arguments);
});

// Access the protected resource with access token
var url='http://term.ie/oauth/example/echo_api.php?method=foo&bar=baz';
consumer.get(url,'accesskey', 'accesssecret', function (err, data, response){
    console.log('==>Access the protected resource with access token');
    console.log(err);
    console.log(data);
});

【问题讨论】:

    标签: node.js oauth module


    【解决方案1】:

    这更像是一个完整的节点 twitter 包,看起来精简且有用。 https://npmjs.org/package/twitter

    【讨论】:

    • 如果 token_request 不存在或未记录在案,则无用
    【解决方案2】:

    【讨论】:

    • 这个 npm 模块肯定需要更多的文档,或者至少需要一些关于每个部分的注释/cmets。我知道 OAuth 是一种标准,但不同的提供商需要/期望不同的东西,具体取决于提供商是谁以及您想要访问的服务。他与示例的链接也已失效。对于不确切知道在 OAuth 中做什么的人来说,这非常令人沮丧和失望。
    猜你喜欢
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 2014-01-24
    • 2021-05-08
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多