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

Authentication already implements the middleware() handler. Inherit it and implement only the two required async methods in your subclass. user_loader(req) returns the account or None. roles_loader(user) returns the user's roles, or an empty list if the user has none.

# 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.13.5

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.13.5
File Size Uploaded Provenance Actions
patera_auth-0.13.5.tar.gz 7.5 kB Without provenance Details for patera_auth-0.13.5.tar.gz

Built distribution (wheel)

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

Total release size: 16.5 kB

Release files / patera_auth-0.13.5.tar.gz

Download URL patera_auth-0.13.5.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dc8efd05e1225215dc1ccf93f5c46371f60e82999073f39e5dd3a8900e15110e
BLAKE2b-256 checksum
How to use checksums
8c0d7dea27d5da7cd31d666e3eff1d0d85a8d89c3a5c01f40d88a9564199e180
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.13.5-py3-none-any.whl

Download URL patera_auth-0.13.5-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca809e089b830af57e207909575ec7b0a20180552a2a11f8f91f7aaf5802f3cb
BLAKE2b-256 checksum
How to use checksums
47e04f791fcaee7739b0f355f1c45c8fbfc22ec9c7fe685a6ec32b9dc140a41b
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}

Security for patera-auth 0.13.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.13.5 This release

2 release files No provenance

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