OAuth 2.0 OpenID Connect Loopback and Keycloak

自古美人都是妖i 提交于 2019-12-21 20:09:07

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/37056089/oauth-2-0-openid-connect-loopback-and-keycloak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!