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(defaulthttps://auth.qavren.com); override per-dependency withbase_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
audtoaccount. 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
064dbcbe8dae54c32328f0782bb1a188f0b1bd2c56e37944f74564f818a46836
|
|
| MD5 |
8af455dc3d96df0b1f2f6bf0dfab3550
|
|
| BLAKE2b-256 |
72d799b637db6caf968372070058e1ccf59e85d49b90de35b867b5e32a1ee1f9
|
Provenance
The following attestation bundles were made for qavren_auth-0.1.0.tar.gz:
Publisher:
release.yml on stevenfackley/qavren-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qavren_auth-0.1.0.tar.gz -
Subject digest:
064dbcbe8dae54c32328f0782bb1a188f0b1bd2c56e37944f74564f818a46836 - Sigstore transparency entry: 2192542152
- Sigstore integration time:
-
Permalink:
stevenfackley/qavren-auth@84334378f0b461aa1e293c2f6317e1533abdc315 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/stevenfackley
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84334378f0b461aa1e293c2f6317e1533abdc315 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acff3ed261b55396220cd807050d716170a9eb6d490200abfbf752278ec708e4
|
|
| MD5 |
82a3bdfa4467622f6572692766bf58c0
|
|
| BLAKE2b-256 |
e74fb6d11021ee0bdfe1c56cb2f5de86b3ce67f4c08746b18714cc1084f27d20
|
Provenance
The following attestation bundles were made for qavren_auth-0.1.0-py3-none-any.whl:
Publisher:
release.yml on stevenfackley/qavren-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qavren_auth-0.1.0-py3-none-any.whl -
Subject digest:
acff3ed261b55396220cd807050d716170a9eb6d490200abfbf752278ec708e4 - Sigstore transparency entry: 2192542205
- Sigstore integration time:
-
Permalink:
stevenfackley/qavren-auth@84334378f0b461aa1e293c2f6317e1533abdc315 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/stevenfackley
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84334378f0b461aa1e293c2f6317e1533abdc315 -
Trigger Event:
push
-
Statement type: