Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango session cookie: from (any) other domain, check if user is logged in
    text
    copied!<p>I have a domain domain1.com. The user logs in and a cookie is set. This is done using Django sessions.</p> <p>I then go to another domain domain2.com. This domain runs javascript. From this javascript, I want to see if the user is logged into domain1.com.</p> <p>Is this possible? Can I see a cookie belonging to domain1 from domain2? Or can I somehow via ajax make a call domain1 to check if the user is logged in? </p> <p>Also, the user might originally have logged into domain1 from Chrome, but now they are accessing domain2 from another browser. Aren't cookies browser specific?</p> <p>EDIT:</p> <p>The real problem I am trying to solve? (re comment below): I have created a Chrome extension. When the user presses the extension icon from domain2, a javascript is run, which collects information from the page. This information needs to be sent to the user's account on domain1. Note that domain2 can be ANY domain, not one that I have created.</p> <p>What I tried with AJAX and cookies.</p> <p>set cookie from domain1:</p> <pre><code>response.set_cookie("user_cookie", value="somevalue", max_age=60*60, expires=None, path='/', domain=None, secure=None, httponly=False) </code></pre> <p>Create Python function, which is executed from domain1.com/checklogin:</p> <pre><code>@csrf_exempt def is_logged_in(request): cookie = request.COOKIES.get('user_cookie') if cookie is not None: return HttpResponse("1") else: return HttpResponse("0") </code></pre> <p>Go to domain1.com/checklogin -> The response is "1"</p> <p>Call javascript from domain2 as follows:</p> <pre><code>var xmlHttp_1=new XMLHttpRequest(); xmlHttp_1.open("POST","http://domain1.com/checklogin/",false); xmlHttp_1.send(); alert(xmlHttp_1.responseText); </code></pre> <p>The response here is, incorrectly, 0. It does not see the cookie created by domain1.</p> <p>Note that domain1 is, at this point, localhost and domain2 is a real domain. Could this be the issue? It does properly call the function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload