{"id":30434356,"url":"https://github.com/dyakovri/fastapi-auth-oidc","last_synced_at":"2026-04-15T22:36:03.447Z","repository":{"id":307895715,"uuid":"973830870","full_name":"dyakovri/fastapi-auth-oidc","owner":"dyakovri","description":"Check credentials with ease using OpenID Connect","archived":false,"fork":false,"pushed_at":"2025-08-02T20:35:41.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-02T22:18:34.485Z","etag":null,"topics":["authentication","fastapi","jwt","openid-connect"],"latest_commit_sha":null,"homepage":"https://pypi.org/p/fastapi-auth-oidc/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dyakovri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2025-04-27T20:30:46.000Z","updated_at":"2025-08-02T20:35:44.000Z","dependencies_parsed_at":"2025-08-02T22:18:36.290Z","dependency_job_id":"19ee44df-c1a1-468b-9c04-a59b76b02233","html_url":"https://github.com/dyakovri/fastapi-auth-oidc","commit_stats":null,"previous_names":["dyakovri/fastapi-auth-oidc"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dyakovri/fastapi-auth-oidc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyakovri%2Ffastapi-auth-oidc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyakovri%2Ffastapi-auth-oidc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyakovri%2Ffastapi-auth-oidc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyakovri%2Ffastapi-auth-oidc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dyakovri","download_url":"https://codeload.github.com/dyakovri/fastapi-auth-oidc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dyakovri%2Ffastapi-auth-oidc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271717620,"owners_count":24808594,"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","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"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":["authentication","fastapi","jwt","openid-connect"],"created_at":"2025-08-22T23:38:21.480Z","updated_at":"2026-04-15T22:35:58.425Z","avatar_url":"https://github.com/dyakovri.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI OIDC Security\n\nThis library allows your server-side application to check credentials with ease using OpenID Connect\ntoken flows. Use it with Firebase, Keycloak, Authentik or other OIDC providers.\n\n\n## Simple usage\n\nYou can just add `auth_user` dependency to take token data into your FastAPI routes.\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_auth_oidc import OIDCProvider, IDToken\nfrom fastapi_auth_oidc.exceptions import AuthenticationException\n\n\napp = FastAPI()\nauth_user = OIDCProvider(\n    configuration_uri=\"https://example.domain/issuer/.well-known/openid-configuration\",\n    client_id=\"my-client\",\n)\n\n\n@app.exception_handler(AuthenticationException)\ndef invalid_credentials(request: Request, exc: InvalidCredentialsException):\n    return JSONResponse(\n        status_code=403,\n        content={\"detail\": \"Invalid token\"},\n    )\n\n\n@app.get(\"/me\")\ndef get_me(\n    user: Annotated[IDToken | None, Depends(auth_user)],\n):\n    return user.model_dump() if user else {}\n```\n\n\n## Advanced authorization\n\nFor authorization with this package you shoud create security guards. Example below provides\n`NamedTuple` with 2 authorization methods: authenticated and is_admin. They uses FastAPI dependency\ninjection to ensure user and validate token. Now you shoud alse use them as dependencies.\n\n```python\nfrom typing import Annotated, NamedTuple\n\nfrom fastapi import Depends\nfrom fastapi_auth_oidc import IDToken, OIDCProvider\nfrom fastapi_auth_oidc import IDToken, OIDCProvider\nfrom fastapi_auth_oidc.exceptions import UnauthenticatedException\n\n\n# Taking a new property mapping from JWT\nclass MyIDToken(IDToken):\n    my_app_permissions: str | None = None\n\n# Setting up provider\nauth_user = OIDCProvider(\n    configuration_uri=str(settings.oidc_configuration_uri),\n    client_id=settings.oidc_client_id,\n    token_type=MyIDToken,\n)\nTokenData = Annotated[MyIDToken | None, Depends(auth_user)]\n\n\n# Check if user token set and valid\ndef get_authenticated(user: TokenData):\n    if not user:\n        raise UnauthenticatedException()\n    return user\n\n\n# Check if user has `my_app_permissions` field in JWT token and it equals to `admin`.\ndef get_is_admin(user: Annotated[MyIDToken, Depends(get_authenticated)]):\n    if not user.my_app_permissions == \"admin\":\n        raise Exception()\n    return user\n\n\n# This utilities in pretty form\nclass User(NamedTuple):\n    authenticated = Annotated[IDToken, Depends(get_authenticated)]\n    is_admin = Annotated[IDToken, Depends(get_is_admin)]\n\n# Usage\napp = FastAPI()\n\n@app.get(\"/everybody\")\ndef get_me(user: TokenData):\n    \"\"\"Everybody can open `\"/everybody` =)\"\"\"\n    return user.model_dump() if user else {}\n\n\n@app.get(\"/authenticated\")\ndef get_me(user: User.authenticated):\n    \"\"\"Only users with valid JWT token will get their data\"\"\"\n    return user.model_dump()\n\n\n@app.get(\"/admin\")\ndef get_me(user: User.is_admin):\n    \"\"\"Only users with `my_app_permissions == \"admin\"` can get their data\"\"\"\n    return user.model_dump()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyakovri%2Ffastapi-auth-oidc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdyakovri%2Ffastapi-auth-oidc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdyakovri%2Ffastapi-auth-oidc/lists"}