1

I have been working on a new electron app with react that uses the Spotify API. I am using oAuth to authenticate with Spotify and a return an access token, this why fine in a local dev env as the app if running on the webpack dev server and can provide a callback url.

However the when the electron app is packaged up and installed it is no longer using the dev server and the JS bundles are packaged up with the app.

At this stage how am I supposed to hit the oauth server and return a valid callback url to get the token?

chinds
  • 1,761
  • 4
  • 28
  • 54

1 Answers1

0

You can register custom protocol and intercept it via electron so that you dont require a web server. you may set the urn of the native desktop/mobile application instead of redirect uri of the web app.

https://electronjs.org/docs/api/protocol

protocol.registerFileProtocol('yourprotocolname', (request, callback) => {

      //parse authorization code from request 

  }, (error) => {
    if (error) console.error('Failed to register protocol')
  })

Set the urn of the application in the oauth configuration as yourprotocolname://example

Sharvin K
  • 697
  • 3
  • 10
  • Does this work in both development and production? Following this example (in development), I keep getting errors from the site that issues the auth token that says: "failed to launch [awesomeProtocol://example] because the scheme does not have a registered handler" – SeanRtS Jul 29 '21 at 21:03
  • FYI I've added a question about this issue here: https://stackoverflow.com/questions/68590822/electron-custom-protocol-no-registered-handler-error – SeanRtS Jul 30 '21 at 12:21