Skip to content

Commit 683f58d

Browse files
Update README.md
1 parent 7004f65 commit 683f58d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@ It can be used even for situations where Single sign-on (SSO) is not suitable, e
66
This project is inspired by [django-xsession](https://github.com/badzong/django-xsession), but uses a different approach to session sharing
77
which sets the cookie on server-side and thus does not require reloading the page.
88

9+
## How it works
10+
11+
1. User visits one of the configured sites
12+
2. Session 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).
13+
3. Browser requests the script files
14+
4. On destination domain the session key is decrypted from payload and saved to cookies
15+
16+
Example HTML snippet:
17+
```html
18+
<script src="http://www.example.org/shared-session/9x7JV1xWFAk8nWhORGCkO5O4zUSjVCR-2abQh7AnFRckiwk8adn6PVlCsdqX4SaTY2dde7S3YuM0ZchKsCuZZiYSZwVLtOA5IoUJRHDl74s4uBYQERQQQMh6T48WD883cFvAaI0XVKB1d5YVtZ7st7GIfxUv2kw6JqftQnFb7uhAOtbTrbdsVWdJEQYdBbweoQPRm9BiRodpk8oo6gpKKC434jPLnJX4-B31KhessmVrgC6_7AOjyZUypC52JXAEjZQm.js" async></script>
19+
<script src="http://www.another-domain.org/shared-session/v_artye4YSMnbbqrrBzUqmIIBFArsMRIkH9vIBNqiEM3uMJQF2RMJtLifIaehbMxRG-ChyMB3gDyLTGmbtCOhs1ODcFAy0PdekJHlSoLR3xezvDCld0YBbfDoOQFVqPeTavHx2uF7X-6A5bWRtV19hg5kI4uFDKWHATCxm2EdXZPrkN23nX_2-PUfCufAQR3vJeJQRjSzj-FfX-qK9xxAeL1-rvUwJvb2bCvoqL0gCTMNBMSeXLMkjjlpXmmlAfGeU3C.js" async></script>
20+
```
21+
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.
22+
923
## Installation
1024

1125
```sh
1226
pip install django-shared-session
1327
```
1428

15-
This tool uses request inside template, so please make sure you have enabled `RequestContext` in your template engine context processors.
29+
This tool accesses request inside template, so please make sure you have `RequestContext` enabled in your template's engine context processors.
1630

1731
## Usage
1832
Add `shared_session` to `INSTALLED_APPS` and set shared session domains in Django settings file.
@@ -59,6 +73,26 @@ layout.html:
5973

6074
If you want to share sessions also in Django admin interface, you can overwrite `admin/base_site.html` and include the loader.
6175

76+
## Advanced options
77+
78+
`SHARED_SESSION_ALWAYS_REPLACE` – Always replace session cookie, even if the session is not empty. (default: False)
79+
`SHARED_SESSION_TIMEOUT` – Expiration timeout. Session needs to be delivered to destination site before this time. (default: 30)
80+
81+
### Signals
82+
83+
Signal `session_replaced` is triggered when target's site session cookie was changed or created.
84+
You can connect your own handlers to run additional functions.
85+
86+
```py
87+
from shared_session import signals
88+
import logging
89+
90+
def log_session_replace(sender, **kwargs):
91+
logging.info('%s session replaced' % kwargs.get('dst_domain'))
92+
93+
signals.session_replaced.connect(log_session_replace)
94+
```
95+
6296
## License
6397

6498
This software is licensed under MPL 2.0.

0 commit comments

Comments
 (0)