OAuth 2.0 OpenID Connect Loopback and Keycloak
Asked Answered
C

1

4

I'm unable to connect to Keycloak from Loopback.

I've been trying to use the keycloak-connect lib:

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

This is my current 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');
    })

};'

Seems quite simple but it gets stuck in a redirection loop.

I've also tried swapping

server.use(session

with

 server.use(keycloak

But then see "Cannot read property 'keycloak-token' of undefined"

Been stuck on this for a while and tried everything. Any other ideas?

Thanks in advance!

Colunga answered 5/5, 2016 at 16:54 Comment(0)
L
2

It seems that you might need to tell your Keycloak instance to use the Memory Store you create when you initialize it, like so:

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

Hope that fixes the problem.

Lisbethlisbon answered 6/5, 2016 at 1:44 Comment(1)
Sorry there was a typo, I do init with memory storeColunga

© 2022 - 2024 — McMap. All rights reserved.