这主要是缺乏对 oauth2 的理解,并且可能不是特定于 Electron 的,但是我试图理解某人如何处理来自桌面平台(如 Electron)的 oauth2 重定向 url?
假设应用程序中没有 Web 服务设置,桌面应用程序如何提示用户输入第三方 oauth2 服务的凭据,然后正确验证它们?
Electron JS 在您的本地主机上运行一个浏览器实例。因此,您可以通过提供 https:localhost/whatever/path/you/want 的回调 url 来处理 oauth2 重定向 url。只要确保在您使用的任何服务的 oauth2 应用程序注册页面上将其列入白名单即可。
例子:
var authWindow = new BrowserWindow({
width: 800,
height: 600,
show: false,
'node-integration': false,
'web-security': false
});
// This is just an example url - follow the guide for whatever service you are using
var authUrl = 'https://SOMEAPI.com/authorize?{client_secret}....'
authWindow.loadURL(authUrl);
authWindow.show();
// 'will-navigate' is an event emitted when the window.location changes
// newUrl should contain the tokens you need
authWindow.webContents.on('will-navigate', function (event, newUrl) {
console.log(newUrl);
// More complex code to handle tokens goes here
});
authWindow.on('closed', function() {
authWindow = null;
});
很多灵感都来自于这个页面:http://manos.im/blog/electron-oauth-with-github/ http://manos.im/blog/electron-oauth-with-github/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)