litestar-keycloak
Keycloak OIDC/OAuth2 authentication plugin for Litestar — token validation, dependency injection, and guards via Litestar's native plugin protocol.
Features
- Bearer token validation (header, cookie, or server-side session)
- JWKS caching with automatic key rotation
- Realm/client role, group, scope and step-up (
acr, recent login) guards - Optional token introspection, so a logout or a disabled user takes effect at once
- Outbound service tokens: cached client_credentials and RFC 8693 token exchange
KeycloakUserinjection via Litestar DI- Optional login/callback/logout/refresh routes — SPA (JSON) or server-rendered (session) flow
Installation
uv add litestar-keycloak
Quick start
from litestar import Litestar, get
from litestar_keycloak import KeycloakPlugin, KeycloakConfig, CurrentUser
@get("/me")
async def me(current_user: CurrentUser) -> dict:
return {"sub": current_user.sub, "roles": current_user.realm_roles}
app = Litestar(
route_handlers=[me],
plugins=[KeycloakPlugin(KeycloakConfig(
server_url="https://keycloak.example.com",
realm="my-realm",
client_id="my-app",
))],
)
Every route requires a valid Bearer token unless it is excluded (excluded_paths, exclude_patterns, exclude_from_auth=True) or marked optional_auth=True; declaring current_user: CurrentUser only gives the handler the user.
Guards
from litestar_keycloak import require_roles, require_scopes
@get("/admin", guards=[require_roles("admin")])
async def admin_panel() -> dict: ...
@get("/reports", guards=[require_scopes("reports:read")])
async def reports() -> dict: ...
Documentation
Configuration, guards, OIDC routes, and the SPA / server-rendered flows are covered in the full documentation. A runnable example app with docker-compose is included.
License
MIT
Metadata
Release files for litestar-keycloak 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| litestar_keycloak-0.3.6.tar.gz | 245.5 kB | With provenance | Details for litestar_keycloak-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| litestar_keycloak-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for litestar_keycloak-0.3.6-py3-none-any.whl |
Total release size: 290.6 kB
Release files / litestar_keycloak-0.3.6.tar.gz
| Download URL | litestar_keycloak-0.3.6.tar.gz |
|---|---|
| Size | 245.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4528df0e63ac08eec98076009ebfd47b6fde5ea115a8961c35a766b0d1a13f5
|
|
BLAKE2b-256 checksum How to use checksums |
3b1e76fee394c081ee83f1704ea1e9b60e9f66e5a83d56139b76756acfc46ab6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / litestar_keycloak-0.3.6-py3-none-any.whl
| Download URL | litestar_keycloak-0.3.6-py3-none-any.whl |
|---|---|
| Size | 45.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71066ee4641698fbca6a8d96cfe88e4607788332dafb3032207da4c30f44c088
|
|
BLAKE2b-256 checksum How to use checksums |
3a57e2419b594aedda15e26434ca241af0f64da15e32b9b831b1de386722e84d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for litestar-keycloak 0.3.6
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for litestar_keycloak-0.3.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA 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.