2012-10-13 27 views
5

node.js.'deki WS REST API'sine erişmek istiyorum. oauth_consumer_key ve oauth_token ve API bitiş noktası var. Oauth_signature_method, HMAC-SHA1'dir.Düğüm içinde OAuth isteği nasıl gönderilir

Düğümde OAuth isteği nasıl gönderilir?

İstek başlıklarını oluşturmak için bir modül/kitaplık var mı?

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

  • GÜNCELLEME 2012/10/14: Ne bekliyoruz bir işlev gibidir. Çözüm ekleniyor.

Aşağıdaki kodu kullanıyorum.

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

cevap

9

Biz bu aerodinamik ve kullanışlı görünüyor komple bir düğüm twitter paketinin daha https://github.com/ciaranj/node-oauth

+6

Bu npm modülünde, her bir parçanın ne olduğu hakkında daha fazla dokümantasyon veya en azından bazı notlar/yorumlar gereklidir. Biliyorum OAuth bir standarttır, ancak farklı sağlayıcılar, sağlayıcının kim olduğuna ve hangi hizmete erişmek istediğinize bağlı olarak farklı şeyler gerektirir/bekler. Örneklere olan bağlantısı da öldü. OAuth'da tam olarak ne yapacağını bilmeyen herkes için çok sinir bozucu ve hayal kırıklığı yaratıyor. – user137717

İlgili konular