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();
}