thegrizzlylabs / sardine-android

A WebDAV library for Android
Apache License 2.0
355 stars 70 forks source link

Digest authentication not supported #17

Closed alexdiostia closed 5 years ago

alexdiostia commented 5 years ago

Hello i'm getting an authentication failure, HTTP 401 on the list() function.

my code: Sardine sardine = new OkHttpSardine(); sardine.setCredentials("login","password"); List resources = sardine.list("https://mydomain.net/webdav/");

i'm sure the login password are correct, as it works with some other sardine wrapper

anyone would please have an idea ? Thanks brgds alex

guillaume-tgl commented 5 years ago

Do you have more details about the error? Have you tried to enable preemptive authentication? You can enable it with this method: https://github.com/thegrizzlylabs/sardine-android/blob/master/src/main/java/com/thegrizzlylabs/sardineandroid/impl/OkHttpSardine.java#L81

If that doesn't help, could you share an example of URL/login/password so that I can reproduce the problem and try to fix it?

alexdiostia commented 5 years ago

Do you have more details about the error? Have you tried to enable preemptive authentication? You can enable it with this method: https://github.com/thegrizzlylabs/sardine-android/blob/master/src/main/java/com/thegrizzlylabs/sardineandroid/impl/OkHttpSardine.java#L81

If that doesn't help, could you share an example of URL/login/password so that I can reproduce the problem and try to fix it?

Hello i have the same authentication failure with, or without preemptive auth.

when reaching the list() function call, i get : I/System.out: Authenticating for response: Response{protocol=http/1.1, code=401, message=Unauthorized, url=https://mydomain.net/webdav/} I/System.out: Challenges: [Digest realm="webdav" charset="ISO-8859-1"]

i am certain URL,login,password are ok (i only replaced here my own domain by "mydomain", the rest is the same) thanks alex

drakeet commented 5 years ago

This library only supports Basic auth now, so if you are using Digest auth, it will fail to sign in and throw the 401 failure.

drakeet commented 5 years ago

You can try the okhttp-digest to instead of the inner Basic auth of our sardine-android.

alexdiostia commented 5 years ago

ok, Thanks Drakeet! That explains why indeed... i'm using Digest. Ideally, the authentication should be successful whatever auth type. I may prefer waiting that you integrate it in the project :)

alexdiostia commented 5 years ago

thanks again! i included the lib , and the following in the setCredentials()... that seems to work fine

final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); final DigestAuthenticator authenticator = new DigestAuthenticator(new com.burgstaller.okhttp.digest.Credentials(username, password)); builder.authenticator(new CachingAuthenticatorDecorator(authenticator, authCache));

guillaume-tgl commented 5 years ago

Actually, you shouldn't even have to modify the library. You can initialize the OkHttpSardine with your own OkHttpClient that you can build as you mentioned. We could even add a mention about this in the Readme of the project.

alexdiostia commented 5 years ago

you're right... i removed the explicit setCredentials(log,pass), created a getClient() method and pass the client to the OkHttpSardine constrcutor Works just fine. would be better included by default, but works fine like this Thanks again