Akka HTTP Client failing OAuth 1.0 Auth header call

I understand there is no implementation for oAuth 1.0 inbuilt with akka so I used MasterCard Api which created OAuth String to be used as header. I used it with Java HttpsURLConnection client, OkHttp3 and it worked perfectly fine but when I use the same with Akka Http client I am getting status 500 error.

Okhttp returns status 200

public String fetchx(String url, String method, Map<String, String> headers, String body, String contentType) throws IOException,
	UnrecoverableKeyException,
	NoSuchAlgorithmException,CertificateException,KeyStoreException,IOException{
        OkHttpClient httpClient = new OkHttpClient();
		Request request = new Request.Builder()
                .url(url)
                .headers(Headers.of(headers))
                .header("Authorization", createAuthHeader(URI.create(url), method, body, StandardCharsets.UTF_8))
                .method(method, body != null ? RequestBody.create(MediaType.parse(contentType), body) : null)
                .build();
        System.out.println("OKHTTP api req: " + request.toString());
        Call call = httpClient.newCall(request);
        String response = null;
        try {
            Response res = call.execute();
            response = res.body().string();
            res.close();
            System.out.println("api res: " + res.toString());
        } catch (IOException e) {
            response = e.getMessage();
        }
        return response;
    }

Akka Http: returns 500

private CompletionStage<HttpResponse> fetch(String url,String method,String payload,Charset charset)throws UnrecoverableKeyException,
	NoSuchAlgorithmException,CertificateException,KeyStoreException,IOException {
		URI uri = URI.create(url);
		String authHeader = createAuthHeader(uri, method, payload,charset);
		HttpRequest req = HttpRequest.create(uri.toString())
				.withMethod(HttpMethods.lookup(method).get())
				.addHeader(HttpHeader.parse("Authorization", authHeader));
		System.out.println("AKKA req: "+req.toString());
		return http.singleRequest(
				req
				);
	}

Most of my project uses Akka http client so it will be really painful to use another httpclient. Any advices will be highly appreciated.

500 is a server error, so it’s hard to say what would be needed on the client to make it work. You can try capturing the exact request sent to find out the differences between okhttp and akka-http. In akka-http you can set
akka.http.client.log-unencrypted-network-bytes = 1000 to get a hexdump of HTTP traffic logged.

I tried…no luck. Doesn’t log anything extra on console except the stuff I am logging.

Thanks for the help. :slight_smile: