{"id":13424568,"url":"https://github.com/dmontagu/fastapi-auth","last_synced_at":"2025-04-14T03:26:00.834Z","repository":{"id":36580217,"uuid":"228746139","full_name":"dmontagu/fastapi-auth","owner":"dmontagu","description":"Auth for use with FastAPI","archived":false,"fork":false,"pushed_at":"2023-02-14T21:35:21.000Z","size":102,"stargazers_count":153,"open_issues_count":5,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-08T01:12:00.207Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dmontagu.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-12-18T03:00:54.000Z","updated_at":"2025-02-21T11:12:33.000Z","dependencies_parsed_at":"2024-01-03T02:29:46.584Z","dependency_job_id":"9bc49f2c-16f4-44f7-a583-4dfa605e558c","html_url":"https://github.com/dmontagu/fastapi-auth","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/dmontagu%2Ffastapi-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmontagu","download_url":"https://codeload.github.com/dmontagu/fastapi-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248814760,"owners_count":21165823,"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":[],"created_at":"2024-07-31T00:00:56.335Z","updated_at":"2025-04-14T03:26:00.800Z","avatar_url":"https://github.com/dmontagu.png","language":"Python","readme":"# FastAPI Auth\n\n**Pluggable auth for use with [FastAPI](https://github.com/tiangolo/fastapi)**\n\n* Supports OAuth2 Password Flow\n* Uses JWT access and refresh tokens\n* 100% mypy and test coverage \n* Supports custom user models (both ORM and pydantic) without sacrificing any type-safety\n\nUsage:\n------\n\nAfter installing the development dependencies, the following script should run as-is:\n\n```python\nfrom typing import Optional\n\nimport sqlalchemy as sa\nfrom fastapi import FastAPI\nfrom pydantic import EmailStr\n\nfrom fastapi_auth.auth_app import BaseAuthRouterBuilder\nfrom fastapi_auth.auth_settings import get_auth_settings\nfrom fastapi_auth.fastapi_util.api_model import APIModel\nfrom fastapi_auth.fastapi_util.orm.base import Base\nfrom fastapi_auth.models.user import (\n    UserBaseInDB as BaseUserModel,\n    UserCreate as BaseUserCreate,\n    UserCreateRequest as BaseUserCreateRequest,\n    UserInDB as BaseUserInDB,\n    UserUpdate as BaseUserUpdate,\n)\nfrom fastapi_auth.orm.user import BaseUser\n\n\n# Pydantic Models\nclass ExtraUserAttributes(APIModel):\n    email: Optional[EmailStr]\n\n\nclass UserCreate(BaseUserCreate, ExtraUserAttributes):\n    pass\n\n\nclass UserCreateRequest(BaseUserCreateRequest, ExtraUserAttributes):\n    pass\n\n\nclass UserInDB(BaseUserInDB, ExtraUserAttributes):\n    pass\n\n\nclass UserUpdate(BaseUserUpdate, ExtraUserAttributes):\n    pass\n\n\nclass UserResult(BaseUserModel, ExtraUserAttributes):\n    pass\n\n\n# Sqlalchemy Model\nclass User(BaseUser, Base):\n    email = sa.Column(sa.String)\n\n\nclass AuthRouterBuilder(\n    BaseAuthRouterBuilder[\n        UserCreate, UserCreateRequest, UserInDB, UserUpdate, UserResult, User\n    ]\n):\n    create_type = UserCreate\n    create_request_type = UserCreateRequest\n    in_db_type = UserInDB\n    update_type = UserUpdate\n    api_type = UserResult\n    orm_type = User\n\n\nauth_settings = get_auth_settings()\nrouter_builder = AuthRouterBuilder(auth_settings)\n\napp = FastAPI()\n\n...  # Add routes\n\nrouter_builder.include_auth(app.router)\nrouter_builder.add_expired_token_cleanup(app)\n\nprint(list(app.openapi()[\"paths\"].keys()))\n\"\"\"\n[\n    \"/auth/token\",\n    \"/auth/token/refresh\",\n    \"/auth/token/validate\",\n    \"/auth/token/logout\",\n    \"/auth/token/logout/all\",\n    \"/auth/register\",\n    \"/auth/self\",\n    \"/admin/users/{user_id}\",\n    \"/admin/users\",\n]\n\"\"\"\n```\n\nYou can run the above app the same way you would run any other ASGI app, and see the docs at `/docs`.\n\n* You can find a more complete example of configuring an app in `tests/test_auth_app/build_app.py`.\n* Dependency functions that can be used to read the user can be found in `fastapi_auth.dependencies`\n    * If you want to inject the full user model from the database, use the classmethod `AuthRouteBuilder.get_user`\n* Various environment-variable-controlled settings are contained in `fastapi_auth.auth_settings`\n\nContributing:\n-------------\n\nPull requests welcome!\n\nTo get started, clone the repo and run `make develop`.\n\n### Make commands:\n\nRun `make` from the project root to see basic command documentation\n\n### TODO:\n\n* Release on PyPI (please let me know if you can help with this!)\n* Improve documentation, including a more representative example app using dependencies, etc.\n* Refactor `fastapi_auth.fastapi_utils` into a stand-alone package\n* Consider replacing the use of `sqlalchemy`'s ORM with `encode/databases`\n","funding_links":[],"categories":["Third-Party Extensions","Packages"],"sub_categories":["Auth"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmontagu%2Ffastapi-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmontagu%2Ffastapi-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmontagu%2Ffastapi-auth/lists"}