简体   繁体   English

如何在 Electron 桌面应用程序中使用 Google 登录?

[英]How can I use Google sign-in inside of an Electron desktop application?

I'm using Node.js and Express to make a simple app.我正在使用 Node.js 和 Express 来制作一个简单的应用程序。 It relies heavily on Google sign-in for profile pictures and nicknames, and when testing it in a new Electron app I got thrown the error -它严重依赖谷歌登录来获取个人资料图片和昵称,在新的 Electron 应用程序中测试它时,我得到了错误 -

" This browser or app may not be secure " 此浏览器或应用程序可能不安全

Try using a different browser.尝试使用其他浏览器。 If you're already using a supported browser, you can refresh your screen and try again to sign in. "如果您已经在使用受支持的浏览器,您可以刷新屏幕并再次尝试登录。”

- when trying to sign in with Google. - 尝试使用 Google 登录时。 I briefly considered opening the sign in inside of the user's browser, before realising this wouldn't pass the details back to the app.在意识到这不会将详细信息传递回应用程序之前,我曾短暂考虑过在用户浏览器中打开登录。 A lot of the solutions that I found online relied on Firebase, which I'm not using.我在网上找到的许多解决方案都依赖于我没有使用的 Firebase。

Is there a way I can send data from the browser back to the app?有没有办法可以将数据从浏览器发送回应用程序? Or some other solution that I haven't considered yet?还是我还没有考虑过的其他解决方案?

This might not be directly related to your mission, but for those of you whose projects are indirectly affected by this issue (eg. if you are building a web browser interface with Electron where you want to allow users to visit Gmail etc. inside the browser), the best way to go about this is to change Electron's user agent to Firefox's.这可能与您的任务没有直接关系,但对于那些项目间接受此问题影响的人(例如,如果您正在构建一个 web 浏览器界面和 Electron,您希望允许用户在浏览器中访问 Z7D53CBD3F0C0E2AF31C3BA1EAB9 等。 ),关于此问题的 go 的最佳方法是将 Electron 的用户代理更改为 Firefox 的。

view.webContents.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0";

This will cause Google Accounts to think you're running on Firefox and not Electron, and therefore it'll prevent further barring checks from happening.这将导致 Google 帐户认为您在 Firefox 而不是 Electron 上运行,因此它将防止进一步的禁止检查发生。 Setting the user agent to Chromium won't work for this scenario since Google Accounts can still detect that the browser is Electron-based.将用户代理设置为 Chromium 不适用于这种情况,因为 Google 帐户仍然可以检测到浏览器是基于 Electron 的。 Setting the user agent to Firefox somehow disables this check.将用户代理设置为 Firefox 会以某种方式禁用此检查。

This seems to work, according to the developers of the Wexond Electron-based web browser.根据基于 Wexond Electron 的 web 浏览器的开发人员的说法,这似乎可行。

See https://github.com/wexond/browser-base/issues/424 for a relevant issue fix on a related project (I'm not affiliated with it).有关相关项目的相关问题修复,请参阅https://github.com/wexond/browser-base/issues/424 (我不隶属于它)。

You don't need firebase to do this.您不需要 firebase 来执行此操作。 You can do this by taking a user to their regular browser and back again.您可以通过将用户带到他们的常规浏览器并再次返回来做到这一点。 It is possible to pass the details back to the app.可以将详细信息传递回应用程序。 We do this in Amna .我们在Amna中执行此操作。

It is a tad more involved (but useful for any other providers too).它涉及更多一点(但对任何其他提供商也很有用)。 I am assuming you have used some kind of OAuth provider before.我假设您以前使用过某种 OAuth 提供程序。

  1. Register a custom url handler in your Electron app (eg myapp:// . You can do this with the protocol ).在您的Electron应用程序中注册一个自定义 url 处理程序(例如myapp:// 。您可以使用protocol执行此操作)。 We used the electron-deeplink library我们使用了电子深度链接

  2. On your app's website, setup a side page that can launch your app.在您的应用程序的网站上,设置一个可以启动您的应用程序的侧页。 For example, we have an authorize page that launches our app.例如,我们有一个启动我们的应用程序的授权页面。 You want to register this website as the redirect url from Google, so when Google hits this url, it passes the validate tokens to it.您想将此网站注册为来自 Google 的redirect url ,因此当 Google 遇到此 url 时,它会将验证令牌传递给它。 You can do any OAuth Work here.你可以在这里做任何 OAuth 工作。

  3. Finally, from your website, call your app's url handler.最后,从您的网站调用您的应用程序的 url 处理程序。 myapp://authroize?code=XYZ . myapp://authroize?code=XYZ This sends all the data back to your main App.这会将所有数据发送回您的主应用程序。

deeplink.on('received', (link) => {
    // parse out the code from the stuff here
});
  1. If you need the final data in your UI, you can pass the data to the UI with ipcRenderer.send()如果您需要 UI 中的最终数据,可以使用ipcRenderer.send()将数据传递给 UI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过执行不同操作的Google按钮获得两次登录? - How can I get two Sign-in with Google buttons executing different actions? 如何/可以使用PHP访问Google+登录SessionState? - How / Can You Access Google+ Sign-In SessionState with PHP? 如何在JavaScript中加入Google登录? - How do I put Google Sign-in in JavaScript? 如何在 electron 应用程序中显示网络摄像头视频源? - How can I show webcam video feed inside an electron application? 谷歌登录,如何从js触发? - Google sign-in, how to trigger from js? Google登录网站 - 如何获取令牌 - Google Sign-in for websites - How to get token 如何更改Google登录按钮语言 - How to change Google Sign-in button language 网站的Google登录自动登录 - Google Sign-In for Websites Automatical Sign-In 如何将动态 IP 地址添加到 Google Cloud 中的“授权 javascript 来源”列表中,以便将 Google 登录集成到我的 web 应用程序中? - How can I add a dynamic IP address to the "Authorised javascript origins" list in Google Cloud so that I can integrate Google sign-in into my web app? 如何管理Google登录会话(Google登录JavaScript客户端) - How to manage google sign-in session (Google Sign-In JavaScript client)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM