mauriciovigolo / keycloak-angular

Easy Keycloak setup for Angular applications.
MIT License
727 stars 279 forks source link

Keycloak undefined error in electron application while redirecting after authentication #377

Closed Siri15 closed 2 years ago

Siri15 commented 2 years ago

Need help to fix this issue as been facing from long time,

Bug Report or Feature Request (mark with an x)

INDEX.html below

...

main.ts

mainWindow.loadURL( url.format({ pathname: path.join(__dirname, /dist/index.html), protocol: "file:", slashes: true }) );

const Keycloak = http.createServer((request, response) => { response.writeHeader(200, { 'Content-Type': 'text/html'}); var readSream = fs.createReadStream('./dist/index.html','utf8') console.log(readSream); readSream.pipe(response); }); Keycloak.listen(5200);

ipcMain.on('keycloak-token', (event, token) => { console.log('token ', token); const winURL = file://${__dirname}/dist/index.html?token=${token} console.log(window); mainWindow.loadURL(winURL); });

Versions.

Repro steps.

I am running the electron application by securing with keycloak. command that used to run the application is --> "start:electron-tsc": "tsc main.ts && ng build --base-href ./ && electron ." in package json.

The log given by the failure.

keycloak.js:1 Uncaught SyntaxError: Unexpected token '<' runtime.js:1 Uncaught SyntaxError: Unexpected token '<' polyfills.js:1 Uncaught SyntaxError: Unexpected token '<' scripts.js:1 Uncaught SyntaxError: Unexpected token '<' vendor.js:1 Uncaught SyntaxError: Unexpected token '<' main.js:1 Uncaught SyntaxError: Unexpected token '<' (index):15 Uncaught ReferenceError: Keycloak is not defined at onloadKeycloak ((index):15) at onload (VM98 :36)

Desired functionality.

After the successfull keycloak authentication the redirection is not happening as expected,

jonkoops commented 2 years ago

I don't think this is an issue with Keycloak JS or Keycloak Angular. It looks like your JavaScript files are returning a different kind of content (presumably HTML considering the unexpected token is an opening bracket).

Check your Network panel in the devtools to see what you are getting back from the server.