is a simple example / template for authentication
- auth-with-frontend uses Jinja2 templates to serve HTML to the client.
- stand-alone-backend uses CORS to allow cross-origin requests, enabling the backend to communicate with frontend applications hosted on different domains.
- ⚡ FastAPI for building APIs with Python 3.7+.
- 📞 Traefik as reverse proxy and load balancer, providing automatic HTTPS encryption and certificate management.
- 🥷 Jinja2Templates for rendering dynamic HTML content, making it easy to create user interfaces.
- 🍪 python-jose for secure user authentication using JSON Web Tokens (JWT), ensuring that only authenticated users can access protected routes.
- 🔒 passlib for secure password hashing and verification.
- 🗃️ SQLite Database for storing usernames and hashed passwords.
- 🛠️ SQLAlchemy as an ORM for working with the database.
- 🛡️ Pydantic for data validation.
- 🐋 Docker Compose to deploy and manage your application, allowing for containerization and orchestration of your services.
- cloe repo
git clone https://github.com/matsjfunke/fastapi-login-traefik.git
- start container
cd auth-with-frontend
docker-compose -f docker-compose.yml up --build
- than access the localhost:8000 and submit username and password, then enter your credentials at localhost:8000/login
- now with the cookies you obtained through logging in you can access the /hello and /users endpoints
- at /hello you can delete your username, password & cookies or update your username
- clone repo
- change line 34 of docker.compose.staging.yml
- "traefik.http.routers.db-access.rule=Host(
your-domain.com
)" # changeyour-domain.com
to your domain
- "traefik.http.routers.db-access.rule=Host(
- start docker
git clone https://github.com/matsjfunke/fastapi-login-traefik.git
cd auth-with-frontend
docker-compose -f docker-compose.staging.yml up
- than access the
your-domain.com
and submit username and password, then enter your credentials atyour-domain.com/login
- now with the cookies you obtained through logging in you can access the /hello and /users endpoints
- at /hello you can delete your username, password & cookies or update your username
test all CRUD functions in this order
- install dependency’s
cd auth-with-frontend
python3 -m venv env
source env/bin/activate
pip install -r tests/requirements.txt
- test if user credentials get saved to db
python tests/signup_test.py
- test authentication with the prior created username & password
python tests/login_test.py
- test update_username function
python tests/update_name_test.py
- test deletion function
python test/deletion_test.py
check /stand-alone-frontend