{"id":15044034,"url":"https://github.com/k4black/fastapi-jwt","last_synced_at":"2025-04-08T11:08:44.398Z","repository":{"id":41853312,"uuid":"434245991","full_name":"k4black/fastapi-jwt","owner":"k4black","description":"FastAPI native extension, easy and simple JWT auth","archived":false,"fork":false,"pushed_at":"2025-02-24T03:07:17.000Z","size":1277,"stargazers_count":144,"open_issues_count":23,"forks_count":19,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T09:29:27.553Z","etag":null,"topics":["api","authorization","fastapi","fastapi-extension","json-web-token","jwt","python","python3"],"latest_commit_sha":null,"homepage":"https://k4black.github.io/fastapi-jwt/","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/k4black.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2021-12-02T14:10:54.000Z","updated_at":"2025-03-12T00:29:20.000Z","dependencies_parsed_at":"2024-01-29T07:46:21.881Z","dependency_job_id":"5556996c-71f7-4b93-911e-ed5a1312c36f","html_url":"https://github.com/k4black/fastapi-jwt","commit_stats":{"total_commits":92,"total_committers":10,"mean_commits":9.2,"dds":0.4782608695652174,"last_synced_commit":"ec8b890f8135ae2ed97faedf7228807fb537db22"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k4black%2Ffastapi-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k4black%2Ffastapi-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k4black%2Ffastapi-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k4black%2Ffastapi-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k4black","download_url":"https://codeload.github.com/k4black/fastapi-jwt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829491,"owners_count":21002995,"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":["api","authorization","fastapi","fastapi-extension","json-web-token","jwt","python","python3"],"created_at":"2024-09-24T20:49:59.090Z","updated_at":"2025-04-08T11:08:44.381Z","avatar_url":"https://github.com/k4black.png","language":"Python","readme":"# fastapi-jwt\n\n[![Test](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/test.yml)\n[![Publish](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml/badge.svg)](https://github.com/k4black/fastapi-jwt/actions/workflows/publish.yml)\n[![codecov](https://codecov.io/gh/k4black/fastapi-jwt/branch/master/graph/badge.svg?token=3F9J850FX2)](https://codecov.io/gh/k4black/fastapi-jwt)\n[![pypi](https://img.shields.io/pypi/v/fastapi-jwt)](https://pypi.org/project/fastapi-jwt/)\n\nFastAPI native extension, easy and simple JWT auth\n\n---\n\n\n**Documentation:** [k4black.github.io/fastapi-jwt](https://k4black.github.io/fastapi-jwt/)  \n**Source Code:** [github.com/k4black/fastapi-jwt](https://github.com/k4black/fastapi-jwt/)\n\n\n## Features\n* OpenAPI schema generation \n* Native integration with FastAPI\n* Access/Refresh JWT\n* JTI\n* Cookie setting\n\n\n## Installation\nYou can access package [fastapi-jwt in pypi](https://pypi.org/project/fastapi-jwt/)\n```shell\npip install fastapi-jwt[authlib]\n# or\npip install fastapi-jwt[python_jose]\n```\n\nThe fastapi-jwt will choose the backend automatically if library is installed with the following priority:\n1. authlib\n2. python_jose (deprecated)\n\n## Usage\nThis library made in fastapi style, so it can be used as standard security features \n\n```python\nfrom fastapi import FastAPI, Security, Response\nfrom fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer\n\n\napp = FastAPI()\naccess_security = JwtAccessBearer(secret_key=\"secret_key\", auto_error=True)\n\n\n@app.post(\"/auth\")\ndef auth():\n    subject = {\"username\": \"username\", \"role\": \"user\"}\n    return {\"access_token\": access_security.create_access_token(subject=subject)}\n\n@app.post(\"/auth_cookie\")\ndef auth(response: Response):\n    subject = {\"username\": \"username\", \"role\": \"user\"}\n    access_token = access_security.create_access_token(subject=subject)\n    access_security.set_access_cookie(response, access_token)\n    return {\"access_token\": access_token}\n\n\n@app.get(\"/users/me\")\ndef read_current_user(\n    credentials: JwtAuthorizationCredentials = Security(access_security),\n):\n    return {\"username\": credentials[\"username\"], \"role\": credentials[\"role\"]}\n```\n\nFor more examples see usage docs\n\n\n## Alternatives \n\n* FastAPI docs suggest [writing it manually](https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/), but\n  * code duplication  \n  * opportunity for bugs\n\n* There is nice [fastapi-jwt-auth](https://github.com/IndominusByte/fastapi-jwt-auth/), but\n  * poorly supported  \n  * not \"FastAPI-style\" (not native functions parameters)\n\n## FastAPI Integration \n\nThere it is open and maintained [Pull Request #3305](https://github.com/tiangolo/fastapi/pull/3305) to the `fastapi` repo. Currently, not considered.\n\n## Requirements \n\n* `fastapi`\n* `authlib` or `python-jose[cryptography]` (deprecated)\n\n## License\nThis project is licensed under the terms of the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk4black%2Ffastapi-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk4black%2Ffastapi-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk4black%2Ffastapi-jwt/lists"}