title: Spring boot 2.0.3 + Security + Oauth2 autoconfigure
body: <p>Spring boot 2.0.3 + Security + Oauth2 autoconfigure</p>
  
  <p>I'm working with OAuth2 and microservices, I've created a microservice to generate the authorization tokens and another microservice as a client. Generation of tokens is working, but when I try to use this generated token on the client service to authenticate, it is not working.</p>
  
  <p>Microservice that generates the tokens: localhost:9999</p>
  
  <p>Token generated with url: estrutura:estruturasecret@localhost:9999/oauth/token</p>
  
  <pre><code>   [
         {
            "key":"grant_type",
            "value":"password"
         },
         {
            "key":"username",
            "value":"matheus"
         },
         {
            "key":"password",
            "value":"teste"
         },
         {
            "key":"client_id",
            "value":"estrutura"
         }
      ]
  </code></pre>
  
  <p>return: </p>
  
  <pre><code> {
          "access_token": "2e4c26b3-0fcf-493e-a255-6216b98811c5",
          "token_type": "bearer",
          "refresh_token": "5e33740a-ccb9-4ec1-94be-3a4643b8097a",
          "expires_in": 42479,
          "scope": "read write"
      }
  </code></pre>
  
  <p>Customer Microservice: localhost:9090</p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  @EnableResourceServer
  public class ClientServer {
     public static void main(String[] args) {
        SpringApplication.run(ClientServer.class, args);
     }
  }
  </code></pre>
  
  <p>application.yml:</p>
  
  <pre><code>server:
    port: 9090
    servlet:
      context-path: /client
  spring:
    application:
      name: client-server
    security:
      oauth2:
        client:
          client-id: estrutura
          client-secret: estruturasecret
          access-token-uri: localhost:9999/oauth/token
          user-authorization-uri: localhost:9999/oauth/authorize
        resource:
          token-info-uri: localhost:9999/oauth/check_token
  logging:
    level:
      org.springframework.security: DEBUG
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>&lt;error&gt;invalid_token&lt;/error&gt;
  &lt;error_description&gt;Invalid access token: 2e4c26b3-0fcf-493e-a255-6216b98811c5&lt;/error_description&gt;
  </code></pre>
  
  <p>Logs: </p>
  
  <pre><code>2018-06-26 11:24:42.641 DEBUG 18658 --- [nio-9090-exec-2] o.s.security.web.FilterChainProxy        : /alunos at position 5 of 11 in additional filter chain; firing Filter: 'OAuth2AuthenticationProcessingFilter'
  2018-06-26 11:24:42.641 DEBUG 18658 --- [nio-9090-exec-2] p.a.OAuth2AuthenticationProcessingFilter : Authentication request failed: error="invalid_token", error_description="Invalid access token: 2e4c26b3-0fcf-493e-a255-6216b98811c5"
  2018-06-26 11:24:42.645 DEBUG 18658 --- [nio-9090-exec-2] o.s.s.w.header.writers.HstsHeaderWriter  : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@1fa75b
  2018-06-26 11:24:42.647 DEBUG 18658 --- [nio-9090-exec-2] s.s.o.p.e.DefaultOAuth2ExceptionRenderer : Written [error="invalid_token", error_description="Invalid access token: 2e4c26b3-0fcf-493e-a255-6216b98811c5"] as "application/xml;charset=UTF-8" using [org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter@30d6fa45]
  2018-06-26 11:24:42.647 DEBUG 18658 --- [nio-9090-exec-2] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
  </code></pre>
  
  <p>Documentation: 
  <a href="https://docs.spring.io/spring-security-oauth2-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-security-oauth2-authorization-server" rel="nofollow noreferrer">https://docs.spring.io/spring-security-oauth2-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-security-oauth2-authorization-server</a></p>