title: How to login using oauth in Springboot / Spring
body: <p>We have one authservice that is running on different machine and this it provides oauth login.
  So I need to write a client to get a access token. For that I wrote following piece of code. but its not working. </p>
  
  <pre><code>String polarisOauthURL = "https://test.com/auth/oauth/token";
          ClientCredentialsResourceDetails resourceDetails  = new ClientCredentialsResourceDetails ();
          resourceDetails.setAccessTokenUri(polarisOauthURL);
          resourceDetails.setClientId("test");
          resourceDetails.setClientSecret("test");
          resourceDetails.setGrantType("client_credentials");
          List&lt;String&gt; scope = new ArrayList&lt;&gt;();
          scope.add("read");
  //        scope.add("write");
          resourceDetails.setScope(scope);
          DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
          OAuth2RestTemplate oauthRestTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
  
          List messageConverters = new ArrayList&lt;&gt;();
          messageConverters.add(new MappingJackson2HttpMessageConverter());
          oauthRestTemplate.setMessageConverters(messageConverters);
  
          System.out.println("access token: " + oauthRestTemplate.getAccessToken());
  </code></pre>
  
  <p>when the last line getAccessToken executed it thows an following error.</p>
  
  <pre><code>error="access_denied", error_description="Error requesting access token."
      at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:145)
      at org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider.obtainAccessToken(ClientCredentialsAccessTokenProvider.java:44)
      at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:148)
      at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:121)
      at org.springframework.security.oauth2.client.OAuth2RestTemplate.acquireAccessToken(OAuth2RestTemplate.java:221)
      at org.springframework.security.oauth2.client.OAuth2RestTemplate.getAccessToken(OAuth2RestTemplate.java:173)
  </code></pre>
  
  <p>but when I am trying to the same thing from console then its working fine. </p>
  
  <pre><code>curl --user test:test --data 'grant_type=client_credentials' https://test.com/auth/oauth/token
  </code></pre>
  
  <p>Could someone help me how I can achieve this think in spring.</p>
  
  <p>Thanks</p>