gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:18:15 26 4
gpt4 key购买 nike

我正在尝试在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com