export type AuthTarget = "github" ; export const authenticate = async ( target ) => { const electronRemote = require ( "electron" ) . remote ; const win = new electronRemote . BrowserWindow ( { show : false , webPreferences : { zoomFactor : 0.75 , nodeIntegration : true , enableRemoteModule : true } , } ) ; return await new Promise < string > ( ( resolve , reject ) => { win . webContents . on ( "dom-ready" , ( ) => { if ( win . webContents . getURL ( ) . indexOf ( "callback?code=" ) !== - 1 ) { win . webContents . executeJavaScript ( `
            require('electron').ipcRenderer.send(
              'auth:${ target }', document.body.textContent
            );
          ` ) ; electronRemote . ipcMain . on ( `auth:${ target }` , ( _ , auth ) => { try { resolve ( JSON . parse ( auth ) . access_token ) ; } catch ( e ) { reject ( e ) ; } finally { win . close ( ) ; } } ) ; } else { win . show ( ) ; } } ) ; win . loadURL ( `https://oauth.nteract.io/${ target }` ) ; } ) ; } ;