views:

160

answers:

2

I want to let the same user session span across: site.com
sub1.site.com
sub2.site.com

How can I do this in Django? With the default auth user package it seems to require the user to login to all 3 sites each time with a different session. How can they share the same login cookie and session-id?

UPDATE: Using the SESSION_COOKIE_DOMAIN value in settings.py seems to work on production sites, but it doesn't work for me on localhost/dev servers. How do you get it to work for localhost sub-domains? When I change the SESSION_COOKIE_DOMAIN to the production website name or ".localhost" django auth logins completely stop working (I'm unable to ever login, no cookie is created on localhost.)

+2  A: 

I believe this is a duplicate, see this question: http://stackoverflow.com/questions/1442017/subdomains-and-logins

Michael Cheng
A: 

I think I got a workaround solution, but couldn't use localhost. I could only get it working for a test ".com" domain that maps to 127.0.0.1.

In my /etc/hosts file (on OSX:)

    127.0.0.1  test.com
    127.0.0.1  sub1.test.com
    127.0.0.1  sub2.test.com

Then on my development settings.py:

    SESSION_COOKIE_DOMAIN=".test.com"

I could not get this working with plain "localhost", it seemed I needed the ".com" string in there to get it working. So then I could login and have cross subdomain auth cookies using sub1.test.com:8000 and sub2.test.com:8000 in my browser.

MikeN