title: Spring OAuth 2 Call /oauth/token Resulted in 401 (Unauthorized)
body: <p>Greeting everyone, I try to configure simple authorization code flow via Spring Security OAuth.</p>
  
  <p>I tested my authorisation and resource server configuration via following approaches:</p>
  
  <ol>
  <li>Create a web application as client and use its page to fire http post call to /oauth/authorize. </li>
  <li>After getting code, I use the same page to
  fire another http post with code and get token. </li>
  <li>At the end, I use
  curl -H to place token inside header and get response from protected
  resource.</li>
  </ol>
  
  <p>But when I try to use rest template. It throw error message 401 Unauthorised error.</p>
  
  <p><strong>Server side - security configure:</strong></p>
  
  <pre><code>&lt;http auto-config="true" pattern="/protected/**"
      authentication-manager-ref="authenticationManager"&gt;
      &lt;custom-filter ref="resourceFilter" before="PRE_AUTH_FILTER" /&gt;
      &lt;csrf disabled="true" /&gt;
  &lt;/http&gt;
  
  &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/**" access="hasRole('ROLE_USER')" /&gt;
      &lt;form-login default-target-url="/admin.html" /&gt;
      &lt;logout logout-success-url="/welcome.html" logout-url="/logout"/&gt;
      &lt;csrf disabled="true" /&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager alias="authenticationManager"&gt;
      &lt;authentication-provider&gt;
          &lt;user-service&gt;
              &lt;user name="admin" password="123456" authorities="ROLE_USER,ROLE_ADMIN" /&gt;
          &lt;/user-service&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p><strong>Server side - authorisation and resource configure:</strong></p>
  
  <pre><code>&lt;oauth:authorization-server
      client-details-service-ref="clientDetails" error-page="error"&gt;
      &lt;oauth:authorization-code /&gt;
  &lt;/oauth:authorization-server&gt;
  
  &lt;oauth:client-details-service id="clientDetails"&gt;
      &lt;oauth:client client-id="admin" secret="fooSecret" /&gt;
  &lt;/oauth:client-details-service&gt;
  
  &lt;oauth:resource-server id="resourceFilter" /&gt;
  </code></pre>
  
  <p><strong>Client Side:</strong> </p>
  
  <pre><code>&lt;oauth:client id="oauth2ClientContextFilter" /&gt;
  &lt;oauth:resource id="sso" client-id="admin"
      access-token-uri="http://localhost:8080/tough/oauth/token"
      user-authorization-uri="http://localhost:8080/tough/oauth/authorize"
      use-current-uri="true" client-secret="secret"
      client-authentication-scheme="header" type="authorization_code"
      scope="trust" /&gt;
  &lt;oauth:rest-template id="template" resource="sso"/&gt;
  </code></pre>
  
  <p>If anyone knows where goes wrong, please do let me know.</p>