title: Creating a Client Spring Security OAuth2 Applicaiton
body: <p>I have the following architecture in my project: </p>
  
  <pre><code> JOB_SCHEDULE ---&gt; API A  ---&gt; API B
  </code></pre>
  
  <p>My JOB_SCHEDULE call API A without any authentication and this is ok for us. But API A need to call API B, and this last have a client_credentials authentication. </p>
  
  <p>We have a IdentityServer to generate this tokens, so in <strong>API A</strong> I configured the following:</p>
  
  <pre><code>security.oauth2.client.client-id=clientid
  security.oauth2.client.client-secret=secret
  security.oauth2.client.access-token-uri=http://localhost:8080/oauth/token
  security.oauth2.client.user-authorization-uri=http://localhost:8080/oauth/authorize
  security.oauth2.client.grant-type=client_credentials
  security.oauth2.client.authentication-scheme=form
  </code></pre>
  
  <p>And in my pom.xml:</p>
  
  <pre><code>&lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security.oauth.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-oauth2-autoconfigure&lt;/artifactId&gt;
              &lt;version&gt;2.1.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security.oauth&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-oauth2&lt;/artifactId&gt;
              &lt;version&gt;2.3.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>And i have a endpoint in <strong>API A</strong> that call API B, see:</p>
  
  <pre><code>private final OAuth2RestTemplate restTemplate;
  
      @GetMapping("/sayhello")
      public ResponseEntity&lt;String&gt; redirectToResourceServer() {
          String strReturn = restTemplate.getForObject("http://localhost:9090/noscope", String.class);
          return ResponseEntity.ok(strReturn);
      }
  </code></pre>
  
  <p>But everytime I call <code>http://localhost/api/v1/hello/sayhello</code> I'm redirected to login page, but this is client_credentials I should not be redirected.</p>