Is there an npm for oauth?



我想从节点服务器向yelp.com发出请求,但我需要在请求中使用OAuth.getParameterMap和其他OAuth函数。我想知道是否有任何具有我需要的功能的npm?

这是我迄今为止的代码:

app.post('/yelpApp', function (req, res)
{
    var auth = {
    consumerKey: conKey,
    consumerSecret: conSec,
    accessToken: accTok,
    accessTokenSecret: accTokSec,
    serviceProvider: {
      signatureMethod: "HMAC-SHA1"
      }
    };
    var terms = 'food';
    var near = 'London';
    var accessor = {
      consumerSecret: auth.consumerSecret,
      tokenSecret: auth.accessTokenSecret
    };
    parameters = [];
    parameters.push(['term', terms]);
    parameters.push(['location', near]);
    parameters.push(['callback', 'cb']);
    parameters.push(['oauth_consumer_key', auth.consumerKey]);
    parameters.push(['oauth_consumer_secret', auth.consumerSecret]);
    parameters.push(['oauth_token', auth.accessToken]);
    parameters.push(['oauth_signature_method', 'HMAC-SHA1']);
    var message = {
      'action': 'http://api.yelp.com/v2/search',
      'method': 'GET',
      'parameters': parameters
    };
    //can't use these OAuth functions on server
    OAuth.setTimestampAndNonce(message);
    OAuth.SignatureMethod.sign(message, accessor);
    var parameterMap = OAuth.getParameterMap(message.parameters);
    parameterMap.oauth_signature =  OAuth.percentEncode(parameterMap.oauth_signature)
    $.ajax(
    {
    'url': message.action,
    'data': parameterMap,
    'cache': true,
    'dataType': 'json',
    'success': function(data, textStats, XMLHttpRequest) 
        {
            res.send(JSON.stringify({foo: data}));
        }
     });
});

Passport处理此问题。看看吧;)

Node yelp提供了与yelp接口的方法,包括身份验证。它取决于oauth

最新更新