{"id":22547469,"url":"https://github.com/matsjfunke/fastapi-traefik-auth","last_synced_at":"2026-04-16T12:38:37.405Z","repository":{"id":233290274,"uuid":"786446446","full_name":"matsjfunke/fastapi-traefik-auth","owner":"matsjfunke","description":"straightforward template/example for user authentication with JSON Web Tokens using FastAPI, Jinja2 templates and Traefik to enable HTTPS encryption","archived":false,"fork":false,"pushed_at":"2024-12-23T20:55:56.000Z","size":54,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T09:41:28.328Z","etag":null,"topics":["authentication","cookies","docker-compose","fastapi","jinja2-templates","jose-jwt","passlib","pydantic","sqlite","traefik"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matsjfunke.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":"2024-04-14T13:46:56.000Z","updated_at":"2024-06-19T10:07:44.000Z","dependencies_parsed_at":"2024-06-19T19:19:25.205Z","dependency_job_id":"78f49f18-f911-4257-97f5-972dc357c0a5","html_url":"https://github.com/matsjfunke/fastapi-traefik-auth","commit_stats":null,"previous_names":["matsjfunke/fastapi-traefik-auth"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsjfunke%2Ffastapi-traefik-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsjfunke%2Ffastapi-traefik-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsjfunke%2Ffastapi-traefik-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsjfunke%2Ffastapi-traefik-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsjfunke","download_url":"https://codeload.github.com/matsjfunke/fastapi-traefik-auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245999595,"owners_count":20707568,"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":["authentication","cookies","docker-compose","fastapi","jinja2-templates","jose-jwt","passlib","pydantic","sqlite","traefik"],"created_at":"2024-12-07T15:11:58.653Z","updated_at":"2026-04-16T12:38:37.372Z","avatar_url":"https://github.com/matsjfunke.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi-login-traefik\n![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge\u0026logo=fastapi)\n![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge\u0026logo=python\u0026logoColor=ffdd54)\n![JWT](https://img.shields.io/badge/JWT-black?style=for-the-badge\u0026logo=JSON%20web%20tokens)\n\nis a simple example / template for authentication\n1. [auth-with-frontend](auth-with-frontend) uses Jinja2 templates to serve HTML to the client.\n2. [stand-alone-backend](stand-alone-backend) uses CORS to allow cross-origin requests, enabling the backend to communicate with frontend applications hosted on different domains.\n\n## Technology Stack and Features\n- ⚡ [FastAPI](https://fastapi.tiangolo.com) for building APIs with Python 3.7+.\n- 📞 [Traefik](https://traefik.io) as reverse proxy and load balancer, providing automatic HTTPS encryption and certificate management.\n- 🥷 [Jinja2Templates](https://fastapi.tiangolo.com/advanced/templates/) for rendering dynamic HTML content, making it easy to create user interfaces.\n- 🍪 [python-jose](https://python-jose.readthedocs.io/en/latest/) for secure user authentication using JSON Web Tokens (JWT), ensuring that only authenticated users can access protected routes.\n- 🔒 [passlib](https://pypi.org/project/passlib/) for secure password hashing and verification.\n- 🗃️ [SQLite Database](https://www.sqlite.org/) for storing usernames and hashed passwords.\n- 🛠️ [SQLAlchemy](https://www.sqlalchemy.org/) as an ORM for working with the database.\n- 🛡️ [Pydantic](https://docs.pydantic.dev) for data validation.\n- 🐋 [Docker Compose](https://www.docker.com) to deploy and manage your application, allowing for containerization and orchestration of your services.\n\n## Quick start / Usage\n\n#### 1. run local without reverse-proxy\n- cloe repo\n```bash\ngit clone https://github.com/matsjfunke/fastapi-login-traefik.git\n```\n- start container\n```bash\ncd auth-with-frontend\ndocker-compose -f docker-compose.yml up --build\n```\n- than access the localhost:8000 and submit username and password, then enter your credentials at localhost:8000/login \n- now with the cookies you obtained through logging in you can access the /hello and /users endpoints\n- at /hello you can delete your username, password \u0026 cookies or update your username \n \n\n#### 2. run on server\n- clone repo\n- change line 34 of docker.compose.staging.yml\n    - \"traefik.http.routers.db-access.rule=Host(`your-domain.com`)\" # change `your-domain.com` to your domain\n- start docker \n```bash\ngit clone https://github.com/matsjfunke/fastapi-login-traefik.git\ncd auth-with-frontend\ndocker-compose -f docker-compose.staging.yml up\n```\n- than access the `your-domain.com` and submit username and password, then enter your credentials at `your-domain.com/login` \n- now with the cookies you obtained through logging in you can access the /hello and /users endpoints\n- at /hello you can delete your username, password \u0026 cookies or update your username\n\n## Test the Code\ntest all CRUD functions in this order\n1. install dependency’s\n```bash\ncd auth-with-frontend\npython3 -m venv env\nsource env/bin/activate\npip install -r tests/requirements.txt\n```\n2. test if user credentials get saved to db\n```bash\npython tests/signup_test.py\n```\n3. test authentication with the prior created username \u0026 password\n```bash\npython tests/login_test.py\n```\n4. test update_username function\n```bash\npython tests/update_name_test.py\n``` \n5. test deletion function\n```bash\npython test/deletion_test.py\n```\n\n## API example without frontend stuff\ncheck /stand-alone-frontend\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsjfunke%2Ffastapi-traefik-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsjfunke%2Ffastapi-traefik-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsjfunke%2Ffastapi-traefik-auth/lists"}