Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OAuth login in separate window/browser with Electron

I’m working on an Electron app connected to a backend on AWS that handles the verification and creation of the user. If it matters I’m building the app with React.

Basically the backend flow is:

  • Navigates to backend.com/oauth/login
  • Backend prepares OAuth config, redirects to the Discord.com authentication url
  • User authenticates, redirects to backend.com/oauth/callback with the neccessary information to validate the authentication and create a user

I’ve got this part working. But if I would open backend.com/oauth/login in a separate browser window, how would I know the authentication was successful?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Are there some events I could listen to in the authentication window I’ve opened? Maybe let the callback redirect to backend.com/login/successful if the authentication was completed or otherwise backend.com/login/failed. This feels like such a hack but I’m way out of my expertise here.

>Solution :

Three ways to do it:

  • Once the authentication is successful, you redirect the user’s browser to your backend where you load the authentication data in the user state. Your React/Electron app is also connected to this backend. You must be able to match those two connections
  • Once the authentication is successful, you redirect the user’s browser to a custom URL protocol which is registered in the OS to open your Electron app
  • Once the authentication is successful, you redirect the user’s browser to a port on your running Electron app

Most good Electron applications use number 2 – but it requires that your application knows how to register an URL handler on every OS it can potentially run. Number 1 is good if you can safely match the two connections. It requires passing some form of identification. Number 3 is a hack.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading