2012-10-13 11 views
5

node.jsのWS REST APIにアクセスしたい私はoauth_consumer_keyoauth_tokenとAPIエンドポイントを持っています。 oauth_signature_methodはHMAC-SHA1です。ノードでOAuthリクエストを送信する方法

ノードでOAuthリクエストを送信するにはどうすればよいですか?

要求ヘッダーを生成するモジュール/ライブラリはありますか?

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

  • UPDATE 2012年10月14日:私は何を期待して、関数のようなものです。ソリューションを追加する。

私は以下のコードを使用しています。

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

答えて

9

私たちは、これは合理的で便利なようで、完全なノードさえずりパッケージの詳細ですhttps://github.com/ciaranj/node-oauth

+6

このnpmモジュールでは、各部分の内容について、より多くのドキュメントまたは少なくともいくつかの注釈/コメントが必要です。私はOAuthが標準だと知っていますが、プロバイダーが誰で、どのサービスにアクセスしたいのかによって、異なるプロバイダーが異なることを要求/期待しています。例への彼のリンクも死んでいます。 OAuthで何をすべきか正確に知らない人にとっては非常に不満であり、失望しています。 – user137717

関連する問題