9
I have a system with two sites in the same domain. The two sites are in separate folders of the same domain, more or less like this:
http://renan/foo
http://renan/bar
The first site (let’s call it "foo
") has a page that accesses data from the other site ("bar
") via Ajax. When the user is logged in to both, everything happens as wish. But when the user is logged in only at foo
, the browser shows a prompt asking for username and password. Authentication is done via Active Directory and not all users of each site should have access to each other.
I would like it in case the user is logged in to foo
nas not in bar
, the login prompt did not appear. I wanted to treat it as an error. Is there any way to verify that the system would ask for authentication and prevent the prompt from appearing?
Follow a snippet of the code I’m using for requisition:
$.ajax({
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
type: "GET",
url: "http://renan/bar/baz",
beforeSend: function (xhr) {
xhr.withCredentials = true;
}
})
Just to clarify: this login prompt is native to the browser (pq vc is using basic HTTP authentication) or is something specific to your website?
– hugomg
@hugomg is native to browser.
– Oralista de Sistemas
This is a bit tricky, but if when the user logs in, try to log in to both sites, it is not easier to silence the error answer in case he does not have authorization to log in to a site?
– Manuel Gerardo Pereira
@Manuelgerardopereira is what I’m trying to do and I don’t know how.
– Oralista de Sistemas
Have you tried inspecting the server request headers? You can toggle the response (by issuing an HTTP error status as 500) accordingly.
– bfavaretto
@bfavaretto I do not control the application for which I will request, so I have no way to manipulate the headers of the answer :\
– Oralista de Sistemas
What about a HEAD request to find out if you’re authenticated? Then don’t proceed if you’re not.
– bfavaretto
I’m gonna try, thanks :)
– Oralista de Sistemas
That HEAD thing worked?
– Daniel
@Daniel I no longer have the environment to test =(
– Oralista de Sistemas
@Daniel however, I found a similar question in the OS: https://stackoverflow.com/questions/26545126/ithit-ajax-file-browser-active-directory-webdav-auto-login
– Oralista de Sistemas