{"id":17658825,"url":"https://github.com/volfpeter/fastapi-flask-auth","last_synced_at":"2026-04-10T16:37:32.650Z","repository":{"id":138825479,"uuid":"579016409","full_name":"volfpeter/fastapi-flask-auth","owner":"volfpeter","description":"Lightweight FastAPI dependencies and authenticator that uses Flask session cookies for access control","archived":false,"fork":false,"pushed_at":"2023-05-27T14:36:10.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T10:31:21.251Z","etag":null,"topics":["cookie","fastapi","flask","python"],"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/volfpeter.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}},"created_at":"2022-12-16T12:58:53.000Z","updated_at":"2024-03-19T03:14:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"f52f8540-83a0-4f4e-8a6b-2eff37d67758","html_url":"https://github.com/volfpeter/fastapi-flask-auth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/volfpeter/fastapi-flask-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volfpeter%2Ffastapi-flask-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volfpeter%2Ffastapi-flask-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volfpeter%2Ffastapi-flask-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volfpeter%2Ffastapi-flask-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/volfpeter","download_url":"https://codeload.github.com/volfpeter/fastapi-flask-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volfpeter%2Ffastapi-flask-auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259810798,"owners_count":22915132,"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":["cookie","fastapi","flask","python"],"created_at":"2024-10-23T15:43:24.494Z","updated_at":"2026-04-10T16:37:32.616Z","avatar_url":"https://github.com/volfpeter.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi-flask-auth\n\nLightweight FastAPI dependencies and authenticator that uses Flask session cookies for access control.\n\nWhy would you want to base your FastAPI application's authentication on session cookies created by a Flask application?\n\nWell, imagine that you have a Flask application that handles authentication (probably with `flask-login`) among other tasks and you'd like to use FastAPI for some new routes, or maybe you just want to offload some work from Flask to FastAPI for convenience or performance reasons. In such a scenario, you probably don't want the client to authenticate at both server applications. What you can do instead is put both server applications behind a reverse proxy, let Flask handle authentication and do its job as before, and use Flask's session cookies for authentication in your FastAPI application with this library.\n\n## Installation \u0026 Usage\n\nYou can install the library from PyPI with `pip install fastapi-flask-auth`.\n\nYou will also need to install a Flask session decoder. If you're looking for a lightweight, zero-dependency decoder, give `flask-session-decoder` (see [here](https://github.com/volfpeter/flask-session-decoder)) a try. You can do this manually with `pip install flask-session-decoder` or you can install `fastapi-flask-auth` together with its default decoder dependency simply with `pip install fastapi-flask-auth[decoder]`.\n\nWith both `fastapi-flask-auth` and `flask-session-decoder` in place, you can set up the authenticator for your FastAPI application like this:\n\n```python\nfrom fastapi_flask_auth import FlaskSessionAuthenticator\nfrom flask_session_decoder import FlaskSessionDecoder\n\ndecoder = FlaskSessionDecoder(secret_key=\"the-secret-key-of-the-flask-app-that-created-the-cookie\")\nflask_auth = FlaskSessionAuthenticator(decoder=decoder)\n```\n\nThen, you can use the authenticator's FastAPI dependencies in your routes like this:\n\n```python\nfrom fastapi import Depends, FastAPI\n\napp = FastAPI()\n\n@app.get(\"/get-session-cookie\")\ndef get_session_cookie(cookie: dict | None = Depends(flask_auth.get_session_cookie)):\n    ...\n\n@app.get(\"/requires-session-cookie\")\ndef requires_session_cookie(cookie: dict = Depends(flask_auth.requires_session_cookie)):\n    ...\n\n@app.get(\"/get-user-id\")\ndef get_user_id(user_id: str | None = Depends(flask_auth.get_user_id)):\n    ...\n\n@app.get(\"/requires-session-cookie\")\ndef requires_user_id(user_id: str = Depends(flask_auth.requires_user_id)):\n    ...\n```\n\n## Dependencies\n\nThe only dependency of this library is `FastAPI`.\n\nThe default decoder dependency is `flask-session-decoder`, which has no further dependencies.\n\n## Development\n\nUse `black` for code formatting and `mypy` for static code analysis.\n\n## License - MIT\n\nThe library is open-sourced under the conditions of the MIT [license](https://choosealicense.com/licenses/mit/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolfpeter%2Ffastapi-flask-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvolfpeter%2Ffastapi-flask-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolfpeter%2Ffastapi-flask-auth/lists"}