2012-10-13 41 views
5

Tôi muốn truy cập API WS REST trong node.js. Tôi có oauth_consumer_keyoauth_token và điểm kết thúc API. Oauth_signature_method là HMAC-SHA1.Cách gửi yêu cầu OAuth trong Node

Cách gửi yêu cầu OAuth trong Nút?

Có mô-đun/thư viện để tạo tiêu đề yêu cầu không? Những gì tôi mong đợi là một chức năng như:

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

  • CẬP NHẬT 2012/10/14. Thêm giải pháp.

Tôi đang sử dụng mã bên dưới.

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

Trả lời

9

Chúng tôi sử dụng https://github.com/ciaranj/node-oauth

+6

mô-đun npm này chắc chắn cần thêm tài liệu hoặc ít nhất một số ghi chú/nhận xét về mỗi phần là gì. Tôi biết OAuth là một tiêu chuẩn, nhưng các nhà cung cấp khác nhau yêu cầu/mong đợi những thứ khác nhau tùy thuộc vào nhà cung cấp là ai và dịch vụ nào bạn muốn truy cập. Mối liên hệ của anh với các ví dụ cũng đã chết. rất bực bội và gây thất vọng cho bất kỳ ai không biết chính xác phải làm gì trong OAuth. – user137717

Các vấn đề liên quan