rburgst / okhttp-digest

a digest authenticator for okhttp
Apache License 2.0
191 stars 42 forks source link

How to use UTF-8 in basic and digest access authentication #66

Closed SailReal closed 4 years ago

SailReal commented 4 years ago

okhttp does support providing different char-sets for authentication. Using the default of okhttp which is ISO_8859_1 I've problems with some servers and chars e.g. "äöü" and want to switch to UTF-8.

How can I archive this using basic and digest access authentication and this library?

https://github.com/rburgst/okhttp-digest/blob/1e271666fbeb42f1e1f9520cc1f48b8826244ad2/src/main/java/com/burgstaller/okhttp/basic/BasicAuthenticator.java#L42

If I provide the authentication directly to okhttp using UTF-8 my Nextcloud accepts chars like "äöü" in the password.

.authenticator((route, response) -> {
    String credential = okhttp3.Credentials.basic("test", "äöüäöüäöü", UTF_8);
    return response.request().newBuilder().header("Authorization", credential).build();
})
rburgst commented 4 years ago

https://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication

rburgst commented 4 years ago

hm, will check this. Sorry, didnt read the 2nd part of your ticket.

SailReal commented 4 years ago

hm, will check this. Sorry, didnt read the 2nd part of your ticket.

Thanks, if you need further information or a test account please let me know.

rburgst commented 4 years ago

released 2.4 which adds the ability to provide the charset.

SailReal commented 4 years ago

Woooow impressive, thanks for the quick implementation :rocket:!

I have already tested it, it works, thanks!

Can you please add it for digest access authentication too?

SailReal commented 4 years ago

@rburgst is there a chance that the UTF-8 charset finds a way also in the DigestAuthenticator?

rburgst commented 4 years ago

@SailReal okhttp-digest is currently a straight up port of https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java, does it work with apache HC?