Package: django-shared-session
django-shared-sessiondjango-shared-session is a tool that enables cross site session sharing, which can be useful when running the same Django
application on different domains (for example due to different language mutations). This library can be used for sharing login information as well as session data for both authenticated and anonymous users. If all you need is to share login information, please  consider using some of single sign-on (SSO) solutions which could be better for this specific use case.This tool is only useful when you are running your application on different domains, not just subdomains. Subdomains can be handled with cookies path set to.domain.tld(starts with dot).This project is inspired bydjango-xsession, but uses a different approach to session sharing which sets the cookie on server-side and thus does not require reloading the page.How it worksUser visits one of the configured sitesSession key is encrypted and included in the HTML file. This file contains<script>tags linking to all configured sites with encrypted session key (as part of the file name).Browser requests the script filesOn destination domain the session key is decrypted from payload and saved to cookiesExample HTML snippet:<scriptsrc="http://www.example.org/shared-session/9x7JV1xWFAk8nWhORGCkO5O4zUSjVCR-2abQh7AnFRckiwk8adn6PVlCsdqX4SaTY2dde7S3YuM0ZchKsCuZZiYSZwVLtOA5IoUJRHDl74s4uBYQERQQQMh6T48WD883cFvAaI0XVKB1d5YVtZ7st7GIfxUv2kw6JqftQnFb7uhAOtbTrbdsVWdJEQYdBbweoQPRm9BiRodpk8oo6gpKKC434jPLnJX4-B31KhessmVrgC6_7AOjyZUypC52JXAEjZQm.js"async></script><scriptsrc="http://www.another-domain.org/shared-session/v_artye4YSMnbbqrrBzUqmIIBFArsMRIkH9vIBNqiEM3uMJQF2RMJtLifIaehbMxRG-ChyMB3gDyLTGmbtCOhs1ODcFAy0PdekJHlSoLR3xezvDCld0YBbfDoOQFVqPeTavHx2uF7X-6A5bWRtV19hg5kI4uFDKWHATCxm2EdXZPrkN23nX_2-PUfCufAQR3vJeJQRjSzj-FfX-qK9xxAeL1-rvUwJvb2bCvoqL0gCTMNBMSeXLMkjjlpXmmlAfGeU3C.js"async></script>Encrypted payload (containing session key, timestamp, source and destination hostname) in base64 is part of the filename itself. Destination server checks the timestamp to prevent replay attacks.Installationpipinstalldjango-shared-sessionThis tool accesses request inside template, so please make sure you haveRequestContextenabled in your template's engine context processors.UsageAddshared_sessiontoINSTALLED_APPSand set shared session domains in Django settings file.
Then addshared_session.urlsto your urlconf.settings.py:INSTALLED_APPS=['django.contrib.admin','django.contrib.auth',# ...'shared_session']SHARED_SESSION_SITES=['www.example.com','www.example.org']urls.py:importshared_sessionurlpatterns=[url(r'^shared-session/',shared_session.urls),# feel free to change the base url]In order to share sessions with configured sites you also need to use{% shared_session_loader %}in your base template.layout.html:{% load shared_session %}<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8">{% shared_session_loader %}</head><body></body></html>If you want to share sessions also in Django admin interface, you can overwriteadmin/base_site.htmland include the loader.Advanced optionsSHARED_SESSION_ALWAYS_REPLACE– Always replace session cookie, even if the session is not empty. (default: False)SHARED_SESSION_TIMEOUT– Expiration timeout. Session needs to be delivered to destination site before this time. (default: 30)SignalsSignalsession_replacedis triggered when target's site session cookie was changed or created.
You can connect your own handlers to run additional functions.fromshared_sessionimportsignalsimportloggingdeflog_session_replace(sender,**kwargs):logging.info('%ssession replaced'%kwargs.get('dst_domain'))signals.session_replaced.connect(log_session_replace)LicenseThis software is licensed under MPL 2.0.http://mozilla.org/MPL/2.0/http://www.mozilla.org/MPL/2.0/FAQ.html#use