TypeError:重定向的路径应与配置的路径匹配,但得到:/ callback

问题描述 投票:0回答:1

我已经在Firebase函数上部署了ExpressJs应用程序,并尝试使用HTTP触发器来触发Express应用程序。

我正在尝试使用OAUTH2.0授权我的快速应用程序使用QuickBooks API。但是,我收到以下错误:

TypeError: Redirected path should match configured path, but got: /callback
    at CodeFlow.getToken (/srv/node_modules/client-oauth2/src/client-oauth2.js:597:7)
    at /srv/routes/callback.js:12:25
    at Layer.handle [as handle_request] (/srv/node_modules/express/lib/router/layer.js:95:5)
    at next (/srv/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/srv/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/srv/node_modules/express/lib/router/layer.js:95:5)
    at /srv/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/srv/node_modules/express/lib/router/index.js:335:12)
    at next (/srv/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/srv/node_modules/express/lib/router/index.js:174:3)

错误在以下文件中:callback.js

router.get('/', function (req, res) {
  // Verify anti-forgery

  console.log("OriginalURL "+req.originalUrl)
  console.log("base URL "+req.baseUrl)
  // Exchange auth code for access token
  tools.intuitAuth.code.getToken(req.originalUrl).then(function (token) {  //This is where promise is failing

我正在使用名为“ client-oauth2”的npm软件包。client-oauth2.js

if (
    typeof options.redirectUri === 'string' &&
    typeof url.pathname === 'string' &&
    url.pathname !== Url.parse(options.redirectUri).pathname
  ) {
    return Promise.reject(
      new TypeError('Redirected path should match configured path, but got: ' + url.pathname)  //The source of Error. I am not able to find out the value of options.redirectUri
    )
  }

以下是我的配置详细信息:

"redirectUri": "us-central1-thematic-runner-245505.cloudfunctions.net/createEstimate/callback"

我已确保此URL与Quickbooks侧重定向URL匹配。对于localhost,它可以正常工作。

Localhost URL: http://localhost:5001/thematic-runner-245505/us-central1/createEstimate/

来自callback.js的req.originalUrl的值是

OriginalURL /thematic-runner-245505/us-central1/createEstimate/callback?code=AB11585447829JwgpXMEpWOR6irwprMe9Z8aqRoSK4npFDKmte&state=Z0t9yRkl-dWaO2J5sJRDaTB9eZKvyyyVcHYQ&realmId=4620816365002391850

有人可以帮我解决这个错误吗?我不知道我在生产中做错了什么。回调URL似乎不错。任何帮助,将不胜感激。

firebase express oauth-2.0 google-cloud-functions quickbooks
1个回答
0
投票

这不是有效的网址:

"redirectUri": "us-central1-thematic-runner-245505.cloudfunctions.net/createEstimate/callback"

该URL没有scheme/protocol部分(例如https://)。它应该以https://开头,但您直接跳到了域中。

它必须是有效的URL,包括协议/方案。

© www.soinside.com 2019 - 2024. All rights reserved.