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 and scope guards
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",
))],
)
Any route that declares current_user: CurrentUser requires a valid Bearer token.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| litestar_keycloak-0.3.0.tar.gz | 184.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| litestar_keycloak-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 208.6 kB
Release files / litestar_keycloak-0.3.0.tar.gz
| Download URL | litestar_keycloak-0.3.0.tar.gz |
|---|---|
| Size | 184.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eab43cac46fe8703e0357e7e1d50ec67499431ae8b4f02ae268185c9fb305d12
|
|
BLAKE2b-256 checksum How to use checksums |
00fba5097868209778be731ab30a9ce57ad9ff918ecfb6292dbed011d124b08a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 24, 2026.
Transparency logRelease files / litestar_keycloak-0.3.0-py3-none-any.whl
| Download URL | litestar_keycloak-0.3.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cac49e45343484cb410918b5d80d0a0175bc8c09c9c3febdfe61d4f603e463d
|
|
BLAKE2b-256 checksum How to use checksums |
16c4b6faa866e93fcf0449f75f928aa0e9828e49dd79cd1f88096fe201b3538a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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 Jul 24, 2026.
Transparency log