我是電子新手,我目前正試圖實現一個需要回調URI的OAuth2.0 API。網址回調需要有效的網址(https://myserver.com/sucess)。所以我試過這個代碼片段,但不起作用。如何在電子中集成OAuth2.0登錄
// Your GitHub Applications Credentials
var options = {
client_id: 'your_client_id',
client_secret: 'your_client_secret',
scopes: ["user:email", "notifications"] // Scopes limit access for OAuth tokens.
};
app.on('ready',() => {
// Build the OAuth consent page URL
var authWindow = new BrowserWindow({ width: 800, height: 600, show: false, 'node-integration': false });
var githubUrl = 'https://github.com/login/oauth/authorize?';
var authUrl = githubUrl + 'client_id=' + options.client_id + '&scope=' + options.scopes;
authWindow.loadURL(authUrl);
authWindow.show();
function handleCallback (url) {
console.log(url);
}
// Handle the response from GitHub - See Update from 4/12/2015
authWindow.webContents.on('will-navigate', function (event, url) {
handleCallback(url);
});
authWindow.webContents.on('did-get-redirect-request', function (event, oldUrl, newUrl) {
handleCallback(newUrl);
});
// Reset the authWindow on close
authWindow.on('close', function() {
authWindow = null;
}, false);
});
另外,我用角js路線,但也不工作。
所以我想知道是否有一種方法來運行服務器內的電子應用程序從URL提供應用程序(https://localhost:3000),如果是這樣將如何影響應用程序在打包和分發時的行爲,我的意思是應用程序將運行從同一端口 ...任何建議將有助於我如何解決這個問題。謝謝