Skip navigation links

Package com.albroco.barebonesdigest

An implementation of the HTTP Digest authentication scheme for Android.

See: Description

Package com.albroco.barebonesdigest Description

An implementation of the HTTP Digest authentication scheme for Android. With a small effort you can use it to get HTTP digest working with HttpURLConnection or any other HTTP stack.

Here is an example of how to make a request and respond to a Digest challenge:


 // Step 1. Create the connection
 URL url = new URL("http://httpbin.org/digest-auth/auth/user/passwd");
 HttpURLConnection connection = (HttpURLConnection) url.openConnection();

 // Step 2. Make the request and check to see if the response contains an authorization challenge
 if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
     // Step 3. Create a authentication object from the challenge...
     DigestAuthentication auth = DigestAuthentication.fromResponse(connection);
     // ...with correct credentials
     auth.username("user").password("passwd");

     // Step 4 (Optional). Check if the challenge was a digest challenge of a supported type
     if (!auth.canRespond()) {
         // No digest challenge or a challenge of an unsupported type - do something else or fail
         return;
     }

     // Step 5. Create a new connection, identical to the original one...
     connection = (HttpURLConnection) url.openConnection();
     // ...and set the Authorization header on the request, with the challenge response
     connection.setRequestProperty(DigestChallengeResponse.HTTP_HEADER_AUTHORIZATION,
     auth.getAuthorizationForRequest("GET", connection.getURL().getPath()));
 }
 
DigestAuthentication is the main entry point of the API, read the documentation for more examples. Some other useful classes include:
Skip navigation links