I’m new to Keycloak and having a hard time integrating my Electron Application to have access to protected API.
Here is what my code looks like in the main.js:
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
const url = require('url');
const path = require('path');
const session = require('express-session');
const Keycloak = require('keycloak-connect');
// Keycloak Setup
const memoryStore = new session.MemoryStore();
const keycloakConfig = {
realm: 'my-realm',
'auth-server-url': 'https://my-keycloak-server/auth',
'ssl-required': 'external',
resource: 'my-client-id',
'public-client': true,
'confidential-port': 0,
"credentials": {
"secret":'my-secret'
}
};
const keycloak = new Keycloak({ store: memoryStore }, keycloakConfig);
// Function to handle application readiness
async function onReady() {
globalShortcut.register('alt+tab', () => {
return false;
});
// Create a new BrowserWindow instance
win = new BrowserWindow({
width: 1920,
height: 1080,
frame: false,
kiosk: true,
isTrusted: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
// Load the frontend
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/frontend/index.html'),
protocol: 'file:',
slashes: true,
}));
// Reload event listener
ipcMain.on('reload', (event, arg) => {
console.log("Reload");
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/frontend/index.html'),
protocol: 'file:',
slashes: true,
}));
});
}
// Start the Electron app
app.on('ready', onReady);
And here is my error:
localhost:3200/api/items:1
Failed to load resource: the server responded with a status of 500 (Internal Server Error)