Hello,
we have a desktop application that is using access-tokens to communicate with a server. It is vital for the application that the tokens are always valid, so we go to great lengths to ensure just that.
Of course, the application always automatically refreshes the tokens before they expire. The issue arises when the keycloak-session of the user ends.
Since our update from Keycloak 3.2.1 to 6.0.1 we see that the expire-claims of the access- and refresh-tokens now reflect the end of the user session (see
https://issues.redhat.com/browse/KEYCLOAK-4215). While I understand the reasoning behind this change, this change actually is a huge issue for us. Before this change, the access-token was valid for longer than user session, so our servers still accepted the tokens while the user was able to attempt a re-login in parallel, thus creating a new session and new tokens without any interruption of our application. This doesn't work anymore with current versions of Keycloak.
Currently there doesn't seem to be any way to extend the session of the user before the current session has timed out. Because of this, there is no way to ensure that there are always valid tokens available without any interruption. One has to wait for the session/tokens to expire before a re-login creates a new session. If you try to force a re-login of the user by using the parameter "login=prompt", Keycloak asks for the credentials again (as expected) but there is no new session created and the current session is not extended. (Related issue: There is no way for the client application to know when the user session ends. There is no claim inside the access-token or inside the response of the token-Endpoint that indicates the end of the user session.)
So, my question really comes down to this: How can I ensure that my application always uses valid tokens even when the user-session ends? To make it clear: There is always a user in front of the application, so user interaction can be enforced at any time. If "login=prompt" could be used to extend the session of the user (and if there was a way to tell when the session ends), this issue could be solved by forcing the user to re-login just before the session ends.