A small FastAPI integration for Keycloak authentication with two example apps (backend + Svelte frontend).
Prerequisites
Quickstart (development)
peotry install
cd examples/backend
# starts the example API at http://127.0.0.1:8000
uvicorn main:app --reload --port 8000
cd examples/svelte
npm install
npm run dev
# the Svelte dev server typically runs at http://127.0.0.1:5173
Environment variables
Keycloak settings are read from environment variables with the KEYCLOAK_ prefix (a .env file is supported). At minimum set:
KEYCLOAK_SERVER_URL (e.g. https://auth.example.com)KEYCLOAK_REALMKEYCLOAK_CLIENT_IDKEYCLOAK_CLIENT_SECRETAdditional options and defaults are defined in src/fastapi_keycloak_auth/config.py (frontend/backend URLs, cookie options, scopes, etc.).
Examples / Demo
examples/backend — small FastAPI app with public and protected endpoints.examples/svelte — Svelte example app that works with the backend.Notes
Further reading
src/fastapi_keycloak_auth/ for router, dependencies and config.KEYCLOAK_ variables to it.License