Using Keycloak with Electron

Hey everyone.

Does someone of you have a working example, how to use the standard flow within an electron app?

I cannot find a fully working example. Maybe it is a little bit difficult, because of the electron architecture with the main and renderer process.

What I already did, without any success:

let authWindow = new BrowserWindow({
    width: WINDOW_WIDTH,
    height: WINDOW_HEIGHT,
    show: false,
    parent: mainWindow,
    modal: true,

    webPreferences: {
        nodeIntegration: false
    }
});

authWindow.loadURL(`http://localhost:9080/auth/realms/myapp/protocol/openid-connect/auth?client_id=myapp&response_type=code`);
authWindow.webContents.on('did-finish-load', function () {
    authWindow.show();
});

authWindow.webContents.on('did-get-redirect-request', function(event, oldUrl, newUrl) {
    console.log('oldUrl', oldUrl)
    console.log('newUrl', newUrl)
});

const {session: {webRequest}} = authWindow.webContents;

const filter = {
    urls: [
        'file:///callback*'
    ]
};

webRequest.onBeforeRequest(filter, async ({url}) => {
     console.log('baam', url)
});

Best regards
Philipp

I also have this problem. I am trying to follow the description here but I can’t seem to grasp how the two pieces come together. Especially difficult is how to deal with the redirects.