title: Spring Boot Oauth2 token request - Bad client credentials from BasicAuthenticationFilter
body: <p>Requesting help on a Spring Boot OAuth2 app's BadCredentialsException when , after user authentication and approval, my Oauth2 client app requests a token from the token endpoint of the OAuth2 AuthServer.</p>
  
  <p>The Spring Boot OAuth2 applications are based off the now famous Dave Syer Spring Boot/ Oauth2 UI Client/Oauth2 AuthServer/JWT example <a href="https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2" rel="nofollow noreferrer">https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2</a></p>
  
  <p>This is in the Client Apps' debug:</p>
  
  <pre><code>DEBUG org.springframework.web.client.RestTemplate - Created POST request for "authserver/uaa/oauth/token"
  DEBUG org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider - Encoding and sending form: {grant_type=[authorization_code], code=[xxxxx], redirect_uri=[oauthclientapp/login]}
  DEBUG org.springframework.web.client.RestTemplate - POST request for "authserver/uaa/oauth/token" resulted in 200 (null)
  DEBUG org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token
  </code></pre>
  
  <p>This is the AuthServer's debug:</p>
  
  <pre><code>DEBUG org.springframework.security.web.FilterChainProxy - /oauth/token at position 9 of 15 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
  DEBUG org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Basic Authentication Authorization header found for user 'clientID'
  DEBUG org.springframework.security.authentication.ProviderManager - Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider
  DEBUG org.springframework.security.authentication.dao.DaoAuthenticationProvider - User 'clientID' not found
  DEBUG org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
  </code></pre>
  
  <p>The Oauth2 client app is just like the one in the example, no customization in the token request process, just whatever @EnableOAuth2Sso gives us. The ClientDetails config on the AuthServer is also just like the example, sample below, so nothing special.</p>
  
  <p>Any suggestions to better troubleshoot this are much appreciated. Thanks.</p>
  
  <pre><code>@Override
          public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
              clients.inMemory()
                      .withClient("clientID")
                      .secret("acmesecret")
                      .authorizedGrantTypes("authorization_code", "refresh_token",
                              "password").scopes("openid");
          }
  </code></pre>