简体   繁体   English

将 oauth 与 Electron 一起使用时出现问题

[英]Problems using oauth with Electron

Im attempting to obtain an oauth token using "Implicit grant flow" in my electron app.我试图在我的 electron 应用程序中使用“隐式授权流”获取 oauth 令牌。 The issue Im having is when the oauth service (in this case Twitch) redirects my electron app to the redirect uri with the token in it.我遇到的问题是当 oauth 服务(在本例中为 Twitch)将我的 electron 应用程序重定向到其中包含令牌的重定向 uri 时。 When redirected the BrowserWindow seems to crash (error can be seen below).重定向时,BrowserWindow 似乎崩溃了(错误如下所示)。 I've tried listening to multiple events provided by the BrowserWindow but all of them seem to not trigger before the crash.我试过听 BrowserWindow 提供的多个事件,但它们似乎都没有在崩溃前触发。 I've following multiple guides on how to make oauth work within Electron but none of them seem to actually work.我已经遵循了多个关于如何使 oauth 在 Electron 中工作的指南,但它们似乎都没有真正起作用。 If anybody has any success in doing this, Id very much appreciate a solution.如果有人在这方面取得了任何成功,我非常感谢一个解决方案。 Thanks.谢谢。

Error message after being redirected重定向后的错误信息

UnhandledPromiseRejectionWarning: Error: ERR_CONNECTION_REFUSED (-102) loading (redirect uri with token in it)

Code代码

const redirect = 'https://localhost/';
const authApp = new AuthApp(cid, redirect);

function handleAuthApp(url: string) {
    const urlD = new URL(url);
    console.log(urlD);
    authApp.reset();
}
//Event that will trigger the AuthWindow to appear
ipcMain.on('get-auth', async (event, arg: any) => {
    const window = await authApp.getWindow();
    window.show();
    window.on('close', () => {
        authApp.reset();
        console.log('closed');
    });
    // These events seem to never trigger 
    window.webContents.on('will-navigate', function(event, newUrl) {
        console.log(`Navigate: ${newUrl}`);
        handleAuthApp(newUrl);
    });
    window.webContents.on('will-redirect', function(event, newUrl) {
        console.log(`Redirect: ${newUrl}`);
        handleAuthApp(newUrl);
    });
    const filter = {
        urls: [redirect+'*']
    };
    const { session } = window.webContents;
    session.webRequest.onBeforeRedirect(filter, details => {
        const url = details.url;
        console.log(url);
        event.returnValue = url;
        window.close();
    });
});

I was awaiting the URL to load before the 'will-navigate' events could be set.在设置“will-navigate”事件之前,我正在等待加载 URL。 So the BrowserWindow would crash before the events could be fired.所以 BrowserWindow 会在事件被触发之前崩溃。 Im dumb.我很笨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM