I have exactly the same problem in a spring (non spring boot) application running behind an apache reverse proxy.
Reverse proxy is configured with:
ProxyRequests Off
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
Keycloak.json:
"realm": "myrealm",
"resource": "myresource",
"auth-server-url": "https://login.sso-migration.example.com/auth",
"ssl-required": "all",
"confidential-port": 443,
"use-resource-role-mappings": true,
"bearer-only": false,
"enable-basic-auth": false,
"expose-token": false,
"credentials": {
"secret": "mysecret"
},
"connection-pool-size": 20,
"disable-trust-manager": true,
"allow-any-hostname": true
The protocol of the redirect_uri param for the keycloak request is correctly “https” (since adding ssl-required: all to keycloak.json) and the port is blank since adding confidential-port: 443.
Nevertheless the request fails at my application:
S 2022-09-09 15:46:52,777 [http-nio-8080-exec-607] DEBUG org.keycloak.adapters.PreAuthActionsHandler - adminRequest http://myapp.example.com/myapp/
S 2022-09-09 15:46:52,780 [http-nio-8080-exec-607] DEBUG org.keycloak.adapters.OAuthRequestAuthenticator - there was no code
S 2022-09-09 15:46:52,781 [http-nio-8080-exec-607] DEBUG org.keycloak.adapters.OAuthRequestAuthenticator - redirecting to auth server
S 2022-09-09 15:46:52,781 [http-nio-8080-exec-607] DEBUG org.keycloak.adapters.OAuthRequestAuthenticator - callback uri: http://myapp.example.com/myapp/
S 2022-09-09 15:46:52,784 [http-nio-8080-exec-607] DEBUG org.keycloak.adapters.OAuthRequestAuthenticator - Sending redirect to login page: https://login.sso-migration.example.com/auth/realms/myrealm/protocol/openid-connect/auth?response_type=code&client_id=myresource&redirect_uri=https%3A%2F%2Fmyapp.example.com%2Fmyapp%2F&state=aaf2342b-82d5-4dac-9010-dcc6029c8a4e&login=true&scope=openid
S 2022-09-09 15:48:13,729 [http-nio-8080-exec-605] DEBUG org.keycloak.adapters.PreAuthActionsHandler - adminRequest http://myapp.example.com/myapp/?state=aaf2342b-82d5-4dac-9010-dcc6029c8a4e&session_state=cf46dace-7b9f-4850-929e-9e11da30b75c&code=80c24aec-ff10-41a2-a9f5-89332ac2362f.cf46dace-7b9f-4850-929e-9e11da30b75c.32c18f21-6c95-4a6a-a757-a8a0a2710924
S 2022-09-09 15:48:13,732 [http-nio-8080-exec-605] DEBUG org.keycloak.adapters.OAuthRequestAuthenticator - there was a code, resolving
S 2022-09-09 15:48:13,732 [http-nio-8080-exec-605] ERROR org.keycloak.adapters.OAuthRequestAuthenticator - Adapter requires SSL. Request: http://myapp.example.com/myapp/?state=aaf2342b-82d5-4dac-9010-dcc6029c8a4e&session_state=cf46dace-7b9f-4850-929e-9e11da30b75c&code=80c24aec-ff10-41a2-a9f5-89332ac2362f.cf46dace-7b9f-4850-929e-9e11da30b75c.32c18f21-6c95-4a6a-a757-a8a0a2710924
Finally I am not sure whether setting “ssl-required” to “all” is the correct way to get keycloak to write a “https”-redirect_uri. I thought that configuring reverse proxy with
"RequestHeader set X-Forwarded-Proto "https"
could be enough but it isn’t.
Any ideas what else to try?