2012-10-13 11 views
5

Desidero accedere all'API WS REST in node.js. Ho il oauth_consumer_key e il oauth_token e il punto finale dell'API. L'oauth_signature_method è HMAC-SHA1.Come inviare la richiesta OAuth nel nodo

Come inviare la richiesta OAuth nel nodo?

Esiste un modulo/libreria per generare le intestazioni di richiesta? Quello che mi aspetto è una funzione come:

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

  • UPDATE 2012/10/14. Aggiungere la soluzione

Sto usando il codice qui sotto.

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

risposta

9
+6

questo modulo npm richiede sicuramente più documentazione o almeno alcune note/commenti su ciò che ogni pezzo è. So che OAuth è uno standard, ma provider diversi richiedono/si aspettano cose diverse a seconda di chi sia il provider e di quale servizio si desidera accedere. Anche il suo link agli esempi è morto. molto frustrante e deludente per chiunque non sappia esattamente cosa fare in OAuth. – user137717

Problemi correlati