Signed & trusted sessions for falcon.
Project description
Falcon signed sessions
This project allows you to easily add trusted cookies to falcon, it works by storing a signed cookie in the client's browser using itsdangerous what we call a session. If the cookie is edited the data won't be loaded into the session context. If you don't store the secret key & salt somewhere secure (like a env file) then the session data will be invalidated between restarts.
How it works
- Use
req.context.get_session(key)
to read session data, None if doesn't exist. - Use
req.context.sessions()
to read all sessions. - Use
resp.context.set_session(key, value)
to edit session data & sign for client.
Install
pip3 install FalconSignedSessions
How to use
import secrets
from FalconSignedSessions import SignedSessions
app = falcon.App()
app.add_middleware(
SignedSessions(
secret_key=secrets.token_urlsafe(24),
salt=secrets.token_bytes(),
session_cookie="session"
)
)
class SessionResource:
def on_get(self, req: Request, resp: Response) -> None:
# Get all sessions as dict.
print(req.context.sessions())
# Used to get a session
print(req.context.get_session("trusted"))
# Set a session.
resp.context.set_session("trusted", True)
app.add_route("/cookies", SessionResource())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
FalconSignedSessions-0.0.3.tar.gz
(16.2 kB
view hashes)
Built Distribution
Close
Hashes for FalconSignedSessions-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba5c006d423c3ef475ef568cb4c36c25546ecdcce6ef6923df302ca79349f3c |
|
MD5 | 2628b3838e27207fa17abeb0f402ff3c |
|
BLAKE2b-256 | 71d2795d72a1536552fe9490918067ae734ce35f969f57e41a007c509dd3eb0f |
Close
Hashes for FalconSignedSessions-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 080e8b5a8950aa6294498e95d180300093baf4b2eed477a88bfadca4de9cd0f3 |
|
MD5 | cc324b6588f2bb3c2e93aa1b2660c2b8 |
|
BLAKE2b-256 | 4753b2025224196897feb9eceb2878dca4f29b72fca2a52cb874ec7bce3b109f |