as the question allready says, I am trying to do digest authentication in android.
Until now i have used the DefaultHttpClient
and it's authentication method (using UsernamePasswordCredentials
and so on), but it is deprecated since Android 5 and will be removed in Android 6.
So i am about to switch from DefaultHttpClient
to HttpUrlConnection
.
Now i am trying to achieve digest authentication, which should work pretty simple as explained here:
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
But the getPasswordAuthentication
gets never called for some reason.
During my search for this problem i found different posts, saying digest authentication is not supported by the HttpUrlConnection
in android, but those posts are from 2010-2012, so i am not sure if this is still true. Also we are using HttpUrlConnection
with digest authentication in our desktop java application, where it does work.
I also found some posts, talking about OkHttp
. OkHttp
seems to be used by Android under the hood (to be more specific the HttpUrlConnectionImpl
). But this HttpUrlConnectionImpl
is a bit strange, it is not even shown in the Eclipse type hierarchy and i am not able to debug it. Also it should be a com.squareup.okhttp.internal.huc.HttpUrlConnectionImpl
, while in android it is a com.android.okhttp.internal.http.HttpUrlConnectionImpl
.
So i am just not able to do digest authentication with this HttpUrlConnection
in android.
Can anyone tell me how to do that without external libraries?
EDIT:
The server asks for digest authentication:
WWW-Authenticate: Digest realm="Realm Name",domain="/domain",nonce="nonce",algorithm=MD5,qop="auth"
So Basic-Authentication shouldn' work, as the server is asking for digest.
HttpUrlConnection
, which does not support digest or also the defaultjava.net.HttpURLConnection
? – Amenable