keycloak-connect, which is the recommended NodeJS adapter from the Keycloak docs, does not take into account the X-Forwarded-Proto header when the protected application is sitting behind an Apache reverse proxy.
Indeed the redirectUri is built this way :
let host = request.hostname;
let headerHost = request.headers.host.split(':');
let port = headerHost[1] || '';
let protocol = request.protocol;*
let hasQuery = ~(request.originalUrl || request.url).indexOf('?');
let redirectUrl = protocol + '://' + host + (port === '' ? '' : ':' + port) + (request.originalUrl || request.url) + (hasQuery ? '&' : '?') + 'auth_callback=1';
request.protocol
always is "http" due to the reverse proxy, thus the redirectUri does not have the expected protocol (HTTPS).
If this is intentional and not a bug, is using HTTP in the redirectUri a security flaw even if the client is redirect to HTTPS ? Couldn't the token have been exposed in the meantime ?