int clientID,
String clientSecret,
String redirectUri,
String code) throws CreateSendException {
JerseyClient oauthClient = new JerseyClientImpl(null);
String body = "grant_type=authorization_code";
try {
body += "&client_id=" + String.valueOf(clientID);
body += "&client_secret=" + URLEncoder.encode(clientSecret, urlEncodingScheme);
body += "&redirect_uri=" + URLEncoder.encode(redirectUri, urlEncodingScheme);
body += "&code=" + URLEncoder.encode(code, urlEncodingScheme);
} catch (UnsupportedEncodingException e) {
body = null;
}
// TODO: Use a custom error deserialiser in the following post
OAuthTokenDetails result = oauthClient.post(
Configuration.Current.getOAuthBaseUri(), OAuthTokenDetails.class, body,
MediaType.APPLICATION_FORM_URLENCODED_TYPE, "token");
return result;
}