Skip to content

Instantly share code, notes, and snippets.

@bkonkle
Last active December 15, 2022 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkonkle/057ce1ed263274912adb1d6d62e4efa7 to your computer and use it in GitHub Desktop.
Save bkonkle/057ce1ed263274912adb1d6d62e4efa7 to your computer and use it in GitHub Desktop.
Electron Google Authentication - Part 2
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