Separate Django sites with a common authentication / registration firewall

I need to split my current Django application into two sites.

Site A will contain an open site that will contain all the static pages and the registration system.

Another site - Site B - is a site for registered users. They can also access the application site through site B.

If I am not mistaken, I can use the django.contrib.sites framework to perform the task with several sites, but can it have a common authentication / registration server?

How can i do this?

Thanks.

+6
source share
3 answers

The structure of Django django.contrib.sites is good if both sites are running on the same server and accessing the same database. If you have a distributed application (different sites on different hosts or different sites in different databases), you can resort to solutions for single sign-on.

I use OpenID with a custom provider to centralize logins between applications running on different databases. Other solutions include CAS ( provider and consumer ).

+2
source

In this case, you will have 2 settings.py files with settings_A.py and settings_B.py parameters that indicate from settings import *

A would have SITE = 1 and B would have SITE = B. You can set these files in your apache configurations by setting the environment variable for each virtual host DJANGO_SETTINGS_MODULE = settings_A and DJANGO_SETTINGS_MODULE = settings_B

Then you will create a contrib.sites application with your two domain names attached to the corresponding site identifier, and your flat pages will be able to link to one or both sites.

Finally, in the_A.py settings_B.py settings, you either specify the individual root urlconfs, or use your .SITE settings in your urlconfs to enable and disable URL groups for each site.

Hope this helps

EDIT: To clarify: as long as you use the same database and SECRET_KEY between both sites, you can use the same user accounts between them. If the sites are in the form of example.com and private.example.com, setting SESSION_COOKIE_DOMAIN to .example.com will allow the session to be transferred between both sites.

+2
source

You can use (external) LDAP authentication for both sites. You need an LDAP server available for both sites. I have never used this, and I don’t know how well it integrates with Django auth. See http://packages.python.org/django-auth-ldap/

0
source

Source: https://habr.com/ru/post/896789/


All Articles