问题
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