Skip to main content

litestar-keycloak

PyPI version Python versions License CI Coverage Checked with mypy

Keycloak OIDC/OAuth2 authentication plugin for Litestar — token validation, dependency injection, and guards via Litestar's native plugin protocol.

📖 Documentation

Features

  • Bearer token validation (header, cookie, or server-side session)
  • JWKS caching with automatic key rotation
  • Realm/client role and scope guards
  • KeycloakUser injection 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.1

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

Source distribution (sdist)

Source distribution for litestar-keycloak 0.3.1
File Size Uploaded
litestar_keycloak-0.3.1.tar.gz 187.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for litestar-keycloak 0.3.1
File Interpreter ABI Platform
litestar_keycloak-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 211.8 kB

Release files / litestar_keycloak-0.3.1.tar.gz

Download URL litestar_keycloak-0.3.1.tar.gz
Size 187.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7948112f47f92a069113345cc39223363e7c8210618bba01b31c798f1a1df516
BLAKE2b-256 checksum
How to use checksums
6ce50b7273a20893bb7af8f6ff348f858865c63f0fb7eaeccc1686c8ced75cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 30, 2026.

Transparency log

Release files / litestar_keycloak-0.3.1-py3-none-any.whl

Download URL litestar_keycloak-0.3.1-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e9a617d9b3879350cb261607e4174a3afa90bf196cedeb248ebe7b2116aa015
BLAKE2b-256 checksum
How to use checksums
57c4c5af9ee6555b01a51bf10477f2c29a7cd27ab7c69a5a1744b7d6549c47a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.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 Aug 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.2

2 release files

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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