title: OAuth2 oltu client
body: <p>I'm building my oauth2-protecet webservice, and a client. For webservice I used spring security implementation, and <a href="https://github.com/royclarkson/spring-rest-service-oauth/" rel="nofollow noreferrer">used this as example</a>. For client I'm trying out apache oltu library. Here's my snippet: </p>
  
  <pre><code>        OAuthClientRequest request = OAuthClientRequest.tokenLocation
                  ("http://localhost:8080/oauth/token")
                  .setGrantType(GrantType.CLIENT_CREDENTIALS)
                  .setClientId("clientapp")
                  .setClientSecret("123456")
                  .buildHeaderMessage();
  
          OAuthAccessTokenResponse oAuthResponse = cli.accessToken(request);
  
          System.out.println(oAuthResponse.getAccessToken());
  </code></pre>
  
  <p>It does not work. While this </p>
  
  <pre><code>curl -X POST -vu clientapp:123456 --data "grant_type=client_credentials&amp;client_secret=123456&amp;client_id=clientapp"  http://localhost:8080/oauth/token
  </code></pre>
  
  <p>works perfectly well. Here's the curl request:</p>
  
  <pre><code>POST /oauth/token HTTP/1.1
  Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==
  User-Agent: curl/7.35.0
  Host: localhost:8080
  Accept: */*
  Content-Length: 70
  Content-Type: application/x-www-form-urlencoded
  
  grant_type=client_credentials&amp;client_secret=123456&amp;client_id=clientapp
  </code></pre>
  
  <p>as you can see, I used Basic authentication with curl and it worked(even though suggested authentication type is Bearer).</p>
  
  <p>And here's oltu packet:</p>
  
  <pre><code>POST /oauth/token HTTP/1.1
  Content-Type: application/x-www-form-urlencoded
  Authorization: Bearer client_credentials123456clientapp
  User-Agent: Java/1.8.0_51
  Host: localhost:8080
  Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
  Connection: keep-alive
  Content-Length: 4
  
  null
  </code></pre>
  
  <p>I'm nor sure how bearer authorization is supposed to work, but this packet looks all wrong. </p>
  
  <p>I also tried to use <code>buildBodyMessage()</code> and <code>buildQueryMessage()</code> instead of <code>buildHeaderessage()</code> as was suggested in <a href="https://stackoverflow.com/questions/20216786/client-credential-grant-type-is-not-properly-sent-with-apache-oltu-client-librar">this post</a>, but it's no good either.</p>