So in order to use digest authentication with OkHTTP I need to use the digest plugin or implement myself so naturally I am using the plugin. However the example usage on the repositories readme is for the previous version of OkHTTP and I cannot use the same code to implement it in version 3. I have tried to look at some of their tests (which use OkHTTP 3) to see how the code works but I am just not sure.
So how can I use this http digest plugin with the most recent version of OkHttp?
import com.burgstaller.okhttp.AuthenticationCacheInterceptor;
import com.burgstaller.okhttp.CachingAuthenticatorDecorator;
import com.burgstaller.okhttp.digest.CachingAuthenticator;
import com.burgstaller.okhttp.digest.Credentials;
import com.burgstaller.okhttp.digest.DigestAuthenticator;
import okhttp3.OkHttpClient;
private OkHttpClient buildHttpClient(String username, String password) {
// Library used for digest authenticaton: https://github.com/rburgst/okhttp-digest
var authenticator = new DigestAuthenticator(new Credentials(username, password));
var authCache = new ConcurrentHashMap<String, CachingAuthenticator>();
var decorator = new CachingAuthenticatorDecorator(authenticator, authCache);
var interceptor = new AuthenticationCacheInterceptor(authCache);
return httpClient.newBuilder()
.authenticator(decorator)
.addInterceptor(interceptor)
.build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With