Keycloak refresh expired token when using Webfilter

Discussão em 'StackOverflow' iniciado por Stack, Maio 17, 2021.

  1. Stack

    Stack Membro Participativo

    I am faced with an issue where I think I need a sliding expiration time for my access token. I am running on a glassfish server using the org.keycloak.adapters.servlet.KeycloakOIDCFilter to inspect all requests. The filter I have setup inspects the AccessToken and interrogates access by making sure the token is not expired by:

    KeycloakSecurityContext kc = (KeycloakSecurityContext) req
    .getAttribute(KeycloakSecurityContext.class.getName());

    AccessToken token = RSATokenVerifier.create(kc.getIdTokenString()).getToken();
    if(token.isExpired()) {
    response.redirect("logout url");
    }


    This works fine. However, in my application, I have screens where users can spending up to an hour entering info where they could be kicked out before they are finished providing for a bad user experience. There are also cases where ajax calls are being made and the response is set to redirect to a logout page causing bad behavior.

    I really think I need to always inspect the expiration, but I am unsure of how to request a new token when it is expired. I appreciate any help I can get. Thank you!

    These are my token settings [​IMG]

    Continue reading...

Compartilhe esta Página