* @return New OAuthTokenDetails instance containing the new access token,
* 'expires in' value, and refresh token.
*/
public OAuthTokenDetails refreshToken() throws CreateSendException {
OAuthTokenDetails result = null;
AuthenticationDetails auth = this.jerseyClient
.getAuthenticationDetails();
if (auth != null && auth instanceof OAuthAuthenticationDetails) {
OAuthAuthenticationDetails oauthDetails = (OAuthAuthenticationDetails) auth;
String body = "grant_type=refresh_token";
try {
body += "&refresh_token="
+ URLEncoder.encode(oauthDetails.getRefreshToken(),
urlEncodingScheme);
} catch (UnsupportedEncodingException e) {
body = null;
}
JerseyClient oauthClient = new JerseyClientImpl(null);
// TODO: Use a custom error deserialiser in the following post
result = oauthClient.post(Configuration.Current.getOAuthBaseUri(),
OAuthTokenDetails.class, body,
MediaType.APPLICATION_FORM_URLENCODED_TYPE, "token");
if (result != null && result.access_token != null
&& result.refresh_token != null) {
AuthenticationDetails newAuthDetails = new OAuthAuthenticationDetails(
result.access_token, result.refresh_token);
this.jerseyClient.setAuthenticationDetails(newAuthDetails);
}
}
return result;