Don't bother reading unless you give at least a quarter of a shit about XMLHttpRequest and HTTP authentication.
Here's a stupid geek trick. The correct login information for this
is user="user", password="password". Give it the wrong password [it will say something like 401 Unauthorized, user="user", password="bogus"]. Then give it the right password and try again - it will keep sending the wrong password. This happens in both Firefox and IE; Safari has a slightly different bug.
Here's the sitch: I have an XMLHttpRequest going out to a password-protected resource. The credentials are supplied by the user and thus they are likely to be wrong some of the time. The script is designed to gracefully handle authentication failure - specifically, I want to avoid the crappy infinite HTTP authentication dialog box loop. I'd think that this issue would come up from time to time, but I guess it doesn't because this is really hairy:
XMLHttpRequest
states "If authentication fails, user agents SHOULD prompt the users for credentials."
To work around this, Paul James
suggests returning 401 Unauthorized without the mandatory WWW-Authenticate header. In theory, this tells the browser to stop trying and forget the password. The browser does, in fact, stop trying, but it also goes into a weird undefined state where it continues to issue the old [incorrect] password despite instruction to the contrary. [Safari instead puts up the dialog on the next request, even if credentials are provided.]
HTTP/1.1
states "If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity might include relevant diagnostic information." - ie, reissue the same challenge to indicate to the browser that it should give up. As near as I can tell, not a single browser has ever done that.
HTTP/1.1 also gives us 403 Forbidden: "Authorization will not help and the request SHOULD NOT be repeated." This response has the same bizarre effects as 401 without WWW-Authenticate.
I'm actually kind of an AJAX newb, so ... does anyone have any recommendations?
- Z
Ah... Hamilton... such a class joint, iain't it? I say the folks from my hometown have class with a capital K.
I get it. But since I don't know what a potato masher looks like, I am at a distinct loss. Was it the helmet like thing on your head or was it some other hidden/in sight implement??