Skip to main content

Thin FastAPI auth dependency for Qavren (Keycloak) realms

Project description

qavren-auth (Python)

Thin FastAPI auth dependency for Qavren (Keycloak) realms. Validates RS256 bearer tokens against a realm's JWKS endpoint. No custom cryptography; PyJWT does the verification. Fails closed (401) on every error path.

Install

pip install qavren-auth

Use

from fastapi import Depends, FastAPI
from qavren_auth import require_user, require_roles, User

app = FastAPI()

@app.get("/me")
def me(user: User = Depends(require_user("squarelog"))):
    return {"sub": user.sub, "email": user.email, "roles": sorted(user.roles)}

@app.get("/admin")
def admin(user: User = Depends(require_roles("squarelog", "admin"))):
    return {"sub": user.sub}

Convention (shared by all Qavren SDKs)

  • Base URL comes from QAVREN_AUTH_URL (default https://auth.qavren.com); override per-dependency with base_url=.
  • Issuer is {base}/realms/{realm}; JWKS is {issuer}/protocol/openid-connect/certs.
  • Claims consumed: sub, email, realm_access.roles. Nothing else.
  • Audience is NOT validated — Keycloak defaults aud to account. Trust rests on RS256 signature (realm JWKS) + issuer + expiry.
  • Fail closed: a missing/garbage/expired/wrong-issuer token, or an unreachable JWKS with no valid cached keys, returns 401 — never 500, never pass-through. Missing a required role returns 403.

Realm isolation

Each app gets its own realm, so a token minted for squarelog is signed by squarelog's key and carries iss=.../realms/squarelog. A require_user("recharacter") dependency fetches recharacter's JWKS and validates a different issuer, so the squarelog token is rejected. This is the product guarantee, covered by test_token_from_another_realm_rejected.

Not yet published

This package is not on PyPI yet. Consume it from a local checkout (pip install -e sdks/python) until the publishing pipeline lands.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qavren_auth-0.1.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qavren_auth-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file qavren_auth-0.1.0.tar.gz.

File metadata

  • Download URL: qavren_auth-0.1.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qavren_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 064dbcbe8dae54c32328f0782bb1a188f0b1bd2c56e37944f74564f818a46836
MD5 8af455dc3d96df0b1f2f6bf0dfab3550
BLAKE2b-256 72d799b637db6caf968372070058e1ccf59e85d49b90de35b867b5e32a1ee1f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for qavren_auth-0.1.0.tar.gz:

Publisher: release.yml on stevenfackley/qavren-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qavren_auth-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qavren_auth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qavren_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acff3ed261b55396220cd807050d716170a9eb6d490200abfbf752278ec708e4
MD5 82a3bdfa4467622f6572692766bf58c0
BLAKE2b-256 e74fb6d11021ee0bdfe1c56cb2f5de86b3ce67f4c08746b18714cc1084f27d20

See more details on using hashes here.

Provenance

The following attestation bundles were made for qavren_auth-0.1.0-py3-none-any.whl:

Publisher: release.yml on stevenfackley/qavren-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page