How to send the OAuth request in Node

僤鯓⒐⒋嵵緔 提交于 2020-01-31 03:57:25

问题


I want to access the WS REST API in node.js. I have the oauth_consumer_key and the oauth_token and the API end point. The oauth_signature_method is HMAC-SHA1.

How to send the OAuth request in Node?

Is there a module/library to generate the request headers? What I expect is a function like:

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

  • UPDATE 10/14/2012. Adding the solution.

I'm using the code below.

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

回答1:


We use https://github.com/ciaranj/node-oauth




回答2:


This is more of a complete node twitter package that seems streamlined and useful. https://npmjs.org/package/twitter



来源:https://stackoverflow.com/questions/12873463/how-to-send-the-oauth-request-in-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!