6👍
Your 3rd requirement could easily be solved by sharing the same database between the two sites (therefore having the same Users table.
The 1st requirement is tricky because of cross domain issues (the session cookie will not be shared).
What you are really looking for is a Single Sign On (SSO). You might consider django-openid.
7👍
It depends on your requirements. If you’re able to, the simple solution is to simply host both sites on one Django instance. In other words, your Django project hosts both sites but you have a url rewrite rule that maps foo.com
to http://localhost/foo/
and bar.com
to http://localhost/bar/
. Django’s auth system will “just work” under this scenario. Rewrite rules can of course also apply to subdomains; I’ve built a system that hosts hundreds of subdomains using this technique.
If this isn’t an option, sharing databases between your Django instances and setting SESSION_COOKIE_DOMAIN
, as mentioned by others, should work.
- Using APITestCase with django-rest-framework
- Set db per model in django
- Multi-Tenant Django Application
- How can I tell Django templates not to parse a block containing code that looks like template tags?
- Django 'function' object has no attribute 'objects'
5👍
I had a very similar problem but OpenID was not a viable solution for me. With the advent of multiple databases in django >1.2, it is now pretty easy to share session and login data across sites. This blog post does a great job of explaining how to get it set up. Hopefully others find this as useful as I did.
- Saving a Pandas DataFrame to a Django Model
- Is there any way to use GUIDs in django?
- How do you use Django-filter's '__in' lookup?
0👍
I think what you are looking for is the SESSION_COOKIE_DOMAIN
setting. You would set it like this:
SESSION_COOKIE_DOMAIN = 'foo.com'
See http://docs.djangoproject.com/en/dev/topics/http/sessions/#session-cookie-domain for more information on that. This does assume that both applications are using the same session storage backend.
- Django-rest-framwork got AttributeError when attempting to get a value for field
- Colorizing the output of Django tests
- Django queryset for many-to-many field
0👍
These can be achieved by implementing CAS (Centralized Authentication Service).
In your example, foo.com is your server, bar.com is the client. Only one server is required; you can have as many clients as you need.
On your server:
- Install and configure django-mama-cas (or any equivalent) and django-cas-ng (or any equivalent).
- Not required to add django-cas-ng urls on the server.
On you client(s):
- Install and configure django-cas-ng (or any equivalent).
- Add the login and logout django-cas-ng urls on the client’s urls.py.
- For me, I have added the decorator @login_required(login_url="/accounts/login") to the protected views
- Be sure to define CAS_SERVER_URL in the settings.py of the client. In your example, that would be something like "CAS_SERVER_URL = foo.com".
Hope this helps someone as I have not found any tutorial that explicitly gave and explained the instructions above.