I think the refresh token issue can be resolved this way, though the code for obtaining a new token still need to be written (AFAIK it is not yet implemented):
Code:
public class OAuth2RestTemplate extends RestTemplate {
...
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
} catch (ExpiredTokenException e) {
OAuth2AccessToken accessToken = OAuth2SecurityContextHolder.getContext().getAccessTokens().get(resource.getId());
if (accessToken.getRefreshToken() != null) {
// TODO: get a new token, store it in the context
// now retry
return super.doExecute(url, method, requestCallback, responseExtractor);
}
}
}
}