I have a nodejs express application with keycloak adapter protecting https://example.com (with SSL)
My keycloak adapter is configured this way:
Notice the httpS in both URLs.
Now I am facing an issue, when the user login successfully (via keycloak) he is presented with a "Invalid Parameter: redirect_uri" error message.
Using the browser devtools I see after going to https://example.com (with SSL) the user is redirected to https://sso.example.com/auth/realms/myrealm/protocol/openid-connect/auth?client_id=my-client-id&state=22f41ed3-ddc6-4758-970b-d876cf631ded&redirect_uri=http%3A%2F%2Fexample.com%2F%3Fauth_callback%3D1&scope=openid&response_type=code
And the key point in the link above is redirect_uri=http%3A%2F%2Fexample.com%2F%3Fauth_callback%3D1&scope=openid&response_type=code
. Here we can see the redirect_uri
has no SSL. It is http instead of https.
This is how I protect the root of my domain:
const server = express()
server.set('trust proxy', 'loopback')
server.use(keycloak.middleware({}))
const keycloak = new Keycloak({ store: memoryStore }, KEYCLOAK_CONFIG) // KEYCLOAK_CONFIG is the json config below
(...)
server.get('/', keycloak.protect('private-user'), (req: Request, res: Response) => {
// Set the cookie
res.cookie(ConfigService.CONFIG_COOKIE_KEY, JSON.stringify(ConfigService.CONFIG), { httpOnly: false })
res.sendFile(path.join(__dirname, 'build', 'index.html'))
return res
})
And my keycloak configuration is:
{
realm: 'myrealm',
'auth-server-url': 'https://sso.example.com/auth/',
'ssl-required': 'external',
resource: 'my-client-id',
'verify-token-audience': false,
credentials: { secret: 'super-secret-credential' },
'use-resource-role-mappings': true,
'confidential-port': 443,
'bearer-only': false,
'enable-cors': true,
'cors-max-age': 1000,
'enable-basic-auth': false,
'expose-token': true,
'disable-trust-manager': false,
'allow-any-hostname': false,
'token-minimum-time-to-live': 10,
'min-time-between-jwks-requests': 10,
'connection-pool-size': 20,
'public-key-cache-ttl': 86400
}
The redirect_uri
must be with SSL. How can I force keycloak to use https (SSL) in redirect_uri?
Adding http://example.com (non SSL) to the Valid Redirect URIs
is not an option.