javascript - 处理来自 Electron (或其他桌面平台)的 oauth2 重定向

标签 javascript oauth-2.0 electron

这主要是缺乏对 oauth2 的理解,可能不是特定于 electron,但是我正在努力思考某人将如何处理来自桌面平台(如 electron)的 oauth2 重定向 url?

假设没有网络服务设置作为应用程序的一部分,桌面应用程序将如何提示用户输入针对第三方 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/

关于javascript - 处理来自 Electron (或其他桌面平台)的 oauth2 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37546656/

相关文章:

javascript - 函数调用之间 Angular 变量不会为 "unset"

javascript - 将元素的宽度设置为等于监视器大小而不改变缩放

security - 使用 JWT 进行应用身份验证和授权

reactjs - Nylas N1插件,可在Nylas窗口中打开网页

javascript - 在 Angular Controller 中从 webContents.send(..) 访问数据

java - 在 war 中打包 Javascript 文件?

c# - 使用从 CodeBehind 动态生成的 Html 打开 Popup

javascript - hello.js:是否可以动态设置提供程序的设置?

asp.net-core - 当 ShowPii 设置为 true 时,IdentityModel 会记录哪些信息?

javascript - 是否可以通过 npm(而不是 yarn )打包 Electron-builder?