1

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.

Zzb
  • 11
  • 1

2 Answers2

1

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

Umbro
  • 1,271
  • 3
  • 19
  • 63
  • I used basic authentication before, but in order to more security, I've to use digest authentication. And I also use a tag in request header to let the server return a 200 http code and responseCode 401 in Response instead of a 401 http code. And then the client can do other things to send the correct authorization.For this question I just want to know if I use digest authentication, how can I prevent browser popup. – Zzb Jun 20 '19 at 08:11
1

"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.

shaochuancs
  • 12,430
  • 3
  • 40
  • 51