Skip to content

Repository files navigation

Auth Service 🔐

A centralized JWT authentication service built with FastAPI. It can be used as a standalone auth backend for multiple projects or dashboards. The JWT validator module is reusable, so other projects can import it to protect their own endpoints.

✨ Features

  • JWT Authentication — Access tokens (short-lived) and refresh tokens (long-lived)
  • Secure Password Hashing — Uses Argon2, a modern and strong hashing algorithm
  • Refresh Token Rotation — A new refresh token is issued on every refresh
  • HttpOnly Cookies — Refresh tokens are stored in secure, httpOnly cookies to protect against XSS
  • Rate Limiting — Login endpoint is protected against brute-force attacks (5 requests/minute)
  • Reusable Validatorshared_auth module can be imported by other projects
  • Docker Ready — Comes with Dockerfile and Docker Compose setup

🛠️ Tech Stack

  • FastAPI — Web framework
  • SQLAlchemy — Database ORM
  • Argon2 — Password hashing
  • python-jose — JWT handling
  • SlowAPI — Rate limiting
  • Pydantic Settings — Configuration management

📡 API Endpoints

Method Endpoint Description
POST /api/v1/auth/login Log in and get an access token
POST /api/v1/auth/refresh Get a new access token
POST /api/v1/auth/logout Log out and clear the cookie
GET /api/v1/auth/me Get the current user info
GET /health Health check

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • Docker (optional)

Installation

  1. Clone the repository:

    git clone https://github.com/InanColak/auth-service.git
    cd auth-service
  2. Install dependencies:

    pip install -r requirements.txt
  3. Create a .env file (see .env.example) and set your JWT_SECRET.

  4. Run the service:

    uvicorn app.main:app --reload

Create a User

python scripts/create_user.py --email admin@example.com --password yourpassword

Run with Docker

docker compose up --build

⚙️ Configuration

Set these environment variables (see .env.example):

  • JWT_SECRET — Secret key for signing tokens (required)
  • JWT_ALGORITHM — Default: HS256
  • ACCESS_TOKEN_EXPIRE_MINUTES — Default: 15
  • REFRESH_TOKEN_EXPIRE_DAYS — Default: 7
  • DATABASE_URL — Default: sqlite:///./data/auth.db

📄 License

This project is licensed under the MIT License.

About

Centralized JWT authentication service for multi-project dashboard access

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages