0

How to redirect to another domain in Django from login view with auto login in the new domain at the same time ?

I have tried to set cookie with current sessionid in HttpResponseRedirect to the new domain.

Any another ways, please ?

how to login to domain1.com, then redirect to domain2.com (domain points to the same ip) and be logged ?

2 Answers2

1

You're asking for Single Sign On (SSO). It's a rather rich and complex topic. There are some available django solutions like django-sso.

Here's another stack overflow question on SSO with django: Implementing Single Sign On (SSO) using Django

Community
  • 1
  • 1
Kevin Stone
  • 8,831
  • 41
  • 29
0

If these domains are subdomains of the same 2nd level domain then you can use the SESSION_COOKIE_DOMAIN setting:

SESSION_COOKIE_DOMAIN = '*.somedomain.com'

If domains are totally different then you in trouble. You can't set cookie for the external domain.

I think you have to create a special view on the second domain which will receive the session_key in the GET parameter and set the cookie for the second domain.

To prevent attacks you can store in the session some info about the user (at least the IP and User-Agent) at the first domain and compare this data against the visitor of the the second site.

catavaran
  • 44,703
  • 8
  • 98
  • 85