【问题标题】:Why can't I use credentials to make followup oauth call为什么我不能使用凭据进行后续 oauth 调用
【发布时间】:2015-01-09 06:13:02
【问题描述】:

我正在使用 passport-freshbooks 来验证和检索令牌和 tokenSecret。但是,当我尝试将它们与单独的 OAuth 对象一起使用时,我收到 401 authentication failed 错误。

passport-freshbooks 使用的策略使用相同的 oauth 库,并且对“post”的调用与后续调用相同(至少在我看来是一样的,但也许我遗漏了一些明显的东西)。

以下是护照策略中的一些相关代码:

OAuth = require('oauth').OAuth //This is called from within require('passport-oauth').OAuthStrategy
...
this._oauth = new OAuth('https://' + options.subdomain + '.freshbooks.com/oauth/oauth_request.php',
    'https://' + options.subdomain + '.freshbooks.com/oauth/oauth_access.php',
    freshbookDao.config.apiSubdomain,  
    freshbookDao.config.oauthSecret,
    "1.0", 
    null, 
    "PLAINTEXT",
    null, 
    options.customHeaders);
...
log.info("Calling userProfile with " + token + " and " + tokenSecret);
...
this._oauth.post(url, token, tokenSecret, post_body, post_content_type, function (err, body, res) {...}

我稍后会尝试使用相同的令牌和 tokenSecret。我正在创建一个新的 OAuth 对象,但使用传递给护照策略的相同设置进行设置。以下是其中的一些代码:

 OAuth = require('oauth')
 ...
 oauth = new OAuth.OAuth(
    'https://' + options.subdomain + '.freshbooks.com/oauth/oauth_request.php',
    'https://' + options.subdomain + '.freshbooks.com/oauth/oauth_access.php',
    exports.config.apiToken,
    exports.config.oauthSecret,
    '1.0',
    null,
    'PLAINTEXT');
...
log.info("Calling listInvoices with " + token + " and " + tokenSecret);
...
oauth.post(url, token, tokenSecret, body, 'application/xml', function(err, data, res) {...}

这些在我看来是一样的。但是,第一个通过,第二个失败并出现此响应:

{"statusCode":401,"data":"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response xmlns=\"http://www.freshbooks.com/api/\" status=\"fail\">\n  <error>Authentication failed.</error>\n  <code>20010</code>\n</response>\n"} <code>20010</code>\n</response>\n"}

我做错了什么?我已经包含在“log.info”行中,以表明我已经比较了 token 和 tokenSecret,它们确实是相同的。我错过了什么?

【问题讨论】:

    标签: node.js oauth passport.js passport-freshbooks


    【解决方案1】:

    很高兴您正在使用护照新书!

    我没有在其中编写 OAuth 代码。我从 Jared Hanson 的 passport-linkedin 模块中复制了这个,然后对其进行了调整以与 Freshbooks 一起使用

    如果您得到不同的输出,则发生以下两种情况之一:
    1)要么您发送不同的输入,要么 2) 内部状态不同。

    对于 1) 尝试将请求记录到文件中,看看会发生什么:Logging in express js to a output file?

    您的应用是否发送不同的请求?

    对于 2) 我不太了解 OAuth 协议,无法对其进行调试。刚好够用。可能是您不能在不同的连接上重用令牌?我不能确定。

    希望对托德有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-09
      • 2019-02-16
      • 2020-11-14
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      相关资源
      最近更新 更多