I am using keycloak 4.8.3 and wildfly-14.0.1 in my Java Application. Facing problem in deleting session from Servelet Filter. Below are approaches which i tried.
Approach 1:
I am using HttpServletRequest.logout()
to delete session from keycloak.This approach is not working for me and i am getting refresh-token
equal to NULL
Approach 2: But when i trigger rest call using curl command with access token provided.
curl -X POST -k -H 'Content-Type: application/x-www-form-urlencoded' \
-i 'https://authserver/auth/realms/{realm}/protocol/openid-connect/logout' \
--data 'username=abc&password=def&client_id=client-id&grant_type=refresh_token&client_secret=a682049d-587c-4c38-a594-814f08b0ca7&refresh_token=<refresh_token>'
This approach2 working fine.
I am not sure why in case of Java ,I am getting refresh-token NULL? Below is the code
KeycloakSecurityContext keycloakSecurityContext = (KeycloakSecurityContext)httpRequest.getAttribute( KeycloakSecurityContext.class.getName() );
if(keycloakSecurityContext instanceof RefreshableKeycloakSecurityContext) {
RefreshableKeycloakSecurityContext ksc = (RefreshableKeycloakSecurityContext)keycloakSecurityContext;
RefreshToken refreshToken = ksc.getRefreshToken();
RefreshToken refreshTokenDecoded = TokenUtil.getRefreshToken(refreshToken);