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 here:
However, Stripe requires additional "Authorization: Bearer" header:
curl -X POST https://connect.stripe.com/oauth/token \
-H "Authorization: Bearer xxxxxxxxxxxxxx" \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code
I tried the following:
OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
String error = oar.getParam("error");
String errorDescription = oar.getParam("error_description");
String code = oar.getCode();
if (null != error && !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<String,String> headers =new HashMap<String, String>();
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();
but it crashes with:
Server returned HTTP response code: 401 for URL: https://connect.stripe.com/oauth/token
Any ideas on how to add the bearer header? Thanks!