title: Apache Amber: How to exchange OAuth code for an access token with Bearer Header?
body: <p>I am trying to receive an authentication token for Stripe Connect using Apache Amber. There is an example of how to exchange OAuth code for an access token <a href="https://cwiki.apache.org/confluence/display/AMBER/OAuth+2.0+Client+Quickstart" rel="nofollow">here</a>: </p>
  
  <p>However, Stripe requires additional "Authorization: Bearer" header:</p>
  
  <pre><code>  curl -X POST https://connect.stripe.com/oauth/token \
        -H "Authorization: Bearer xxxxxxxxxxxxxx" \
        -d code=AUTHORIZATION_CODE \
        -d grant_type=authorization_code
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>            OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
              String error = oar.getParam("error");
              String errorDescription = oar.getParam("error_description");
              String code = oar.getCode();
  
  
              if (null != error &amp;&amp; !error.isEmpty()){
                  System.err.println ("Authentication failed: " + errorDescription);
                  System.exit(1);
              }
  
              OAuthClientRequest exchangeRequest = OAuthClientRequest
              .tokenLocation("https://connect.stripe.com/oauth/token")
              .setGrantType(GrantType.AUTHORIZATION_CODE)
              .setClientId("my-client-id")
              .setCode(code)
              .buildBodyMessage();
  
              Map&lt;String,String&gt; headers =new HashMap&lt;String, String&gt;();
              headers.put("Authorization", "Bearer xxxxxxxxxxxxxx");
  
              exchangeRequest.setHeaders(headers);
  
             //create OAuth client that uses custom http client under the hood
             OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
  
  
             GitHubTokenResponse oAuthResponse = oAuthClient.accessToken(exchangeRequest, GitHubTokenResponse.class);
  
             String accessToken = oAuthResponse.getAccessToken();
  </code></pre>
  
  <p>but it crashes with:</p>
  
  <blockquote>
    <p>Server returned HTTP response code: 401 for URL:
    <a href="https://connect.stripe.com/oauth/token" rel="nofollow">https://connect.stripe.com/oauth/token</a></p>
  </blockquote>
  
  <p>Any ideas on how to add the bearer header? Thanks!</p>