微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

解决方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐