{"id":17657763,"url":"https://github.com/livioribeiro/fastapi-resource-server","last_synced_at":"2025-10-26T16:37:17.649Z","repository":{"id":57428513,"uuid":"371451714","full_name":"livioribeiro/fastapi-resource-server","owner":"livioribeiro","description":"Authenticate FastAPI with OIDC discovery","archived":false,"fork":false,"pushed_at":"2024-04-24T14:37:28.000Z","size":7,"stargazers_count":24,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-19T20:53:46.066Z","etag":null,"topics":["authentication","fastapi","oidc","python","web"],"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/livioribeiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-27T17:22:43.000Z","updated_at":"2025-01-15T18:24:05.000Z","dependencies_parsed_at":"2022-09-19T05:10:12.876Z","dependency_job_id":null,"html_url":"https://github.com/livioribeiro/fastapi-resource-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Ffastapi-resource-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Ffastapi-resource-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Ffastapi-resource-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Ffastapi-resource-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livioribeiro","download_url":"https://codeload.github.com/livioribeiro/fastapi-resource-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252850590,"owners_count":21813988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["authentication","fastapi","oidc","python","web"],"created_at":"2024-10-23T14:43:23.278Z","updated_at":"2025-10-26T16:37:17.576Z","avatar_url":"https://github.com/livioribeiro.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI Resource Server\n\nBuild an OIDC resource server using FastAPI.\n\nYour aplication receives the claims decoded from the access token.\n\n# Usage\n\nRun keycloak on port 8888:\n\n```sh\ndocker container run --name auth-server -d -p 8888:8080 \\\n    -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin \\\n    jboss/keycloak:latest\n```\n\nInstall dependencies\n\n```sh\npip install fastapi fastapi_resource_server uvicorn\n```\n\nCreate the main.py module\n\n```python\nfrom fastapi import Depends, FastAPI, Security\nfrom pydantic import BaseModel\n\nfrom fastapi_resource_server import JwtDecodeOptions, OidcResourceServer\n\napp = FastAPI()\n\ndecode_options = JwtDecodeOptions(verify_aud=False)\n\nauth_scheme = OidcResourceServer(\n    \"http://localhost:8888/auth/realms/master\",\n    scheme_name=\"Keycloak\",\n    jwt_decode_options=decode_options,\n)\n\n\nclass User(BaseModel):\n    username: str\n    given_name: str\n    family_name: str\n    email: str\n\n\ndef get_current_user(claims: dict = Security(auth_scheme)):\n    claims.update(username=claims[\"preferred_username\"])\n    user = User.parse_obj(claims)\n    return user\n\n\n@app.get(\"/users/me\")\ndef read_current_user(current_user: User = Depends(get_current_user)):\n    return current_user\n```\n\nRun the application\n\n```sh\nuvicorn main:app\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivioribeiro%2Ffastapi-resource-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivioribeiro%2Ffastapi-resource-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivioribeiro%2Ffastapi-resource-server/lists"}