【发布时间】: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