Skip to main content

quadkit-auth

Authentication and authorization for the Quadkit Framework — JWT, OAuth2, SAML, RBAC, and multi-tenancy.


Overview

Complete authentication and authorization stack for Quadkit — JWT, OAuth2, RBAC, SAML, passkeys, and MFA. Provides a production-ready auth layer with multiple authentication strategies, policy-based access control, session management, and seamless integration with quadkit-web middleware.

Use AuthModule.configure() to register the auth bundle and protect routes with @require_auth, @require_roles, and @require_permissions decorators.

Full documentation: docs.quadkit.dev

Install

uv add quadkit-auth
# Optional extras
uv add "quadkit-auth[oauth2,saml]"

Quick Start

from quadkit import Application
from quadkit.di.module import Module, module
from quadkit.auth import AuthModule, AuthConfig, JWTConfig


@module(
    imports=[
        AuthModule.configure(
            config=AuthConfig(
                secret_key="your-secret-key",
                token=JWTConfig(secret_key="your-jwt-secret"),
            )
        )
    ]
)
class AppModule(Module):
    pass


async def main() -> None:
    async with Application.boot(modules=[AppModule]) as app:
        # app is running — resolve services from app.container
        ...


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Configuration

Note: AuthConfig requires both secret_key and token.secret_key — pass an explicit config via AuthModule.configure().

Option 1 — YAML file

# application.yaml
auth:
  secret_key: "your-secret-key"
  token:
    secret_key: "your-jwt-secret"
    algorithm: "HS256"
    access_token_expire: "30m"
  rbac:
    enabled: true
    default_role: "viewer"
export QK_AUTH__SECRET_KEY=your-secret-key
export QK_AUTH__TOKEN__SECRET_KEY=your-jwt-secret
export QK_AUTH__TOKEN__ALGORITHM=HS256
export QK_AUTH__RBAC__DEFAULT_ROLE=viewer

Option 3 — Python

from quadkit.auth import AuthModule, AuthConfig, JWTConfig
from quadkit.contracts.core import Duration

config = AuthConfig(
    secret_key="your-secret-key",
    token=JWTConfig(
        secret_key="your-jwt-secret",
        algorithm="HS256",
        access_token_expire=Duration.minutes(30),
    ),
)
AuthModule.configure(config)

Config reference

Field Default Env var Description
secret_key — QK_AUTH__SECRET_KEY Top-level signing secret (required)
token.secret_key — QK_AUTH__TOKEN__SECRET_KEY JWT signing secret (required)
token.algorithm HS256 QK_AUTH__TOKEN__ALGORITHM JWT algorithm: HS256, RS256, ES256
token.access_token_expire 30m QK_AUTH__TOKEN__ACCESS_TOKEN_EXPIRE Access token lifetime (duration string, e.g. 30m, 1h30m)
rbac.enabled True QK_AUTH__RBAC__ENABLED Enable RBAC
rbac.default_role viewer QK_AUTH__RBAC__DEFAULT_ROLE Default role for new users

Module Factory Methods

Method Description
AuthModule.configure(...) Configure with explicit AuthConfig
AuthModule.stub() Minimal config for testing

Key Features

  • JWT authentication — HS256/RS256, key rotation, token blacklisting
  • OAuth2 / OIDC — authlib-backed: Google, GitHub, custom providers
  • SAML 2.0 — Enterprise SSO via pysaml2
  • Passkeys (WebAuthn) — FIDO2 device-based authentication
  • MFA (TOTP) — Time-based one-time passwords
  • RBAC — Role/permission inheritance with policy expressions
  • Session management — Device-aware sessions with concurrency limits
  • Token binding — IP address binding to prevent token theft

Testing

async with Application.boot(modules=[AuthModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/quadkit/auth/module.py AuthModule definition
src/quadkit/auth/config.py AuthConfig, JWTConfig, RBACConfig
src/quadkit/auth/di/bundle_provider.py AuthBundleProvider wiring
src/quadkit/auth/di/sub_providers/token_provider.py TokenProvider (boots policy)
src/quadkit/auth/authn/jwt.py JWTTokenManager implementation
src/quadkit/auth/authn/_jwt_lifecycle.py verify_token (enforces policy)
src/quadkit/auth/authz/service.py AuthorizationService

JWT verification policy

quadkit-auth enforces verified-only JWT decoding — signature verification cannot be disabled.

Environment Secret present Behaviour
PRODUCTION / STAGING yes Verified-only. Boot succeeds.
PRODUCTION / STAGING no Raises ConfigurationError at boot.
DEVELOPMENT yes Verified-only. Boot succeeds.
DEVELOPMENT no Verified-only. Boots with a generated ephemeral secret (tokens invalidated on restart).

Stable development secret

For multi-service development, set a stable secret via environment variable:

export QK_AUTH__TOKEN__SECRET_KEY="a-stable-dev-secret-at-least-32-chars"

Via Python config:

from quadkit.auth.config import AuthConfig, JWTConfig

config = AuthConfig(
    secret_key="a-stable-dev-secret-at-least-32-chars",
    token=JWTConfig(
        secret_key="a-stable-dev-secret-at-least-32-chars",
    ),
)

This prevents the Piccolina-style mistake of silently trusting unverified tokens in production when a secret env-var is missing.

Metadata

Release files for quadkit-auth 0.0.43

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

Source distribution (sdist)

Source distribution for quadkit-auth 0.0.43
File Size Uploaded Provenance
quadkit_auth-0.0.43.tar.gz 287.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for quadkit-auth 0.0.43
File Interpreter ABI Platform
quadkit_auth-0.0.43-py3-none-any.whl Python 3 none any Details

Total release size: 542.5 kB

Release files / quadkit_auth-0.0.43.tar.gz

Download URL quadkit_auth-0.0.43.tar.gz
Size 287.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2963e07bb0994b614b6ea9646083dfb80adcd871f1a174b6edebc2a4431bd619
BLAKE2b-256 checksum
How to use checksums
d4e5b61ac2b24e26bcc3909c6e483f77c5fa8c2c971a16d66e5e9a1a64e8c43e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release files / quadkit_auth-0.0.43-py3-none-any.whl

Download URL quadkit_auth-0.0.43-py3-none-any.whl
Size 255.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48eb3ac1ad639e086127e00d42b6a6266c72ae61f4c099486be3834133f33896
BLAKE2b-256 checksum
How to use checksums
2052814e038d295da29836cd887b8b793ebb6a1000dc3b470e9183bcd4676fc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Security for quadkit-auth 0.0.43

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.

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