Skip to content

Sahith-03/fastapi-auth-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here’s a clean and professional README.md for your FastAPI Auth Service repository:


🔐 FastAPI Auth Service

A lightweight and secure authentication microservice built with FastAPI, PostgreSQL, and Docker. It provides essential authentication and authorization functionalities such as user registration, login, and JWT-based token management.


🚀 Features

  • 🔑 User Authentication — Secure login and registration with hashed passwords.
  • 🛡️ JWT Tokens — Access and refresh token management for user sessions.
  • 👥 Role-Based Access — Manage user roles and permissions (optional).
  • 🧱 Database Integration — PostgreSQL with SQLAlchemy ORM and Alembic migrations.
  • 🐳 Dockerized Setup — Easy deployment with Docker and docker-compose.
  • 🧪 Scalable Structure — Modular, extensible, and production-ready architecture.

📁 Project Structure

fastapi-auth-service/
│
├── app/
│   ├── api/              # Route handlers
│   ├── core/             # Configs and JWT utilities
│   ├── db/               # Database models and session setup
│   ├── schemas/          # Pydantic models
│   ├── services/         # Authentication and user logic
│   └── main.py           # FastAPI entry point
│
├── alembic/              # Database migrations
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── README.md

⚙️ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/Sahith-03/fastapi-auth-service.git
cd fastapi-auth-service

2️⃣ Configure environment variables

Create a .env file:

DATABASE_URL=postgresql://postgres:password@db:5432/auth_db
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

3️⃣ Run with Docker

docker-compose up --build

4️⃣ Access the API

Open your browser or API client:

http://localhost:8000/docs

🧠 API Endpoints

Method Endpoint Description
POST /register Register a new user
POST /login Authenticate and get token
GET /users/me Get current user profile
POST /refresh Refresh access token

🧩 Tech Stack

  • Backend: FastAPI
  • Database: PostgreSQL
  • ORM: SQLAlchemy + Alembic
  • Auth: JWT (PyJWT / jose)
  • Containerization: Docker, docker-compose

🧑‍💻 Development

Run locally without Docker:

pip install -r requirements.txt
alembic upgrade head
uvicorn app.main:app --reload

About

A lightweight and secure authentication microservice. It provides essential authentication and authorization functionalities such as user registration, login, and JWT-based token management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors