【问题标题】:TypeError: Redirected path should match configured path, but got: /callbackTypeError:重定向的路径应该与配置的路径匹配,但得到:/callback
【发布时间】:2020-03-29 03:02:31
【问题描述】:

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

我正在尝试使用 OAUTH2.0 授权我的 express 应用程序使用 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)

错误在以下文件中: 回调.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 包。 客户端-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】:

    这不是一个有效的网址:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 2018-12-23
      • 2017-10-31
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多