A simple, from scratch implementation of token-based authentication using FastAPI.
Note: Endpoints requiring refresh tokens only work on localhost because Secure cookies demand HTTPS. To enable HTTPS elsewhere, configure Traefik with Docker Compose as a proxy.
Use the .env template provided and replace the values
- Build and start the container:
The application will start at
docker-compose up --build
http://localhost:8000. Database migrations will run automatically on startup.
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # or .venv\Scripts\Activate.ps1 on Windows
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
alembic upgrade head
-
Start FastAPI:
fastapi dev app/main.py
Head to the /docs endpoint for FastAPI's autogenerated documentation!