A production-style authentication and authorization backend built using FastAPI, featuring secure user authentication, JWT-based access control, and database-backed user management.
This project demonstrates how modern backend systems handle authentication, security, and role-based access using industry-standard practices.
- User registration and login
- Secure password hashing
- JWT-based authentication (access tokens)
- Role-based access control (RBAC)
- Protected routes using dependency injection
- PostgreSQL database integration
- SQLAlchemy ORM for data modeling
- Environment-based configuration
- Automatic API documentation (Swagger / OpenAPI)
- Backend Framework: FastAPI
- Language: Python
- Database: PostgreSQL
- ORM: SQLAlchemy
- Auth: JWT (JSON Web Tokens)
- Security: Password hashing with
passlib - API Docs: Swagger UI (built-in FastAPI)
login-fastapi/
├── app/
│ ├── main.py
│ ├── database.py
│ ├── models.py
│ ├── schemas.py
│ ├── auth.py
│ ├── dependencies.py
│ └── routes/
│ ├── auth.py
│ └── users.py
├── .env
├── requirements.txt
└── README.md
- User registers with email and password
- Password is securely hashed before storage
- User logs in with valid credentials
- Server issues a signed JWT access token
- Client sends token in
Authorizationheader - Protected routes validate token and user role
git clone https://github.com/404zhan/login-fastapi.git
cd login-fastapipython -m venv venv
source venv/bin/activatepip install -r requirements.txtDATABASE_URL=postgresql://username:password@localhost:5432/dbname
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30uvicorn app.main:app --reload- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Azhan Farooqui
GitHub: https://github.com/404zhan