OAuthClientRequest request = OAuthClientRequest.tokenProvider(oauthParams.getProviderType()).setGrantType(oauthParams.getGrantType()).setClientId(oauthParams.getClientKey()).setClientSecret(oauthParams.getClientSecret()).setRedirectURI(oauthParams.getRedirectURI()).setCode(code).buildBodyMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
// Send request to oauth server
OAuthAccessTokenResponse oauthAccessTokenResponse = oAuthClient.accessToken(request, oauthParams.getTokenResponseClass());
OAuthConsumer consumer = oauthParams.getNewOAuthConsumer(oauthAccessTokenResponse);
return consumer;
} catch (OAuthSystemException e) {
// Error building request