@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
try{
OAuth2Message requestMessage = OAuth2Servlet.getMessage(request, null);
OAuth2Client client = SampleOAuth2Provider.getClient(requestMessage);
String userId = request.getParameter("userId");
if(userId == null){
SampleOAuth2Provider.VALIDATOR.validateRequestMessageForAuthorization(requestMessage,client);
sendToAuthorizePage(request, response, client);
}
OAuth2Accessor accessor = new OAuth2Accessor(client);
// set userId in accessor and mark it as authorized
SampleOAuth2Provider.markAsAuthorized(accessor, userId);
String requested = requestMessage.getParameter(OAuth2.RESPONSE_TYPE);
if (requested.equals(OAuth2.ResponseType.CODE)) {
SampleOAuth2Provider.generateCode(accessor);
returnToConsumer(request, response, accessor);
}else if (requested.equals(OAuth2.ResponseType.TOKEN)){
// generate refresh token here but do not send back that