【问题标题】:Is there an npm for oauth? [closed]是否有用于 oauth 的 npm? [关闭]
【发布时间】:2016-01-31 00:26:38
【问题描述】:

我想从我的节点服务器向 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}));
        }
     });
});

【问题讨论】:

  • 对场外资源的请求对于 SO 来说是题外话。请查看help center 以获取列表。另外,我只是通过搜索您的问题标题找到了this:请先搜索再提问。谢谢。
  • 对不起,我只是想知道是否有一个具有我需要的功能的 npm。此外,您显然没有阅读我的其余问题或该包裹中的内容,因为其中没有 setTimestampAndNonceSignatureMethodgetParameterMappercentEncode
  • 你明白了,我没有费心阅读题外话......

标签: javascript node.js oauth oauth-2.0


【解决方案1】:

Passport 处理这个问题。看看吧;)

【讨论】:

    【解决方案2】:

    Node-yelp 提供与 Yelp 交互的方法,包括身份验证。这取决于oauth

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 2021-06-16
      • 2011-01-26
      相关资源
      最近更新 更多