Jetty HTTP Client Digest Auth

Viewed 3924

I am trying to get authenticated using a Jetty HTTP Client and Digest Auth.

I always get the Exception:

org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header

Here is my Code:

    HttpClient httpClient = new HttpClient();

    httpClient.start();

    String realm = "me@kennethreitz.com";
    String user = "user";
    String pass = "passwd";
    URI uri =new URI("http://httpbin.org/digest-auth/auth/user/passwd/MD5");
    AuthenticationStore a = httpClient.getAuthenticationStore();
    a.addAuthentication(
        new DigestAuthentication(uri, realm, user, pass));

    ContentResponse response = httpClient
            .newRequest(uri)
            .send();
            //.get(5, TimeUnit.SECONDS);

    System.out.println(response);

For testing purposes i use a http://httpbin.org/ endpoint, but i also tried other endpoints - all unsuccessfully...

Am i missing something or doing wrong?

1 Answers

I believe this message represents the 401 http status and the situation when you have to pass an Authorization header in the request.

For example this is a typical situation when you're trying access to the OAuth 2.0 secured endpoint without a token. At least this is what I have faced with, having the very same error with jetty http client.

Related