// Make sure the client is authenticated
Client client = authenticateClientIfNeeded(params);
// Find the grant handler
AccessTokenGrantHandler handler = findGrantHandler(params);
if (handler == null) {
return createErrorResponse(params, OAuthConstants.UNSUPPORTED_GRANT_TYPE);
}
// Create the access token
ServerAccessToken serverToken = null;
try {
serverToken = handler.createAccessToken(client, params);
} catch (OAuthServiceException ex) {
OAuthError customError = ex.getError();
if (writeCustomErrors && customError != null) {
return createErrorResponseFromBean(customError);
}