title: How to get the last login session details of a user in Keycloak using Keycloak rest endpoints?
body: <p>How to get the last login session details of a user in Keycloak using keycloak rest endpoints?</p>
  
  <p>Example:</p>
  
  <pre><code>builder.append(OAuth2Constants.AUDIENCE+"="+clientId+"&amp;");
  builder.append(OAuth2Constants.GRANT_TYPE+"="+OAuth2Constants.UMA_GRANT_TYPE+"&amp;");
  headers.put("Content-Type", "application/x-www-form-urlencoded");
  headers.put("Authorization", "Bearer "+accessToken);
  
  //String keycloakURL = keyCloakCFGBean.getCreateRefreshSession();
  String keycloakURL="http://10.10.8.113:10004/auth/realms/{realm}/protocol/openid-connect/token";
  keycloakURL = keycloakURL.replace("{realm}", realmName);
  
  URL url = new URL(keycloakURL);
  httpURLConnection  = (HttpURLConnection) url.openConnection();
  httpURLConnection.setUseCaches(false);
  httpURLConnection.setDoInput(true);
  httpURLConnection.setRequestMethod("POST");
  httpURLConnection.setDoOutput(true);
  if (headers != null &amp;&amp; headers.size() &gt; 0) {
      Iterator&lt;Entry&lt;String, String&gt;&gt; itr = headers.entrySet().iterator();
      while (itr.hasNext()) {
          Entry&lt;String, String&gt; entry = itr.next();
          httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
      }
  }
  
  outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream(), StandardCharsets.UTF_8);
  outputStreamWriter.write(builder.toString());
  outputStreamWriter.flush();
  </code></pre>