No project description provided
Project description
Tornado Auth Sessions
Simple, secure Redis-backed session mixin for Tornado.
Installation
pip install tornado-auth-sessions
Setup
Configure Redis via Tornado application settings:
import tornado.web
app = tornado.web.Application(
handlers,
redis_host={
"host": "localhost",
"port": 6379,
"db": 0,
"password": None,
"decode_responses": True,
},
cookie_secret="YOUR_SECRET_KEY",
)
Usage
Create a base handler:
import tornado
from tornado_auth_sessions import TornadoSessionsMixin
class BaseHandler(
TornadoSessionsMixin,
tornado.web.RequestHandler,
):
pass
Example
Login
class LoginHandler(BaseHandler):
def post(self):
# authenticate user...
self.set_session(user.id)
self.redirect("/dashboard")
Protected route
class DashboardHandler(BaseHandler):
def get(self):
user_id = self.get_session()
if not user_id:
self.redirect("/login")
return
self.write(f"Welcome user {user_id}")
Logout
class LogoutHandler(BaseHandler):
def post(self):
self.remove_session(user.id)
self.redirect("/")
Authentication (Tornado Native)
This library integrates seamlessly with Tornado’s built-in authentication system via get_current_user.
Add this to your base handler:
def get_current_user(self):
return self.get_session()
Authentication (Tornado Native)
This library integrates seamlessly with Tornado’s built-in authentication system via get_current_user.
Add this to your base handler:
import tornado
class DashboardHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
user_id = self.current_user
self.write(f"User: {user_id}")
def get_current_user(self):
return self.get_session()
---
## Security notes
- Uses Tornado set_secure_cookie (signed, tamper-proof)
- Always use HTTPS in production
- Set secure=True for cookies
- Use strong cookie_secret
- Pair with CSRF protection for forms
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tornado_auth_sessions-0.0.3.tar.gz.
File metadata
- Download URL: tornado_auth_sessions-0.0.3.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0718021a21541c0069b62e644c7f93cd3aa942148b4a2864e2c0fc1bcec47a75
|
|
| MD5 |
2fc555bc2b044390d177b5d886460a64
|
|
| BLAKE2b-256 |
62de7531944c2f456347bc0b5eb9d8156669e1966b401f2542f1c26ed08ad610
|
File details
Details for the file tornado_auth_sessions-0.0.3-py3-none-any.whl.
File metadata
- Download URL: tornado_auth_sessions-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b8f547668f3ea97e16badccacff145054eb5ed99b09a8e621fe62cef104a4f1
|
|
| MD5 |
e4bdaa1b0b9f6a5f90807b034fae9049
|
|
| BLAKE2b-256 |
f72cf8f33ce4291177c6303eba1b1bc1efa2d50ce58884d53a44aacdac3b4d87
|