private JWSToken refreshToken(String accessToken, String refreshToken) throws IOException, InvalidTokenException{
JWSToken token = null;
String url = "http://127.0.0.1:8080/auth/realms/myrealm/tokens/refresh";
//String query = “refresh_token=“ + refreshToken;
//String query = “refresh_token=“ + refreshToken + “client_id=" + CLIENT_ID";
String query = "refresh_token=" + refreshToken + "client_id=" + CLIENT_ID + "grant_type=refresh_token";
//Tried all the above
HttpPost httppost = new HttpPost(url);
httppost.addHeader(“Authorization”, “Bearer “ + accessToken); //401 with 400 without
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
ByteArrayEntity entity = new ByteArrayEntity(query.getBytes());
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK){
InputStream stream = null;
try{
stream = response.getEntity().getContent();
ObjectMapper mapper = new ObjectMapper();
token = mapper.readValue(stream, JWSToken.class);
}finally{
if (stream != null){
stream.close();
}
}
}else{
throw new InvalidTokenException();
}
return token;
}