Oauth2ClientRestTemplate { public OAuth2RestOperations clientCredentialsRestTemplate(String client_id, String client_secret, String access_token_uri, String... scope) { if (!access_token_uri.contains("token")) throw new RuntimeException("uri is wrong : access_token_uri = " + access_token_uri); ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails(); details.setId("4"); details.setClientId(client_id); if (client_secret != null && !client_secret.isEmpty()) details.setClientSecret(client_secret); details.setAccessTokenUri(access_token_uri); details.setScope(Arrays.asList(scope)); return new OAuth2RestTemplate(details, oAuth2ClientContext); }  OAuth2RestOperations authorizationCodeRestTemplate(String client_id, String client_secret, String authorization_uri, String access_token_uri, String... scope); @Deprecated OAuth2RestOperations implicitResourceRestTemplate(String client_id, String client_secret, String authorization_uri, String access_token_uri, String... scope); @Deprecated OAuth2RestOperations resourceOwnerPasswordRestTemplate(String client_id, String client_secret, String access_token_uri, String username, String password, String... scope); OAuth2RestOperations clientCredentialsRestTemplate(String client_id, String client_secret, String access_token_uri, String... scope);  }
@Test public void testClientCredentialsRestTemplate() throws Exception { ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails(); details.setId("4"); details.setClientId(client_id); details.setClientSecret(client_secret); details.setAccessTokenUri(access_token_uri); OAuth2RestTemplate operations = new OAuth2RestTemplate(details,new DefaultOAuth2ClientContext()); operations.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider()); DefaultOAuth2AccessToken token=(DefaultOAuth2AccessToken)operations.getAccessToken(); token.setTokenType("Bearer"); System.out.println("client_id : " + client_id); System.out.println("source_url : " + source_url); System.out.println(JSON.toJSONString(operations.getForObject(source_url, JsonNode.class))); }