如何在Node中发送OAuth请求 [英] How to send the OAuth request in Node
本文介绍了如何在Node中发送OAuth请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想访问node.js中的WS REST API.我有oauth_consumer_key
和oauth_token
以及API端点. oauth_signature_method是HMAC-SHA1.
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.
如何在Node中发送OAuth请求?
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);
- 2012年10月14日更新.添加解决方案.
- 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);
});
推荐答案
我们使用 https://github. com/ciaranj/node-oauth
这篇关于如何在Node中发送OAuth请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文