title: How to overwrite Spring Cloud OAuth2 client autoconfiguration?
body: <p>We want to setup a microservice which provides a REST API so it is configured as a OAuth2 resource server. This service should also act as a OAuth2 client with the client credential grant. Here is the configuration:</p>
  
  <pre><code>spring.oauth2.client.id=clientCredentialsResource
  spring.oauth2.client.accessTokenUri=http://localhost:9003/oauth/token
  spring.oauth2.client.userAuthorizationUri=http://localhost:9003/oauth/authorize
  spring.oauth2.client.grantType=client_credentials
  spring.oauth2.client.clientId=&lt;service-id&gt;
  spring.oauth2.client.clientSecret=&lt;service-pw&gt;
  </code></pre>
  
  <p>The resource server part works fine. For the client part we want to use Feign, Ribbon and Eureka:</p>
  
  <pre><code>@FeignClient("user")
  public interface UserClient
  {
    @RequestMapping( method = RequestMethod.GET, value = "/user/{uid}")
    Map&lt;String, String&gt; getUser(@PathVariable("uid") String uid);
  }
  </code></pre>
  
  <p>Based on the gist in issue <a href="https://github.com/spring-cloud/spring-cloud-security/issues/56">https://github.com/spring-cloud/spring-cloud-security/issues/56</a> I created a feign request intercepter which sets the access token from the autowired OAuth2RestOperations template in the feign request header </p>
  
  <pre><code>@Autowired
  private OAuth2RestOperations restTemplate; 
  
  template.header(headerName, String.format("%s %s", tokenTypeName, restTemplate.getAccessToken().toString()));
  </code></pre>
  
  <p>But this gives me the error on calling the user service: </p>
  
  <pre><code>error="access_denied", error_description="Unable to obtain a new access token for resource 'clientCredentialsResource'. The provider manager is not configured to support it.
  </code></pre>
  
  <p>As I can see the OAuth2ClientAutoConfiguration creates always an instance of AuthorizationCodeResourceDetails for an web application but not the required ClientCredentialsResourceDetails which is only used for non-web applications. In the end the no access token privider is responsible for the resource details and the call failed in </p>
  
  <pre><code>AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:146) 
  </code></pre>
  
  <p>I tried to overwrite the auto configuration but failed. Can somebody please give me a hint how to do it?</p>