Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 236
tobier Avatar asked Dec 05 '25 06:12

tobier


1 Answers

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.

like image 133
mmomtchev Avatar answered Dec 07 '25 12:12

mmomtchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!