【发布时间】:2021-03-24 04:19:44
【问题描述】:
我正在尝试使用 discord 的 Oauth2 为我的应用程序创建登录名,目前我正在为 API 调用显示一个单独的 BrowserWindow,因为 discords Oauth2 要求用户单击授权。我的 API 调用返回 access_tokens 的原始 JSON。在我的应用程序的当前状态下,单独的窗口仅显示 JSON。我需要一种从窗口内或从变量中的请求获取 JSON 的方法。我似乎找不到任何访问原始内容的方法。
function createAuthWindow(){
var authWindow = new BrowserWindow({
width: 400,
height: 600,
show: false,
'node-integration': false,
'web-security': false,
icon: getFile('f','/src/asset/instance.png'),
});
// This is just an example url - follow the guide for whatever service you are using
var authUrl = 'http://localhost:3001/api/discord/login'
authWindow.loadURL(authUrl, (res) => {
console.log(res)
console.log(authWindow);
});
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) {
// More complex code to handle tokens goes here
console.log(event.code);
authWindow.webContents.session.webRequest.onCompleted({ urls: [newUrl] }, (details) => {
// Access request headers via details.requestHeaders
// Access response headers via details.responseHeaders
console.log(authWindow.webContents.code)
});
});
【问题讨论】:
标签: node.js oauth-2.0 electron discord