How to integrate oAuth login with a packaged electron app

佐手、 提交于 2021-02-05 10:48:43

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/56202191/how-to-integrate-oauth-login-with-a-packaged-electron-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!