How to honour Keycloak sessions when using websockets?

We have a webapp which establishes a socket connection to make calls to backend services.

We authenticate using a Keycloak server. If receive a valid access token from Keycloak, we establish a websocket connection to our backend services.

If the Keycloak session expires, the websocket connection remains intact.

Is anyone aware of any patterns or examples or documentation, which would result in the websocket closing when the Keycloak session expires?


are you using If so, supports the WAMP meta API which incudes a procedure to actively kick (another) WAMP-WebSocket session:

So in, I would configure a custom authenticator that authenticates incoming WAMP-WebSocket connection against this Keycloak thingy, and starts a server-side time to call into above meta API to kill the WAMP-WebSocket session whenever the Keycloak token expires.


Thanks heaps Tobias.

Yes, we are using and we are using a custom authenticator, so we are able to implement something along the lines of what you suggest.