{"id":34097010,"url":"https://github.com/michael7nightingale/fastapi_authtools","last_synced_at":"2026-05-24T23:34:45.969Z","repository":{"id":180322106,"uuid":"664649164","full_name":"michael7nightingale/fastapi_authtools","owner":"michael7nightingale","description":"JWT authentication fot FastAPI framework.","archived":false,"fork":false,"pushed_at":"2023-09-28T03:57:03.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-16T20:33:23.267Z","etag":null,"topics":["fastapi","jwt-authentication","starlette"],"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/michael7nightingale.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-07-10T12:50:38.000Z","updated_at":"2023-08-08T09:41:25.000Z","dependencies_parsed_at":"2023-08-08T11:28:00.614Z","dependency_job_id":null,"html_url":"https://github.com/michael7nightingale/fastapi_authtools","commit_stats":null,"previous_names":["michael7nightingale/fastapi_auth","michael7nightingale/fastapi_authtools"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/michael7nightingale/fastapi_authtools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael7nightingale%2Ffastapi_authtools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael7nightingale%2Ffastapi_authtools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael7nightingale%2Ffastapi_authtools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael7nightingale%2Ffastapi_authtools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael7nightingale","download_url":"https://codeload.github.com/michael7nightingale/fastapi_authtools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael7nightingale%2Ffastapi_authtools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33455024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-24T19:21:36.376Z","status":"ssl_error","status_checked_at":"2026-05-24T19:21:10.562Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","jwt-authentication","starlette"],"created_at":"2025-12-14T15:46:56.139Z","updated_at":"2026-05-24T23:34:45.963Z","avatar_url":"https://github.com/michael7nightingale.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI auth library.\n\nIt`s simple to connect to your project. Just make user_data verification, and library will manage JWT-tokens.\n\n## Installation\nInstall package with pip:\n```commandline\npip install fastapi-authtools\n```\n\n...or with poetry:\n```commandline\npoetry add fastapi-authtools\n```\n\n## Usage\nYou can you it with JWT-token (default in you headers).\n\n```python\nfrom fastapi import FastAPI, Request, Body\n\nfrom fastapi_authtools import AuthManager, login_required\nfrom fastapi_authtools.models import UsernamePasswordToken, UserModel\n\n\napp = FastAPI()\n\n# JWT token settings\nSECRET_KEY = 'secretSERCRET007'\nEXPIRE_MINUTES = 60 * 40\nALGORITHM = \"HS256\"\n\n# create login manager\nauth_manager = AuthManager(\n    app=app,\n    secret_key=SECRET_KEY,\n    algorithm=ALGORITHM,\n    expire_minutes=EXPIRE_MINUTES\n)\n\n# now you can use login_manager directly or py adding it to the application statement\n# it`s comfortable while dealing with APIRouters\napp.state.auth_manager = auth_manager\n\n\n@app.get(\"/\")\n@login_required  # make this endpoint allowed only for authenticated users\nasync def homepage(request: Request):\n    current_user = request.user\n    return {\"current_user\": current_user}\n\n\n@app.post(\"/auth/token\", status_code=201)\nasync def get_access_token(request: Request, user_data: UsernamePasswordToken = Body()):\n    # ... here goes db user verification and getting user information\n    # user = get_login_user(user_data)\n    user = UserModel(\n        email=\"suslanchikmol@gmail.con\",\n        username=\"michael7nightingale\"\n    )\n    token = request.app.state.auth_manager.create_token(user)\n    return {\"access_token\": token}\n\n```\n\nBut you can still use cookies to save token, just define `user_cookies` as True when initialize AuthManager.\n\nTo use templates and form data you should install `jinja2` and `python-multipart`. \n```python\nfrom fastapi import FastAPI, Request\nfrom fastapi.responses import RedirectResponse\nfrom fastapi.templating import Jinja2Templates\n\nfrom fastapi_authtools import AuthManager, login_required\nfrom fastapi_authtools.models import UserModel\n\n\napp = FastAPI()\ntemplates = Jinja2Templates(directory=\"templates\")\n\n# JWT token settings\nSECRET_KEY = 'secretSERCRET007'\nEXPIRE_MINUTES = 60 * 40\nALGORITHM = \"HS256\"\n\n# create login manager\nauth_manager = AuthManager(\n    app=app,\n    use_cookies=True,\n    secret_key=SECRET_KEY,\n    algorithm=ALGORITHM,\n    expire_minutes=EXPIRE_MINUTES\n)\n\n# now you can use login_manager directly or py adding it to the application statement\n# it`s comfortable while dealing with APIRouters\napp.state.auth_manager = auth_manager\n\n\n@app.get(\"/\")\n@login_required  # make this endpoint allowed only for authenticated users\nasync def homepage(request: Request):\n    return templates.TemplateResponse(\n        name=\"homepage.html\",\n        context={\"request\": request, \"current_user\": request.user}\n    )\n\n\n@app.get('/login')\nasync def login_get(request: Request):\n    return templates.TemplateResponse(\n        name='login.html',\n        context={\"request\": request}\n    )\n\n\n@app.post(\"/login\", status_code=201)\nasync def login_post(request: Request):\n    user_data = await request.form()\n    # ... here goes db user verification and getting user information\n    # user = get_login_user(user_data)\n    user = UserModel(\n        email=\"suslanchikmol@gmail.con\",\n        username=\"michael7nightingale\"\n    )\n    response = RedirectResponse(app.url_path_for(\"homepage\"), status_code=303)\n    app.state.auth_manager.login(response, user)\n    return response\n```\n\n\nAuth manager adds authentication middleware to your application instance and uses authentication backends to treat token and\nrequest user instance. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael7nightingale%2Ffastapi_authtools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael7nightingale%2Ffastapi_authtools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael7nightingale%2Ffastapi_authtools/lists"}