code: public OAuthAccessToken refreshToken(RequestContext requestContext, OAuthAccessToken token) {
      OAuthAccessToken result = token;
      
      String[] scopes = token.getScopes();
      String tokenUrl = String.format("%s/realms/%s/protocol/openid-connect/token", getServerUrl(), getRealm());
      
      HttpPost httpPost = new HttpPost(tokenUrl);
      
      try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("client_id", getApiKey()));
        params.add(new BasicNameValuePair("client_secret", getApiSecret()));
        params.add(new BasicNameValuePair("grant_type", "refresh_token"));
        params.add(new BasicNameValuePair("refresh_token", token.getRefreshToken()));
  
        httpPost.setEntity(new UrlEncodedFormEntity(params));
        try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
          StatusLine statusLine = response.getStatusLine();
          
          if (statusLine.getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            
            ObjectMapper objectMapper = new ObjectMapper();
            try (InputStream stream = entity.getContent()) {
              RefreshTokenResponse refreshTokenResponse = objectMapper.readValue(stream, RefreshTokenResponse.class);
              Date expiresAt = getExpiresAt(refreshTokenResponse.getExpiresIn());
              result = new OAuthAccessToken(token.getExternalId(), refreshTokenResponse.getAccessToken(), refreshTokenResponse.getRefreshToken(), expiresAt, scopes);
              AuthUtils.purgeOAuthAccessTokens(requestContext, getName());
              AuthUtils.storeOAuthAccessToken(requestContext, getName(), result);            
            }
            
            EntityUtils.consume(entity);
          } else {
            logger.log(Level.WARNING, String.format("Failed to refresh access token with message [%d]: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase()));
          }
        }
      } catch (IOException e) {
        logger.log(Level.WARNING, "Failed to refresh access token", e);
      }
      
      return result;
    }
docs: Refreshes the access token
  
  @param requestContext request context
  @param token token
  @return refreshed token