Sign inSign up

moootid/auth-service

By moootid

•Updated about 1 year ago

Auth and routing service using Go

Image
0

203

moootid/auth-service repository overview

⁠Auth Service

A high-performance authentication and authorization service built with Go, designed as part of a microservices video processing cluster. This service handles user authentication, JWT token management, and acts as a proxy for video analysis and transcoding operations.

ā šŸš€ Features

  • User Authentication: Registration and login with JWT tokens
  • Password Security: Bcrypt hashing for secure password storage
  • Profile Management: User profile retrieval and updates
  • Video Operations Proxy: Secure access to video analysis and transcoding services
  • Database Integration: PostgreSQL/CockroachDB support with GORM
  • Metrics & Monitoring: Prometheus metrics endpoint
  • CORS Support: Cross-origin resource sharing for web applications
  • Health Checks: Service health monitoring endpoint
  • S3 Integration: Video file download from Amazon S3

ā šŸ—ļø Architecture

This service acts as an authentication gateway for a video processing cluster, providing:

  • Authentication Layer: Secure user management and JWT-based authorization
  • Service Proxy: Routes authenticated requests to video analysis and transcoding services
  • Data Persistence: User profiles and video processing job tracking
  • Security Middleware: Request validation and user context injection

ā šŸ“‹ API Endpoints

⁠Public Endpoints
  • GET /health - Service health check
  • GET /metrics - Prometheus metrics
  • POST /auth/register - User registration
  • POST /auth/login - User login
⁠Protected Endpoints (Require JWT Token)
  • GET /auth/profile - Get user profile
  • PUT /auth/profile - Update user profile
⁠Video Analysis
  • POST /auth/video/analyze - Submit video for analysis
  • GET /auth/video/analyze - List user's video analyses
  • GET /auth/video/analyze/{id} - Get specific analysis details
⁠Video Transcoding
  • POST /auth/video/transcode - Submit video for transcoding
  • GET /auth/video/transcode - List user's transcoding jobs
  • GET /auth/video/transcode/{id} - Get specific transcoding job details
  • GET /auth/video/transcode/{id}/download - Download processed video from S3

ā šŸ› ļø Tech Stack

  • Language: Go 1.24
  • Web Framework: Gorilla Mux
  • Database: PostgreSQL/CockroachDB with GORM
  • Authentication: JWT tokens with golang-jwt/jwt
  • Password Hashing: bcrypt
  • Cloud Storage: AWS S3
  • Monitoring: Prometheus metrics
  • Containerization: Docker

ā šŸš€ Quick Start

⁠Using Docker Hub Image
# Pull the latest image
docker pull moootid/auth-service:latest

# Run with environment variables
docker run -p 8080:8080 \
  -e DB_HOST=your-db-host \
  -e DB_PORT=26257 \
  -e DB_USER=your-db-user \
  -e DB_PASSWORD=your-db-password \
  -e DB_NAME=microservices \
  -e JWT_SECRET=your-secret-key \
  moootid/auth-service:latest
⁠Using Docker Compose
  1. Clone the repository:
git clone https://github.com/moootid/auth-service.git
cd auth-service
  1. Create a .env file with your configuration:
DB_HOST=localhost
DB_PORT=26257
DB_USER=root
DB_PASSWORD=your-password
DB_NAME=microservices
DB_SSLMODE=disable
JWT_SECRET=your-secret-key-here
  1. Run with Docker Compose:
docker-compose up -d
⁠Building from Source
  1. Clone the repository:
git clone https://github.com/moootid/auth-service.git
cd auth-service
  1. Install dependencies:
go mod download
  1. Set environment variables:
export DB_HOST=localhost
export DB_PORT=26257
export DB_USER=root
export DB_PASSWORD=your-password
export DB_NAME=microservices
export JWT_SECRET=your-secret-key
  1. Run the service:
go run main.go

The service will start on port 8080 by default.

ā šŸ”§ Configuration

⁠Environment Variables
VariableDescriptionDefault
PORTService port8080
DB_HOSTDatabase hostlocalhost
DB_PORTDatabase port26257
DB_USERDatabase userroot
DB_PASSWORDDatabase password""
DB_NAMEDatabase namemicroservices
DB_SSLMODEDatabase SSL modedisable
JWT_SECRETJWT signing secretyour-secret-key
⁠Database Setup

The service uses GORM for database operations and supports PostgreSQL/CockroachDB. Ensure your database is running and accessible with the provided credentials.

Required tables will be automatically created by GORM migrations:

  • users - User profiles and authentication data
  • video_analyses - Video analysis job tracking
  • transcoding_jobs - Video transcoding job tracking

ā šŸ“ Usage Examples

⁠Register a New User
curl -X POST http://localhost:8080/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "securepassword"
  }'
⁠Login
curl -X POST http://localhost:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "securepassword"
  }'
⁠Access Protected Endpoint
# Use the JWT token from login response
curl -X GET http://localhost:8080/auth/profile \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
⁠Submit Video for Analysis
curl -X POST http://localhost:8080/auth/video/analyze \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "video_url": "https://example.com/video.mp4",
    "analysis_type": "content_detection"
  }'

ā šŸ” Monitoring

  • Health Check: GET /health - Returns service status
  • Metrics: GET /metrics - Prometheus metrics endpoint

ā šŸ›ļø Project Structure

auth-service/
ā”œā”€ā”€ main.go                 # Application entry point
ā”œā”€ā”€ database/
│   └── db.go              # Database connection and configuration
ā”œā”€ā”€ handlers/
│   ā”œā”€ā”€ auth.go            # Authentication handlers
│   ā”œā”€ā”€ analyze.go         # Video analysis proxy handlers
│   └── transcode.go       # Video transcoding proxy handlers
ā”œā”€ā”€ middleware/
│   ā”œā”€ā”€ auth.go            # JWT authentication middleware
│   └── metrics.go         # Prometheus metrics middleware
ā”œā”€ā”€ models/
│   ā”œā”€ā”€ user.go            # User data models
│   ā”œā”€ā”€ video_analyses.go  # Video analysis models
│   └── transcoding_job.go # Transcoding job models
ā”œā”€ā”€ Dockerfile             # Container configuration
ā”œā”€ā”€ docker-compose.yml     # Multi-container setup
ā”œā”€ā”€ go.mod                 # Go module dependencies
└── go.sum                 # Dependency checksums

ā šŸ“„ License

This project is licensed under the MIT License - see the LICENSE⁠ file for details.

This auth service is part of a larger video processing cluster:

  • Video Analysis Service: Handles video content analysis
  • Video Transcoding Service: Manages video format conversion and processing
  • Storage Service: Manages file uploads and downloads

Docker Hub: moootid/auth-service:latest⁠
GitHub: moootid/auth-service⁠

Tag summary

Content type

Image

Digest

sha256:62f5712d8…

Size

15.2 MB

Last updated

about 1 year ago

docker pull moootid/auth-service