node.js – 如何在Node中发送OAuth请求

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

如何在Node中发送OAuth请求?

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

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

>更新10/14/2012.添加解决方案.

我正在使用下面的代码.

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,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',data,response){
    console.log('==>Access the protected resource with access token');
    console.log(err);
    console.log(data);
});

解决方法

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...