【问题标题】:Firebase and LinkedIn Auth integration unknown routeFirebase 和 LinkedIn Auth 集成未知路由
【发布时间】:2021-05-24 16:03:56
【问题描述】:

我一直在研究 this code base 作为如何使用 Firebase 后端对我的项目实施 LinkedIn 授权的示例。我感到困惑的一件事是这些行:

var code = getURLParameter("code");
var state = getURLParameter("state");
var error = getURLParameter("error");
if (error) {
  document.body.innerText = "Error back from the LinkedIn auth page: " + error;
} else if (!code) {
  // Start the auth flow.
  window.location.href = "/redirect";
} 

window.location.href = '/redirect',我相信它是为了调用称为“重定向”的云功能。在我的代码库中,它只是去一个未知的路线并触发我的后备。我对这行代码的目的有误吗?有谁知道它没有触发云功能的任何可能原因(控制台说 0 次调用)?我应该查看哪些其他信息来尝试调试?

【问题讨论】:

  • 您是否设置了 firebase.json 以将 /redirect 路径指向函数?
  • @imjared 我没有。非常感谢您指出这一点。这是否意味着 firebase 功能仅在托管在 firebase 上时才有效?

标签: firebase http firebase-authentication google-cloud-functions linkedin-api


【解决方案1】:

为了提供更全面的答案:

您提供的示例依赖于 Firebase.json 文件。此文件在(且仅当)您的应用程序由 Firebase 托管 (see docs) 托管时提供配置。

如果您希望在其他地方托管您的应用,则需要确保您的 /redirect 路径指向 Firebase 函数 URL 本身(可能类似于 https://us-central1-project-name.cloudfunctions.net/redirect)。在授权流程中,示例 repo 中的 LinkedIn 模块将重定向到 default or a configured callback url

【讨论】:

  • 您好,感谢您的帮助。所以据我了解,通过popup.html上的逻辑,第一次打开弹出窗口时,会调用重定向函数(我将/redirect替换为函数URL)。重定向流程完成后,该函数将重定向回 popup.html,然后调用令牌函数(我将回调更改为 popup.html 并将 /token 更改为令牌函数)。一旦我到达令牌函数调用,我就会遇到“令牌函数中的错误:未定义”。你有没有看到我可能错过的任何东西? firebase 函数日志不是很有帮助。
  • 再次感谢您的帮助。我想我已经将问题缩小到几行代码。在 popup.html (github.com/firebase/functions-samples/blob/master/linkedin-auth/…) 第 56 行调用 tokenReceived.name。 tokenReceived 函数接收数据,但我们不会在调用时传递数据。因此,tokeReceived 进入“else”(因为没有数据)并打印“token Function 中的错误:”data.error。 Data.error 未定义。
猜你喜欢
  • 2018-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-15
  • 2018-12-15
  • 1970-01-01
  • 2015-09-18
相关资源
最近更新 更多