Django Session Header: Identify the session through a header
There are some situations where the browser may not allow any cookies at all to be used. In those cases, we would like to be able to fall back to something that is both secure, and capable. This package allows you to manually pass the sessionid using a header, so that you can continue to use Django’s excellent session management.
It extends Django’s built-in sessions to support sessions in places where cookies are not allowed. For most views, the handling will be seamless. Those that need to have sessions that persist despite the absence of cookies, there are a few extra features.
Usage
First, install the package.
pip install django-session-header
Replace django.contrib.sessions.middleware.SessionMiddleware in your settings.py with the following:
MIDDLEWARE_CLASSES = [
# ...
# 'django.contrib.session.middleware.SessionMiddleware',
'django_session_header.middleware.SessionMiddleware',
]
And replace the Django Rest Framework SessionAuthentication class with django_session_header.authentication.SessionAuthentication:
REST_FRAMEWORK = {
'DEFAUlT_AUTHENTICATION_CLASSES': [
# ...
# 'rest_framework.authentication.SessionAuthentication',
'django_session_header.authentication.SessionAuthentication',
]
}
If a session was obtained via a session header, then request.session.csrf_exempt will be True. You can use this to conditionally apply CSRF protection. Or, if you prefer, you can replace Django’s normal CSRF middleware with django_session_header.middleware.CsrfViewMiddleware:
MIDDLEWARE_CLASSES = [
# ...
# 'django.middleware.csrf.CsrfViewMiddleware',
'django_session_header.middleware.CsrfViewMiddleware',
]
The sessionid will be available in the X-SessionID response header, and you can now set the X-SessionID header on the request manually to avoid needing cookies to power your sessions.
Metadata
Release files for django-session-header 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-session-header-1.0.tar.gz | 4.5 kB | Without provenance | Details for django-session-header-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_session_header-1.0-py3-none-any.whl | Python 3 | none | any | Details for django_session_header-1.0-py3-none-any.whl |
Total release size: 17.6 kB
Release files / django-session-header-1.0.tar.gz
| Download URL | django-session-header-1.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcbffc01d21ffcf22344529142d320300f76d7de7d14ff2e9b29b830b5a6c54b
|
|
BLAKE2b-256 checksum How to use checksums |
3455bea72634c423822c80b8142a68e1ffc5a5067c62e398546833ef3a6d2684
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0a2 CPython/3.6.6 Linux/4.18.0-16-generic
|
Release files / django_session_header-1.0-py3-none-any.whl
| Download URL | django_session_header-1.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
683c940c8b2550a2ccf45ab58def563921f14ecb307746960b03ea3cac6b0f57
|
|
BLAKE2b-256 checksum How to use checksums |
f17b65ec8d807c4d9d5bda1b4626e5dc5d5aeab8dc1577c83de6ea32bd2f0b4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0a2 CPython/3.6.6 Linux/4.18.0-16-generic
|
Security for django-session-header 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.