Skip to content

A robust session-based authentication system built with Go, featuring Redis for session management and PostgreSQL for persistent data storage.

Notifications You must be signed in to change notification settings

Krish-Depani/auth-session-manager

Repository files navigation

Auth Session Manager

A robust session-based authentication system built with Go, featuring Redis for session management and PostgreSQL for persistent data storage.

Links

Features

  • Secure user authentication with session management
  • Dual database system: PostgreSQL (persistent data) + Redis (session storage)
  • Session tracking with device info and location
  • Protection against brute force attacks
  • Active session management and monitoring
  • Automatic session expiration
  • Secure password handling with bcrypt

Security Features

  1. Session Management

    • Session tokens stored in Redis with TTL
    • Device and location tracking for each session
    • Active session monitoring
  2. Brute Force Protection

    • Maximum login attempt limits
    • Cool-down period after failed attempts
    • Automatic account protection
  3. Secure Authentication

    • Bcrypt password hashing
    • HTTP-only cookies for session tokens
    • Transaction-based operations for data consistency

Prerequisites

  • Go 1.x
  • PostgreSQL
  • Redis
  • GNU Make (for using Makefile commands)

Installation

  1. Clone the repository:
git clone https://github.com/Krish-Depani/auth-session-manager.git
cd auth-session-manager
  1. Install dependencies:
go mod download
  1. Rename the .env.example file to .env and update the following environment variables as needed

  2. Set up the databases:

    • Create PostgreSQL database
    • Start Redis server
    • Run migrations:
make migrate-up

Running the Application

Development Mode

make start-dev

Production Mode

make start-prod

API Routes

Authentication Endpoints

  • POST /auth/register - Register a new user
  • POST /auth/login - User login
  • POST /auth/logout - User logout (requires authentication)

User Endpoints

  • GET /auth/user/me - Get current user details (requires authentication)
  • GET /auth/user/sessions - Get active sessions (requires authentication)

Database Management

Creating New Migrations

make migrate-create name=migration_name

Migration Commands

  • Up: make migrate-up
  • Down: make migrate-down n=1
  • Status: make migrate-status
  • Force Version: make migrate-force version=1

Project Structure

├── bin/                  # Compiled binary
├── config/              # Configuration files
├── controllers/         # Request handlers
├── database/           # Database connections and migrations
├── models/             # Data models
├── routes/             # API route definitions
├── utils/              # Utility functions
└── validators/         # Request validation

If you like this project, please give it a 🌟.

Thank you 😊.

About

A robust session-based authentication system built with Go, featuring Redis for session management and PostgreSQL for persistent data storage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published