我正在尝试使用 Apache Amber 接收 Stripe Connect 的身份验证令牌。这里有一个如何用 OAuth 代码交换访问令牌的示例:
但是,Stripe 需要额外的“Authorization: Bearer”标头:
curl -X POST https://connect.stripe.com/oauth/token \
-H "Authorization: Bearer xxxxxxxxxxxxxx" \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code
我尝试了以下方法:
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();
但它崩溃了:
服务器返回 HTTP 响应代码:401 用于 URL: https ://connect.stripe.com/oauth/token
关于如何添加不记名标头的任何想法?谢谢!