September 17, 2012

Avoiding browser popup for 401

I was facing this issue recently, too. Since you can't change the browser's default behavior of showing the popup in case of a 401 (basic or digest authentication), there are two ways to fix this:

  • Change the server response to not return 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" }
  • Alternatively, if you can customize your server response, you could return a 403 Forbidden.
  • The browser will not open the authentication popup and the jquery callback will be called.

Please also take a look at.