Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

piodrs/auth-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth Microservice

A simple authentication microservice built with Go. It provides a passwordless login flow using One-Time Passwords (OTP) sent via email.

Features

  • Passwordless, email-based authentication.
  • OTP generation and verification.
  • Email delivery using SendGrid.
  • OTP storage using Redis.
  • User persistence with PostgreSQL.
  • JWT for session management.
  • IP-based rate limiting for OTP requests.

Configuration

  1. Clone the repository.
  2. Create a .env file in the root directory by copying the example below.
  3. Fill in the required environment variables.
# .env file
SENDGRID_API_KEY="your_sendgrid_api_key"
SENDER_EMAIL="your_sender_email@example.com"
JWT_SECRET_KEY="a_very_secret_key"
DATABASE_URL="postgres://user:password@localhost:5432/auth_service?sslmode=disable"
REDIS_ADDR="localhost:6379"
REDIS_PASSWORD=""
SERVER_PORT="8080"

Running the Application

  1. Install the dependencies:
    go mod tidy
  2. Run the server:
    go run ./cmd/server/main.go

The server will start on the port specified by SERVER_PORT, by default :8080.

API Endpoints

  • POST /auth/request-code

    • Sends an OTP to the provided email address.
    • Body: { "email": "user@example.com" }
  • POST /auth/verify-code

    • Verifies the OTP and, if successful, returns a session cookie.
    • Body: { "email": "user@example.com", "code": "123456" }

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A simple authentication microservice built with Go. It provides a passwordless login flow using One-Time Passwords (OTP) sent via email.

Topics

Resources

License

Stars

Watchers

Forks

Contributors