Skip to content

whoismehfooz/SecureAuth-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” SecureAuth Backend (FastAPI)

A production-style authentication system built with FastAPI, featuring secure password hashing, JWT-based login, and protected routes.


πŸš€ Overview

This project implements a complete authentication flow used in real-world backend systems:

  • User registration with password hashing
  • Secure login with credential validation
  • JWT token generation
  • Token-based protected routes

⚑ Features

  • πŸ” User Signup (hashed passwords)
  • πŸ”‘ Login with JWT token
  • πŸ›‘οΈ Token Verification
  • 🚫 Unauthorized access handling
  • πŸ“¦ Modular architecture (Auth separated cleanly)

🧱 Tech Stack

  • ⚑ FastAPI
  • 🐍 Python
  • πŸ—„οΈ SQLite
  • 🧠 SQLAlchemy ORM
  • πŸ” JWT (python-jose)
  • πŸ”’ Password Hashing

πŸ“‚ Project Structure

src/
β”œβ”€β”€ auth/
β”‚   β”œβ”€β”€ controllers.py
β”‚   β”œβ”€β”€ routers.py
β”‚   β”œβ”€β”€ schemas.py
β”‚   └── utils.py
β”‚
β”œβ”€β”€ users/
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ schemas.py
β”‚   β”œβ”€β”€ controllers.py
β”‚   └── routers.py
β”‚
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ db.py
β”‚   └── settings.py
β”‚
└── main.py

πŸ”₯ API Endpoints

πŸ‘€ Users

  • POST /users/ β†’ Register user

πŸ” Auth

  • POST /auth/login β†’ Login & get token
  • GET /auth/me β†’ Protected route (requires token)

πŸ§ͺ Example Login Response

{
  "access_token": "your.jwt.token",
  "token_type": "bearer"
}

πŸ” How Authentication Works

User β†’ Login β†’ Token Generated
      ↓
Client stores token
      ↓
Client sends token in headers
      ↓
Server verifies token
      ↓
Access granted / denied

βš™οΈ Setup & Run

git clone https://github.com/your-username/secureauth-backend.git
cd secureauth-backend

python -m venv venv
source venv/bin/activate

pip install -r requirements.txt

uvicorn src.main:app --reload

πŸ“š API Docs

Swagger UI:

πŸ‘‰ http://127.0.0.1:8000/docs


🧠 What I Learned

  • Implementing authentication from scratch
  • Secure password handling
  • Token-based authorization flow
  • Dependency-based security in FastAPI
  • Writing modular backend architecture

πŸš€ Future Improvements

  • πŸ” Role-Based Access Control
  • ♻️ Refresh Tokens
  • πŸ—„οΈ PostgreSQL integration
  • 🌍 Deployment

πŸ‘¨β€πŸ’» Author

Building secure backend systems step by step πŸš€

About

πŸ‘‰ JWT-based authentication system with FastAPI including secure login, token verification, and protected routes

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages