A new signed-cookie implementation for Beaker Sessions
Features
- so much safer than default Pickle serialization
- serialize with BSON and compress, so more datatypes supported than JSON (optional)
- multiple keys, so you can rotate them
- stronger hash algorithm (SHA256)
- backwards compatible reads/writes with original pickle-based beaker session cookies
- JWT for signing (although not much else of JWT is implemented)
Install
pip install 'beaker-session-jwt'
Usage
See beaker docs for general implementation. Specify using this class:
from beaker_session_jwt import JWTCookieSession
app = SessionMiddleware(app, config, session_class=JWTCookieSession)
Additional config options
See Beaker docs for main config options, many of which apply to this class too.
jwt_secret_keysrequired. One or more comma-separated keys- generate a key with
python -c 'import secrets; print(secrets.token_hex());' - multiple signing keys are supported, so you can rotate them. The first one in the list will be used for writing, the rest will be permitted for verifying.
- generate a key with
bson_compress_jwt_payloaddefault True- serializing with BSON and compressing with zlib, to allow for types like datetime, bytes, etc to be stored which JSON cannot store. This is stored all in a single JWT field, so JWT is hardly being used, just for signatures really
read_original_formatdefault False- set to true to read original beaker signed cookies. Allows for backward compatibility and transition periods
- after a transition period, make sure to set this back to False
original_format_validate_keyrequired ifread_original_formatoriginal_format_data_serializeroriginal_format_remove_keysoptional comma-separated list- if your old sessions have values that pickle supported, but don't work any more, list the session keys here. They will be removed but the rest of the session will be preserved.
write_original_formatdefault False- set to true if you have many servers/processes and need to roll this out gradually. Then later set to False when all processes are ready.
Non-Features
- no encrypted cookies (could be possible with JWT though)
- JWT payload/claim fields (
iss,sub,exp, etc) are not used or verified. Instead, this uses the fields that a beaker CookieSession has, for maximum backwards compatibility and simplicity. - pymongo/bson is always required even with
bson_compress_jwt_payload=False
License
Apache License
Metadata
Release files for beaker-session-jwt 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| beaker_session_jwt-1.0.4.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| beaker_session_jwt-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / beaker_session_jwt-1.0.4.tar.gz
| Download URL | beaker_session_jwt-1.0.4.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df44fdda050fbb0e89f0171edcab30f95748367bedbb392615fa601b3c4c2d64
|
|
BLAKE2b-256 checksum How to use checksums |
bf2f8c8dfa1ebf1c2c0d3f34703f466163f78d5863fc2f33ea1f3846776aab35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / beaker_session_jwt-1.0.4-py3-none-any.whl
| Download URL | beaker_session_jwt-1.0.4-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a81c9b41c80c783a1860db3cb4444ac02500d296c6d53a4356ebfb01cbc547ce
|
|
BLAKE2b-256 checksum How to use checksums |
b7538a95492fe5828500e7598d425ec55711074f9c545807799fad7bc5fcf133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|