patera-auth
Authentication and authorization middleware for Patera: cookies, JWT, roles and password hashing. Part of Patera, a modular async-first Python web framework.
Installation
pip install patera-auth
# or, with uv
uv add "patera[auth]"
Requires Python 3.13 or newer and patera>=0.121.
Usage
patera-auth provides an authentication middleware. Implement how users and roles are loaded:
# app/middleware/auth_mw.py
import jwt
from patera import Request
from patera.auth import Authentication, AuthUtils
from patera.middleware import middleware
@middleware
class TokenAuth(Authentication):
async def user_loader(self, req: Request):
token = req.headers.get("authorization", "").removeprefix("Bearer ")
try:
claims = AuthUtils.validate_jwt_token(token, self.app.configs.SECRET_KEY)
except jwt.InvalidTokenError:
return None # -> not authenticated
return await load_user(claims["sub"])
async def roles_loader(self, user) -> list:
return user.roles
See the Authentication section of the Patera documentation for the full guide.
License
MIT. See LICENSE.
Metadata
Release files for patera-auth 0.11.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 | |
|---|---|---|---|
| patera_auth-0.11.0.tar.gz | 7.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| patera_auth-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / patera_auth-0.11.0.tar.gz
| Download URL | patera_auth-0.11.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7faa76b3b5896c1bec6aafa2000d2107977aee5f6aad417c86c23b0c457e6cf
|
|
BLAKE2b-256 checksum How to use checksums |
43a8366d64286863d40131df75ab531dae4a047ea2762d3da2d000dfcca1e4e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / patera_auth-0.11.0-py3-none-any.whl
| Download URL | patera_auth-0.11.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf645216887744870da85469578db14ec61976a6ce60b7bd5305d56101fb01ef
|
|
BLAKE2b-256 checksum How to use checksums |
74606e2e00856159df80642cfe3878876a473bc0fd69cd8f01fb02e06394cd57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|