session.setAttribute("user", user);
}
private Tokens fetchTokens(HttpServletRequest req) throws IOException {
String authorizationCode = getAuthorizationCode(req);
Resty resty = createResty();
String tokenUri = getTokenUri();
JSONObject json = new JSONObject();
try {
json.put("client_id", properties.get("auth0.client_id"));
json.put("client_secret", properties.get("auth0.client_secret"));
json.put("redirect_uri", req.getRequestURL().toString());
json.put("grant_type", "authorization_code");
json.put("code", authorizationCode);
JSONResource tokenInfo = resty.json(tokenUri, content(json));
return new Tokens(tokenInfo.toObject());
} catch (Exception ex) {
throw new IllegalStateException("Cannot get Token from Auth0", ex);
}