Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send the OAuth request in Node

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);
});
like image 590
Jeffrey Avatar asked Oct 13 '12 13:10

Jeffrey


1 Answers

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

like image 101
skovalyov Avatar answered Nov 09 '22 13:11

skovalyov