I've encountered some odd behaviour with a jQuery ajax call to a resource in a parent directory when using HTTP Basic authentication.
It seems like there's something going on here which I don't understand, but I've not been able to find a good reference source which gives me enough detail to know what I'm doing wrong.
Can anyone point out what I'm missing, or point me at some source which will help me understand how browsers decide to send (or not to send) a WWW-Authenticate header on Ajax requests?
My setup looks something like the following.
Page: https://site.com/d1/d2/page.html (contains a jQuery ajax call to load 'Ajax') Ajax: https://site.com/d3/some_resource.json Both require the same HTTP Basic authentication (with the same realm)
Walking through the behaviour I see...
When requesting 'Page' in a new browser session, the user is challenged with an HTTP basic a login prompt, and if they give the right details 'Page' is loaded.
If the user tries to access 'Ajax' directly in a new browser session they are also challenged with a HTTP basic login, using the same realm. If the same details as above are used, the json content is loaded.
In the first case, I expect that loading 'Page' successfully should allow Javascript code within 'Page' to load 'Ajax', even though it's in a parent directory.
RFC 2617 - HTTP Authentication
The realm value (case-sensitive), in combination with the canonical root URL (the absoluteURI for the server whose abs_path is empty; see section 5.1.2 of [2]) of the server being accessed, defines the protection space.
Instead, what I see is that the ajax call fails (401 Unauthorized) and looking at the request through Firefox's console, it appears no 'WWW-Authenticate' header was sent.
However - If the user then loads 'Ajax' directly in the browser, the json content is loaded (no login prompt), and subsequent requests to 'Page' now successfully load the 'Ajax' resource. In this case I would have expected that loading 'Ajax' directly in the browser would have no impact.
(If it's important I'm using Firefox 30.0 and jQuery 1.10.2)