title: Spring Boot 1.3 + OAuth: Authentication request failed: BadCredentialsException: Could not obtain access token
body: <p>I'm trying to authenticate an OAuth Spring Boot 1.3 with WSO2 Identity provider.</p>
  
  <p><strong>Problem:</strong> Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token</p>
  
  <p><strong>Question:</strong> What is missing in my code/configuration in order to obtain the Access Token.</p>
  
  <p><strong>application.yml</strong></p>
  
  <pre><code>security:
      oauth2:
          client:
              clientId: 6kRDeCMVKjYzH7duL33AFAYX8dka
              clientSecret: USEZhqRyCfF_dIdEIjFolFOkTAoa
              accessTokenUri: https://localhost:9443/oauth2/token
              userAuthorizationUri: https://localhost:9443/oauth2/authorize
              clientAuthenticationScheme: form
          resource:
  schema=openid
              userInfoUri: https://localhost:9443/oauth2/userinfo?schema=openid
  </code></pre>
  
  <p><strong>Application.groovy</strong></p>
  
  <pre><code>@SpringBootApplication
  @EnableOAuth2Sso
  class Application extends GrailsAutoConfiguration {
  
      static void main(String[] args) {
          GrailsApp.run(Application, args)
      }
  
      @Bean public RequestContextListener requestContextListener(){
          return new RequestContextListener();
      }
  
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Request '/login' matched by universal pattern '/**'
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 1 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 2 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
  DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - HttpSession returned null object for SPRING_SECURITY_CONTEXT
  DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@67c3c622. A new one will be created.
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 3 of 12 in additional filter chain; firing Filter: 'HeaderWriterFilter'
  DEBUG org.springframework.security.web.header.writers.HstsHeaderWriter - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@681bd9a9
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 4 of 12 in additional filter chain; firing Filter: 'CsrfFilter'
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 5 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
  DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Request 'GET /login' doesn't match 'POST /logout
  DEBUG org.springframework.security.web.FilterChainProxy - /login?code=4ccb21df259c452e187421d46b984cf3&amp;state=ioU1XC at position 6 of 12 in additional filter chain; firing Filter: 'OAuth2ClientAuthenticationProcessingFilter'
  DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/login'; against '/login'
  DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Request is to process authentication
  DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token
  DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Updated SecurityContextHolder to contain null Authentication
  DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Delegating to authentication failure handler org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@1ed9d99c
  DEBUG org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler - No failure URL set, sending 401 Unauthorized error
  DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
  DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
  </code></pre>