如何将oAuth登录信息与打包的电子应用程序集成 [英] How to integrate oAuth login with a packaged electron app

查看:47
本文介绍了如何将oAuth登录信息与打包的电子应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个新的电子应用程序,该应用程序具有使用Spotify API的react.我正在使用oAuth来通过Spotify进行身份验证并返回访问令牌,这就是为什么如果在webpack开发服务器上运行并且可以提供回调网址,那么在本地开发环境中作为应用可以正常使用的原因.

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.

但是,打包并安装电子应用程序后,就不再使用开发服务器,而JS捆绑包则与该应用程序打包在一起.

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.

在这个阶段,我应该如何访问oauth服务器并返回有效的回调URL以获取令牌?

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

推荐答案

您可以注册自定义协议并通过电子拦截它,因此您不需要Web服务器.您可以设置本机桌面/移动应用程序的缸,而不是Web应用程序的重定向uri.

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')
  })

在oauth配置中将应用程序的容器设置为您的协议名称://example

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

这篇关于如何将oAuth登录信息与打包的电子应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆