How to prevent browser to invoke Digest auth popup and handle 401 error using Jquery?

Viewed 739

I need to send authorization request using digest auth. I have successfully implemented this using jquery. However when I get 401 error digest auth browser popup is opened and jquery ajax error callback is not called.

2 Answers

Change the server response to not return a 401. Return a 200 code instead and handle this in your jQuery client. Change the method that you're using for authorization to a custom value in your header. Browsers will display the popup for Basic and Digest. You have to change this on both the client and the server.

headers : {
  "Authorization" : "BasicCustom"
}

Look here: Use basic authentication with jQuery and Ajax

"For this question I just want to know if I use digest authentication, how can I prevent browser popup."

Unfortunately, it's impossible. For all Ajax request events (loadstart, load, loadend, progress, error, abort, timeout) handler and event handler onreadystatechange, only loadstart is fired before the browser popup for digest (actually it is fired even before server retrieves the request).

Thus, from browser side JavaScript point of view, nothing is invoked before digest popup, which means there is nothing we can do to prevent the popup.

Related