return;
}
// always verify code and remove access code from map before authenticating user
// if user authentication fails, we want the code to be removed irreguardless just in case we're under attack
String code = request.getParameter("code");
JWSInput input = new JWSInput(code, providers);
boolean verifiedCode = false;
try
{
verifiedCode = RSAProvider.verify(input, realmPublicKey);
}
catch (Exception ignored)
{
log.error("Failed to verify signature", ignored);
}
if (!verifiedCode)
{
Map<String, String> res = new HashMap<String, String>();
res.put("error", "invalid_grant");
res.put("error_description", "Unable to verify code signature");
response.sendError(400);
response.setContentType("application/json");
mapWriter.writeValue(response.getOutputStream(), res);
response.getOutputStream().flush();
return;
}
String key = input.readContent(String.class);
AccessCode accessCode = accessCodeMap.remove(key);
String redirect = request.getParameter("redirect_uri");
GenericPrincipal gp = basicAuth(request, response);
if (gp == null)