String accessTokenResponse = accessTokenConnection.getResponseAsString();
return new JSONObject(accessTokenResponse);
}
private JSONObject getUserInfo(String accessToken, String tokenType, HttpServletResponse httpResponse) throws IOException {
HttpGetMethod getMethod = new HttpGetMethod(new URL(this.userInfoEndpoint));
getMethod.setHeader("Authorization", tokenType + " " + accessToken);
HttpConnection userInfoConnection = getMethod.openConnection();
if (userInfoConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
LOGGER.error("Request for user information failed: %s", userInfoConnection.getResponseMessage());
httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return null;