{"id":27248830,"url":"https://github.com/bakdata/python-keycloak-oauth","last_synced_at":"2026-04-27T11:32:04.031Z","repository":{"id":225842902,"uuid":"759849571","full_name":"bakdata/python-keycloak-oauth","owner":"bakdata","description":"Keycloak authentication for Python projects with optional integrations for FastAPI \u0026 Starlette-Admin","archived":false,"fork":false,"pushed_at":"2024-03-18T11:23:40.000Z","size":72,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-11T06:49:04.707Z","etag":null,"topics":["fastapi","keycloak","starlette-admin"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bakdata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-02-19T13:05:02.000Z","updated_at":"2025-08-17T07:36:54.000Z","dependencies_parsed_at":"2025-04-10T23:48:15.348Z","dependency_job_id":"30b069ca-a294-4c7b-82bb-98100c52af44","html_url":"https://github.com/bakdata/python-keycloak-oauth","commit_stats":null,"previous_names":["bakdata/python-keycloak-oauth"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bakdata/python-keycloak-oauth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakdata%2Fpython-keycloak-oauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakdata%2Fpython-keycloak-oauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakdata%2Fpython-keycloak-oauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakdata%2Fpython-keycloak-oauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bakdata","download_url":"https://codeload.github.com/bakdata/python-keycloak-oauth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakdata%2Fpython-keycloak-oauth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","keycloak","starlette-admin"],"created_at":"2025-04-10T23:48:12.523Z","updated_at":"2026-04-27T11:32:04.012Z","avatar_url":"https://github.com/bakdata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-keycloak-oauth\n\nKeycloak OAuth client for Python projects with optional integrations for [FastAPI](https://github.com/tiangolo/fastapi) \u0026 [Starlette-Admin](https://github.com/jowilf/starlette-admin).\n\n## Getting started\n\n### FastAPI\n\n```sh\npip install keycloak-oauth[fastapi]\n```\n\n```python\nfrom typing import Annotated\nfrom fastapi import FastAPI, Request, Depends\nfrom starlette.middleware.sessions import SessionMiddleware\nfrom backend.settings import settings, BASE_URL, SECRET_KEY  # secrets\nfrom keycloak_oauth import KeycloakOAuth2\n\nkeycloak = KeycloakOAuth2(\n    client_id=settings.keycloak.client_id,\n    client_secret=settings.keycloak.client_secret,\n    server_metadata_url=str(settings.keycloak.server_metadata_url),\n    client_kwargs=settings.keycloak.client_kwargs,\n    base_url=BASE_URL,\n)\n# create router and register API endpoints\nkeycloak.setup_fastapi_routes()\n\napp = FastAPI()\napp.add_middleware(SessionMiddleware, secret_key=SECRET_KEY)\napp.include_router(keycloak.router, prefix=\"/auth\")\n\n@app.get(\"/\")\ndef index(\n    request: Request, user: Annotated[User, Depends(KeycloakOAuth2.get_user)]\n):\n    \"\"\"Protected endpoint, will return 401 Unauthorized if not signed in.\"\"\"\n    return f\"Hello {user.name}\"\n```\n\nWe now expose the API endpoints for Keycloak:\n\n- `/auth/login`: redirect to Keycloak login page\n- `/auth/callback`: authorize user with Keycloak access token\n- `/auth/logout`: deauthorize user and redirect to the logout page\n\n### Starlette-Admin\n\n```sh\npip install keycloak-oauth[starlette-admin]\n```\n\n```python\nfrom starlette.middleware.sessions import SessionMiddleware\nfrom starlette_admin.contrib.sqla import Admin\nfrom backend.settings import settings, BASE_URL, SECRET_KEY  # secrets\nfrom keycloak_oauth import KeycloakOAuth2\nfrom keycloak.starlette_admin import KeycloakAuthProvider\n\nkeycloak = KeycloakOAuth2(\n    client_id=settings.keycloak.client_id,\n    client_secret=settings.keycloak.client_secret,\n    server_metadata_url=str(settings.keycloak.server_metadata_url),\n    client_kwargs=settings.keycloak.client_kwargs,\n    base_url=BASE_URL,\n)\n\nadmin = Admin(\n    # engine,\n    title=...,\n    base_url=BASE_URL,\n    auth_provider=KeycloakAuthProvider(keycloak),\n    middlewares=[Middleware(SessionMiddleware, secret_key=SECRET_KEY)],\n)\n\nadmin.add_view(...)\n```\n\n## Development\n\nIf you want to contribute to this project, you can simply clone the repository and run `poetry install --all-extras`.\n\nPlease also run `pre-commit install` for linting and enforcing a consistent code style.\n\n## Contributing\n\nWe are happy if you want to contribute to this project. If you find any bugs or have suggestions for improvements, please open an issue. We are also happy to accept your PRs. Just open an issue beforehand and let us know what you want to do and why.\n\n## License\n\nThis project is licensed under the MIT license. Have a look at the [LICENSE](LICENSE) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakdata%2Fpython-keycloak-oauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbakdata%2Fpython-keycloak-oauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakdata%2Fpython-keycloak-oauth/lists"}