Skip to content

Learn how to: ✅ Register a user ✅ Login and generate a token ✅ Protect routes with authentication

Notifications You must be signed in to change notification settings

chandrakantapanda/FastAPI-Login-Token-Authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 FastAPI Login + Token Authentication

This project demonstrates how to build a secure login system in FastAPI using JWT (JSON Web Tokens) for authentication.

It’s the same project shown in my YouTube Short — Build Login + Token Auth with FastAPI 🚀 (Watch the full demo there!)


⚡ Features

✅ Register a new user (/auth/register)
✅ Login and get an access token (/auth/login)
✅ Verify the current user (/auth/me)
✅ Password hashing using Passlib
✅ JWT token creation & verification with python-jose
✅ Clean project structure with routers, schemas, and models


🗂️ Project Structure

fastapi-login-jwt/
│
├── main.py
├── auth.py
├── models.py
├── schemas.py
├── utils.py
├── database.py
└── requirements.txt

🚀 Quick Start

1️⃣ Clone the Repository

git clone https://github.com/your-username/fastapi-login-jwt.git
cd fastapi-login-jwt

2️⃣ Install Dependencies

pip install -r requirements.txt

Or install manually:

pip install fastapi uvicorn sqlalchemy pymysql python-jose[cryptography] passlib[bcrypt] python-multipart "pydantic[email]"

3️⃣ Run the App

uvicorn main:app --reload

Open your browser or Postman:
👉 http://127.0.0.1:8000/docs


🔑 API Endpoints

1. Register User

POST /auth/register

{
  "email": "[email protected]",
  "password": "password123"
}

2. Login User

POST /auth/login

{
  "email": "[email protected]",
  "password": "password123"
}

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6...",
  "token_type": "bearer"
}

3. Get Current User

GET /auth/me
Header → Authorization: Bearer <your_token>


🧰 Tech Stack

  • FastAPI — Web framework
  • SQLAlchemy — ORM for DB
  • Passlib — Password hashing
  • python-jose — JWT token handling
  • Uvicorn — ASGI server

📹 YouTube Tutorial

🎥 Watch the full Shorts video here:
👉 Build Login + Token Auth with FastAPI


👨‍💻 Author

Programmer Chandra
🔗 YouTube Channel


⭐ If you find this helpful, star the repo and share it with your dev friends!

About

Learn how to: ✅ Register a user ✅ Login and generate a token ✅ Protect routes with authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages