Application
Google OAuth Screen
Backstory
Starting on January 4th 2021 Google began blocking Google account sign-ins from embedded browsers including Electron (the framework ToDesktop uses under the hood)
If you previously showed your users a Google sign in screen inside your app they might now be seeing a warning telling them that Google doesn't allow sign ins from insecure browsers.
In order to continue allowing your users to sign into your desktop app with Google you'll have to move the sign in flow to the user's default browser.
Enable Open Google OAuth Screen in Browser & set an App Protocol
We need to ensure all Google OAuth links open in the user's default browser and set an app protocol so we can get back to your Desktop app from the browser.
- Go to https://app.todesktop.com and select your app.
- Tick the checkbox for Open Google OAuth Screen in Browser in App Options
- Tick the checkbox for Support App Protocol and enter a protocol
- E.g:
todesktop://
- E.g:
Redirect instead of showing prompt
This depends on how you've implemented sign in with google but the key thing is that you need to sign in with a redirect not with a prompt.
For ToDesktop's App we use Firebase. Firebase has a function firebase.auth().signInWithRedirect(googleProvider)
which seems like it would do the job however the redirect doesn't include the id_token
so instead we have to do the authentication manually
1. Load the Google Platform Library
2. Sign in with GAPI
Here we use window.todesktop
to check if we're in the Desktop app. If so, we load auth2
into GAPI, initialize it with our project's client id, and then get an auth instance and start the redirect sign in.
You can find your project's Google Client ID in your Project's Developers Console Credentials page.
If you're using typescript you can add @types/gapi and @types/gapi.auth2 to the
types
field in yourtsconfig.json
3. Add a new redirect URL to your project
In your project's Developer Console Credentials page click the OAuth 2.0 Client that you're using and add a desktop specific redirect URL to Authorised redirect URIs
After signing in Google will redirect users to this URL with id_token
as a hash parameter e.g:http://localhost:3000/desktopLogin#scope=email&id_token=xxxxx-xxxxxx
)
4. Redirect back to your Desktop App
On your redirect page you'll want to tell your users that the login succeeded and then open up your Desktop app using an app protocol. The info you want to pass back depends your implementation
Firebase:
All Firebase needs is the id_token
2. GAPI
GAPI handles signing in based off a redirect automatically so you'll need to open your Desktop app with the whole url
Sign the Desktop app in using the id token
Once your Desktop app has opened you'll want to finally sign in
Firebase
Install query-string
Get the id token
GAPI
GAPI does this automatically once it has been initialized