首页 > 解决方案 > Firebase 和 LinkedIn Auth 集成未知路由

问题描述

我一直在研究这个代码库作为如何使用 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 次调用)?我应该查看哪些其他信息来尝试调试它?

标签: firebasehttpfirebase-authenticationgoogle-cloud-functionslinkedin-api

解决方案


为了提供更全面的答案:

您提供的示例依赖于 Firebase.json 文件。当(且仅当)您的应用程序由 Firebase 托管托管时,此文件提供配置(请参阅文档)。

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


推荐阅读