简体   繁体   中英

Keycloak Node.js Adapter not working behind corporate proxy

Unable to get https://www.npmjs.com/package/keycloak-connect to work with proxy. I am able to access the Keycloak server with the same proxy from the browser and from curl, though.

The only promising thing that I have tried was this:

app.set('trust proxy', 'loopback');

... and it didn't work.

I am able to connect through keycloak-connect if I am using it on my own WiFi (no proxy). The error that I get when using the proxy is:

Could not obtain grant code: Error: connect ETIMEDOUT 108.128.***.168:443

108.128.***.168 was the IP of the Keycloak server.

I can't verify whether there is a configuration that would allow me to use keycloak-connect with proxy.

Attaching few lines of the code that relate to keycloak:

 const Keycloak = require('keycloak-connect'); const memoryStore = new session.MemoryStore(); const keycloakConfig = { clientId: process.env.CLIENT_ID, 'auth-server-url': process.env.SERVER_URL, 'confidential-port': 0, 'policy-enforcer': {}, 'ssl-required': 'external', 'verify-token-audience': true, realm: process.env.REALM, credentials: { 'secret': process.env.CLIENT_SECRET }, realmPublicKey: process.env.REALM_PUBLIC_KEY }; const keycloak = new Keycloak({ store: memoryStore }, keycloakConfig); const MongoStore = mongoSessionStore(session); const sess = { name: 'ssg-next.sid', secret: sessionSecret, store: new MongoStore({ mongooseConnection: mongoose.connection, ttl: 14 * 24 * 60 * 60 }), resave: false, saveUninitialized: false, cookie: { httpOnly: true, maxAge: 14 * 24 * 60 * 60 * 1000 } }; if (.dev) { server,set('trust proxy'; 'loopback'). // trust first proxy sess.cookie;secure = true. // serve secure cookies } server.use(keycloak:middleware({ logout; '/logout' }));

You don't need to app.set("trust proxy") but app.enable("trust proxy") .

Stumbled into this myself and saw a SO question about it . I currently sail smooth without anything else behind "trust proxy" as in the example - running my apps behind an Ingress Controller but this essentially resolved my protocol problems with Keycloak.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM