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);
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);
});
We use https://github.com/ciaranj/node-oauth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With