javascript - 如何在 Electron/Firebase 应用中支持 HTTP 协议(protocol)

标签 javascript node.js firebase firebase-authentication electron

我正在尝试在我的 Electron 应用程序中使用 firebase 身份验证(saml)。我读过 Electron 不是“官方支持的”,但是我也遇到了一些线程表明人们已经让它工作了。我的问题是使用 firebase.auth().signInWithRedirect 时(或 signInWithPopup ),我得到错误:

 code: "auth/operation-not-supported-in-this-environment"
 message: "This operation is not supported in the environment this application
 is running on. "location.protocol" must be http, https or chrome-extension and 
 web storage must be enabled."

谷歌出现this tips and tricks article这建议只使用托管 URL:

Third, OAuth requests need to have a verifiable origin, which can be whitelisted in the Firebase Console. This requires the current Electron browser window to use the http or https protocol, and not file. That means the current window contents should be loaded with browserWindow.loadURL and not browserWindow.loadFile, and the url must be an http or https url, not a file:// url. This generally requires a hosted page somewhere that gets wrapped into the Electron window.



这可能会起作用,因为只需使用以下方法在 Angular 开发服务器上本地运行应用程序即可:
mainWindow.loadURL('http://localhost:4200');

我不想这样做,因为拥有托管页面会大大降低拥有原生应用程序的吸引力。

我可以通过让本地 Node/Express 实例使用 get-port 在本地为应用程序提供服务来完成这项工作。找到一个空闲端口在那里运行应用程序。我还没有真正看到任何例子表明这一点。有一些关于让它工作的 Stackoverflow 问题,但没有什么让我认为它是一个可接受的生产级解决方案。

本地 Express 服务器是规避此错误的可接受方式,还是目前有更好的解决方案?

注:The package推荐于 this answer不是由 Firebase 发布的,而且它看起来也不支持 SAML 身份验证。

最佳答案

我已经在我的应用程序中成功实现了 firebase Electron 邮件版本,加载 .html 文件而不是从 url 加载页面更可行,因为用户可以通过发送虚假数据来利用 url。但是使用 oauth 是不可能的,firebase 创建 webapp 您可以创建一个 html 文件,它应该包含 api key 、主机 url 等并将其托管在本地 android 文件中://android_assets/filename.html 即使离线也可以正常工作我不知道正确关于
Electron

关于javascript - 如何在 Electron/Firebase 应用中支持 HTTP 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61541848/

相关文章:

javascript - 根据它的值将样式应用于 knockout JS 动态表中的特定单元格

javascript - Mongoose 中 "SELECT * WHERE city != null"的模拟

node.js - Mongoose 安装 - 无法验证第一个证书

带下划线的 JavaScript 命名约定

javascript - 如何链接到 javascript 文件中的 javascript 文件?

javascript - 将存储在 localStorage 中的 jQuery 可拖动位置保存到 MySQL

javascript - 将 Node.js 应用程序扩展到 10 到 1000 个并发连接

javascript - Flutter 无法使用脚本为范围注册 ServiceWorker,该脚本具有不受支持的 MIME 类型

java - 你如何使用谷歌云平台?

javascript - Firebase Cloud Functions - sendToTopic() 格式错误