I have an Angular Electron app that uses a BrowserWindow to log in using a third-party OpenID Connect Identity Provider.
Additionally, I have my own Backend that implements the OpenID Connect standard.
The backend runs under localhost:5000.
Package versions:
Angular: 11.1.0
electron: 9.1.0
ngx-electron: 2.2.0
The Flow is like this:
- Electron opens a BrowserWindow with
localhost:5000/connect/authorizeas URL (including required query parameters) - Backend redirects to third-party Identity Provider
- User logs in
- Third Party redirects to Backend with auth info
- Backend redirects to the provided returnUri (Frontend callback)
- BrowserWindow calls the callback function and has the auth token in the URL (as expected)
--> How do I get the auth token from the BrowserWindow to the main Electron app? Actually, I need the callback function to be called in the main Electron app
Login logic, that is called in the main Electron app:
public login() {
// Everything in here is called in the main Electron app
const authWindow = new this.electron.remote.BrowserWindow({
width: 800,
height: 600,
show: false,
webPreferences: {
nodeIntegration: false,
webSecurity: false
}
});
authWindow.loadURL(myAuthurl);
authWindow.show();
authWindow.webContents.openDevTools();
const defaultSession = this.electron.remote.session.defaultSession;
const { session: { webRequest } } = authWindow.webContents;
webRequest.onBeforeRequest(null, async request => {
console.log(request);
});
webRequest.onBeforeRedirect(null, async request => {
console.log(request); // Callback function never called
});
defaultSession.webRequest.onBeforeRequest(null, async request => {
console.log(request); // Callback function never called
});
defaultSession.webRequest.onBeforeRequest(null, request => {
console.log(request); // Callback function never called
});
defaultSession.webRequest.onBeforeRedirect(null, request => {
console.log(request); // Callback function never called
});
authWindow.on('closed', (event) => {
console.log(event); // Callback function called when the window is closed but with no data
});
}
Callback Logic, called in BrowserWindow (But it's the same Angular app):
// this method is called after successful log in
// here I'm still in the BrowserWindow
public callback()
// here's the data I need. How do I "send" this data to the main Electron app?
const hash = window.location.hash;
}
Edit:
I tried ipcRenderer, but the on callback is never triggered:
// executed in the main Electron app
const ipc = this.electron.ipcRenderer;
ipc.on('authtoken', (event, arg) => {
console.log(arg);
})
ipc.send('authtoken', 'DATA');
Any ideas about what I'm missing here? Are there better approaches?