@Override
    public BearerTokenCredentialsBean generateToken(HttpServletRequest request) {
        BearerTokenCredentialsBean bean = new BearerTokenCredentialsBean();

        KeycloakSecurityContext session = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());
        if (session != null) {
            bean.setToken(session.getTokenString());
            int nowInSeconds = getCurrentTime();
            long expiresInSeconds = session.getToken().getExp();

            if (expiresInSeconds <= nowInSeconds) {
                bean.setRefreshPeriod(1);
            } else {
                bean.setRefreshPeriod(expiresInSeconds - nowInSeconds);
            }
        } else {
            bean.setToken("LOGGED_OUT"); //$NON-NLS-1$
            bean.setRefreshPeriod(30);
        }

        return bean;
    }
@see io.apiman.manager.ui.server.auth.ITokenGenerator#generateToken(javax.servlet.http.HttpServletRequest)
manager/ui/war/src/main/java/io/apiman/manager/ui/server/kc/KeyCloakBearerTokenGenerator.java