-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage digest authentication with Retrofit #281
Comments
looking for it too |
When the server returns with the 401 status, the RetrofitError response object is null, and the networkError flag is set to true, making it impossible for the app to check |
In my case the challenge is empty but i get a challenge. But when i add challengeResponse to the request it's like the request is send a second time. |
Wild guess that implementing a custom client could do the trick. class ChallengeResponseClient implements Client{
Client delegate;
public Response execute(Request request) throws IOException {
Response response = delegate.execute(request);
if (response.getStatus() == 401){
// authenticate, etc. |
Had the same issue as @Anndressa. After I included Okhttp library, the correct response status, 401, is returning now instead of IOException. Retrofit uses OkClient if there is Okhttp library.
Edit: The other possible solution is to include WWW-Authenticate header field with 401 response if you can modify the server. See discussion here. http://stackoverflow.com/questions/1357372/ioexception-received-authentication-challenge-is-null-apache-harmony-android |
I'm having a really weird issue related to this. I'm testing incorrect logins, where the server returns a 401 with an error message. Running on a Nexus 5 (api level 19) I get a retrofiterror and I have access to the server's response and error message, so it's fine. Testing on an api level 16 device, I get a retrofiterror where isNetworkError() is true, caused by "java.io.IOException: No authentication challenges found". Besides the exception message, there's nothing distinguishing this from an actual network error. I searched around a lot, but there isn't a lot of documentation about this issue. I tried adding WWW-Authenticate: none to the server's 401 response, as suggested by various posts, but that doesn't seem to work. I'll have to add an ugly fix to this for the moment, but I'd like to understand why there's a difference, and how I can properly fix this. I'd appreciate any help :D |
We will not be implementing this at the Retrofit level. Tracked at square/okhttp#205. |
@dslounge Best regards |
It's been a while, so I don't remember if this was exactly the solution, but I added OkHttp to my project and it was fixed. Took me forever to figure that out, and there wasn't much documentation on this issue. Seems like the problem was caused by the default Android HTTP library doing things to a certain spec. |
Retrofit error: 401 Unauthorized. Previously it was working fine for me but now i am geting this error. |
Hi everyone,
Do somebody have any idea on how to implement a digest authentication solution with Retrofit ? When the server answers with a 401 Unauthorized responses, the
Callback
object calls itsfailure()
method..Is it possible with retrofit ? Thanks in advance.
The text was updated successfully, but these errors were encountered: