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);
}
}
if (serverToken == null) {
return createErrorResponse(params, OAuthConstants.INVALID_GRANT);
}
// Extract the information to be of use for the client
ClientAccessToken clientToken = new ClientAccessToken(serverToken.getTokenType(),
serverToken.getTokenKey());
clientToken.setRefreshToken(serverToken.getRefreshToken());
if (isWriteOptionalParameters()) {
clientToken.setExpiresIn(serverToken.getExpiresIn());
List<OAuthPermission> perms = serverToken.getScopes();
if (!perms.isEmpty()) {
clientToken.setApprovedScope(OAuthUtils.convertPermissionsToScope(perms));
}
clientToken.setParameters(serverToken.getParameters());
}
// Return it to the client
return Response.ok(clientToken)
.header(HttpHeaders.CACHE_CONTROL, "no-store")