title: Spring OAuth2 custom request - put parameters on body like raw data
body: <p>I am implementing a client with Spring Security OAuth2 to use resources through an API, I have to customize the request like this:</p>
  
  <pre><code>POST https://example.com/v2/oauth2/token HTTP / 1.1
  Authorization: Basic xxxXXXXxxXXXXXXxXXxxXX
  Content-Type: application / x-www-form-urlencoded
  Accept: application / json; charset = UTF-8
  
  grant_type = authorization_code &amp; code = 12345678901234567890
  </code></pre>
  
  <p>Where: grant_type = authorization_code &amp; code = 12345678901234567890
  it is contained in the body as raw data.</p>
  
  <p>How can I put the grant_type and code parameters on the body?</p>
  
  <p>At the moment my code is formalized in this way:</p>
  
  <pre><code>AuthorizationCodeResourceDetails resource = new AuthorizationCodeResourceDetails ();
  resource.setAccessTokenUri ( "https://example.com/v2/oauth2/token");
  resource.setClientId ( "xxxxx");
  resource.setClientSecret ( "xxxxx");
  resource.setGrantType ( "authorization_code");
  resource.setUseCurrentUri (false);
  AccessTokenRequest atr = new DefaultAccessTokenRequest ();
  atr.setPreservedState (new Object ());
  atr.setAuthorizationCode(authCode);
  
  AuthorizationCodeAccessTokenProvider provider = new AuthorizationCodeAccessTokenProvider ();
  
  try {
  OAuth2AccessToken accessToken = provider.obtainAccessToken (resource, atr);
  }
  catch (Exception e) {
  System.out.println ("DEBUG" + e);
  }
  </code></pre>