Skip to main content

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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for patera-auth 0.11.1
File Size Uploaded
patera_auth-0.11.1.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for patera-auth 0.11.1
File Interpreter ABI Platform
patera_auth-0.11.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / patera_auth-0.11.1.tar.gz

Download URL patera_auth-0.11.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4f061edea062fb64fdaa972af52c1ff73741be294c6241d8df3737b85186acf8
BLAKE2b-256 checksum
How to use checksums
6524bc3cde575eb10b8c056be6a8281c8a337a9bd4aecf643fc94a64b901ef9d
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.1-py3-none-any.whl

Download URL patera_auth-0.11.1-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b59c5dfaf80ae84f94191a59be653358f91cfb93e05e5dfae939e361dd99518
BLAKE2b-256 checksum
How to use checksums
4448337ccbdc36310d9b26a8c6b9daf89c4320a065aec19416e84c54d7bc21e0
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 history Release notifications | RSS feed

This release

0.11.1 This release

2 release files

0.11.0

2 release files

0.10.0

1 release file

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page