I am new to keycloak, so there is a high chance I don't understand something going on here. Im currently trying to understand how to use Keycloak, so I have set up a small demo application:
- Its the application from IntelliJ JavaEE tutorial which runs on the root context path
/app - I use it dockerized on a Wildfly Server
jboss/wildfly:17.0.0.Final, WILDFLY keycloak adapter already installed. Traefikproxy is used to reach the app on the browser usinghttp://localhost/appand keycloak usinghttp://keycloak.localhost- Keycloak docker container is reachable from the network using alias
keycloak, but I use environment variableKEYCLOAK_FRONTEND_URL=http://keycloak.localhost/authto set another URL for frontend related stuff - I have created a realm
javaee-realmand one client for my application calledjavaee-app. Also, one user called "user" with a role of "user" is configured in Keycloak. - When accessing the app in the browser using
http://localhost/app, I get redirected to Keycloak where I can login as User "user". I get redirected back to the application afterwards.
The Problem:
When logging out by destroying the session inside Keycloak Dashboard or by accessing http://keycloak.localhost/auth/realms/javaee-realm/protocol/openid-connect/logout the session gets deleted, but I can still use the application. Usually, I would expect to be redirected to Keycloak again. After some time, an error is logged in the application container:
16:09:48,285 ERROR [org.keycloak.adapters.RefreshableKeycloakSecurityContext] (default task-1) Refresh token failure status: 400 {"error":"invalid_grant","error_description":"Stale token"}
Wildfly Adapter Configuration standalone.xml
[...]
<subsystem xmlns="urn:jboss:domain:keycloak:1.2">
<secure-deployment name="javaee-application.war">
<realm>javaee-realm</realm>
<auth-server-url>http://keycloak:8080/auth</auth-server-url>
<ssl-required>none</ssl-required>
<resource>javaee-app</resource>
<principal-attribute>preferred_username</principal-attribute>
<public-client>true</public-client>
</secure-deployment>
</subsystem>
[...]
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<module-name>javaee-application</module-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>All other resources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>KEYCLOAK</auth-method>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
</web-app>
Client Configuration in Keycloak
The expected behavior occurs when I delete the JSESSIONID cookie in my browser. So, after deletion, I get redirected to Keycloak when I try to access the application. But obv this is no solution...
Does anyone know what the problem here is precisely?
