From 2fc67d1c9bc2038179771238a0cb5d58995e05c3 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 21 Dec 2018 11:35:00 +0100 Subject: BasicAuth first draft --- src/index.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 830166dcf..a4bc44a6c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,8 @@ import { - app, BrowserWindow, shell, ipcMain, + app, + BrowserWindow, + shell, + ipcMain, } from 'electron'; import fs from 'fs-extra'; @@ -7,9 +10,14 @@ import path from 'path'; import windowStateKeeper from 'electron-window-state'; import { - isDevMode, isMac, isWindows, isLinux, + isDevMode, + isMac, + isWindows, + isLinux, } from './environment'; +import { mainIpcHandler as basicAuthHandler } from './features/basicAuth'; + // DEV MODE: Save user data into FranzDev if (isDevMode) { app.setPath('userData', path.join(app.getPath('appData'), 'FranzDev')); @@ -229,23 +237,42 @@ app.on('ready', () => { }); // This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕 +// TODO: rewrite to handle multiple login calls +const noop = () => null; +let authCallback = noop; app.on('login', (event, webContents, request, authInfo, callback) => { - event.preventDefault(); + authCallback = callback; debug('browser login event', authInfo); + event.preventDefault(); if (authInfo.isProxy && authInfo.scheme === 'basic') { webContents.send('get-service-id'); - ipcMain.on('service-id', (e, id) => { + ipcMain.once('service-id', (e, id) => { debug('Received service id', id); const ps = proxySettings.get(id); callback(ps.user, ps.password); }); - } else { - // TODO: implement basic auth + } else if (authInfo.scheme === 'basic') { + console.log('basic auth handler', authInfo); + basicAuthHandler(mainWindow, authInfo); } }); +ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { + debug('Received basic auth credentials', user, '********'); + + authCallback(user, password); + authCallback = noop; +}); + +ipcMain.on('feature-basic-auth-cancel', () => { + debug('Cancel basic auth'); + + authCallback(null); + authCallback = noop; +}); + // Quit when all windows are closed. app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar -- cgit v1.2.3-70-g09d2