Can't use Discord OAuth2 in Electron application

荒凉一梦 提交于 2021-01-29 17:58:14

问题


I'm trying to create an Electron app (using Electron.net and MVC) with user sign-ins using Discord's OAuth2. However when loading up the OAuth2 page, Discord thinks that I'm using a broken installation of Discord. I assume that this is because the Discord desktop application also uses Electron. When not using Electron, the link opens fine.

So far I've attempted changing the User-Agent (both in the Electron startup code and directly on the link with Javascript) used by Electron as I believed that this was how Discord was identifying the app as using Electron, however this hasn't worked. Does anyone know how else Discord might be working out that I'm using Electron and how I might get around it?

Not sure if it adds much, but here's a screenshot of the error I get when trying to get to the Discord login page.


回答1:


I had to deal with the same issue, so I enabled devtools on load. I found this script here (https://discordapp.com/assets/db6c3ddb51620cee5d94.js) where they handle the app events, and I realized that they were loading node modules, which would not be available in a browser setting. The solution is to set nodeIntegration: false in the window options like so:

authWindow = new BrowserWindow({
        width: 800,
        height: 500,
        frame: false,
        webPreferences: {
            nodeIntegration: false
        }
});


来源:https://stackoverflow.com/questions/57987668/cant-use-discord-oauth2-in-electron-application

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