Exploring the OAuth 2.0 integration with OpenID Connect, Loopback, and Keycloak

I'm having trouble establishing a connection to Keycloak from Loopback.

I've been experimenting with the keycloak-connect library available at:

https://github.com/keycloak/keycloak-nodejs-connect

This snippet shows my current implementation in server/boot/root.js

module.exports = function (server) {
    var session = require('express-session');
    var Keycloak = require('keycloak-connect');

    var memoryStore = new session.MemoryStore();

    var keycloak = new Keycloak({
        store: memoryStore
    });

    server.use(session({
        secret: 'xxx',
        resave: false,
        saveUninitialized: true,
        store: memoryStore,
    }))

    server.use(keycloak.middleware({}));

    server.get('/*', keycloak.protect(), function (req, resp) {
        resp.send('hello');
    })

};'

Although seemingly straightforward, I am encountering a redirection loop issue.

In an attempt to troubleshoot, I have switched

server.use(session

with

 server.use(keycloak

However, this resulted in a "Cannot read property 'keycloak-token' of undefined" error.

I have exhausted all options and have not been able to resolve this issue. Are there any other suggestions or insights? Your help is appreciated!

Thank you in advance!

Answer №1

To resolve the issue, it is recommended to instruct your Keycloak instance to utilize the Memory Store that you have set up during initialization. You can achieve this by adding the following line of code:

var keycloak = new Keycloak({ store: memoryStore });

This should address the problem you are experiencing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to duplicate a file without removing the original in node.js

I'm in need of a node.js method that can copy, move, and rename a file from one location to another without removing the original. I've come across other options like fs.rename but they seem to delete the original file. This process will be exec ...

Display upon hovering, conceal with a button located within a popup container

There seems to be an issue with the code below. Even though it works perfectly in jsfiddle, it breaks in my Chrome and other browsers right after displaying the ".popup" div. Can anyone point out what I might be doing wrong? I found similar code on this si ...

Using array map to create a centered table in a React web application

In my React project, I created a table using the array.map function. However, I'm facing an issue where the output of array.map is always aligned to the left, even before the table itself. I want to center the entire table. JSX: <div className=&qu ...

Unable to allocate a second item to an existing one

Encountering an unusual issue while trying to assign an item a second time. Initial scenario: I am working with a jqxTree containing various items as shown below: - apple - oracle - microsoft When I drag and drop one item into another, the structure loo ...

Can we include an option to display all pages in one row on a single page?

Is it possible to include an option to display all rows alongside the current options of 10, 15, and 100? I've been unable to locate this feature in the documentation: Check out the Codesandbox example: https://codesandbox.io/s/muidatatables-custom-t ...

Strategies for extracting targeted information from my mondoDB records

I am seeking guidance on selecting specific data to transmit to my state, as currently it is sending all information when I only require 'firstname', 'lastname', email, and so forth. Below is the NodeJS code snippet for my backend call ...

When Socket.emit is called, it outputs <span> elements within a well-structured message

Currently working on a small chat application using Node.js, Express.js, and Socket.IO. However, I'm encountering an issue with formatting. Instead of displaying the message content within <span> tags as intended, it is printing out the actual t ...

When I restart my NodeJS/Koa.app with Mongoose, I noticed that the Mongo data gets erased

I'm facing an issue where the data stored in my MongoDB instance gets deleted whenever I restart my Node/Koa.app. This application utilizes Mongoose to connect to the local Mongo instance. Here's the code for reference: app.js (I have written c ...

Using Backbone for the front end and Node.js for the backend, this website combines powerful technologies

Currently, I am in the process of developing a new website that will function as a single-page application featuring dialog/modal windows. My intention is to utilize Backbone for the frontend and establish communication with the backend through ajax/webs ...

Incorporating a classList.toggle into a snippet of code

button, p, h1, h2, h3, h4, h5, a{ /* Define specific elements to use "fantasy" font */ font-family: Tahoma; } #main_body{ margin: 0px auto; background-color: #dedede; } #top_body{ /* Remove margin for simplicity */ } #t ...

What is the mechanism behind image pasting in Firefox's imgur integration?

Start by launching an image editing software and make a copy of any desired image. Avoid copying directly from a web browser as I will explain the reason later on. Navigate to "http://imgur.com" using Firefox. To paste the copied image, simply press Ctrl+V ...

Analysis of npm script execution time and performance metrics

Can the performance of npm scripts be measured in a similar way to how time-grunt operates? I'm transitioning some critical build tasks to use npm instead of Grunt because creating my own build script offers more flexibility than relying on certain G ...

Having trouble deploying Node.js due to encountering a require statement error?

After deploying my app on Azure and trying to access the endpoint, I encountered this error message: Error [ERR_REQUIRE_ESM]: require() of ES Module C:\home\site\wwwroot\index.js from C:\Program Files (x86)\iisnode\interc ...

What are the advantages of using global.mongoose for caching the MongoDB connection?

What is the reason for adding global.mongoose to cache the MongoDB connection? import mongoose from 'mongoose' let cached = global.mongoose if (!cached) { cached = global.mongoose = { conn: null, promise: null } } What is the purpose of this ...

pm2 is launching multiple instances of identical next.js applications

I am in the process of deploying my Next.js app on my local PC. Below are the contents of my configuration and package.json files: // package.json { "name": "smarf", "private": true, "scripts": { "dev ...

Building a custom DSL expression parser and rule engine

In the process of developing an app, I have included a unique feature that involves embedding expressions/rules within a configuration yaml file. For instance, users will be able to reference a variable defined in the yaml file using ${variables.name == &a ...

What is the best way to insert an object at a particular position within an array containing numerous nested objects?

This is the given Object: [ { "id": "1709408412689", "name": "WB1", "children": [ { "id": "1709408412690", "n ...

Could one potentially generate new static files in Nextjs without needing to rebuild the entire app?

After recently beginning to utilize NextJs' getStaticProps feature, I have found that the static files generated at build time are quite impressive. However, my content is not static and requires updates without having to rebuild the entire app each t ...

Establishing a connection to SQL Server through the use of Express.js

Having some issues with my code to establish a connection to SQL Server from express.js. I'm trying to handle errors by assigning them to a global variable and returning it at the end of the function, but for some reason the value is always undefined. ...

Is pl/pgsql block code supported by postgres-nodejs?

I am attempting to define a custom UUID variable that can be utilized across multiple queries within a transaction. Initially, I attempted using a JavaScript variable which ultimately defeated the purpose of declaring the variable on the server side. The ...