Last active
December 15, 2022 11:32
-
-
Save bkonkle/057ce1ed263274912adb1d6d62e4efa7 to your computer and use it in GitHub Desktop.
Electron Google Authentication - Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function signInWithPopup () { | |
return new Promise((resolve, reject) => { | |
const authWindow = new remote.BrowserWindow({ | |
width: 500, | |
height: 600, | |
show: true, | |
}) | |
// TODO: Generate and validate PKCE code_challenge value | |
const urlParams = { | |
response_type: 'code', | |
redirect_uri: GOOGLE_REDIRECT_URI, | |
client_id: GOOGLE_CLIENT_ID, | |
scope: 'profile email', | |
} | |
const authUrl = `${GOOGLE_AUTHORIZATION_URL}?${qs.stringify(urlParams)}` | |
function handleNavigation (url) { | |
// ... | |
} | |
authWindow.on('closed', () => { | |
// TODO: Handle this smoothly | |
throw new Error('Auth window was closed by user') | |
}) | |
authWindow.webContents.on('will-navigate', (event, url) => { | |
handleNavigation(url) | |
}) | |
authWindow.webContents.on('did-get-redirect-request', (event, oldUrl, newUrl) => { | |
handleNavigation(newUrl) | |
}) | |
authWindow.loadURL(authUrl) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment