A simple authentication microservice built with Go. It provides a passwordless login flow using One-Time Passwords (OTP) sent via email.
- 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.
- Clone the repository.
- Create a
.envfile in the root directory by copying the example below. - 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"- Install the dependencies:
go mod tidy
- Run the server:
go run ./cmd/server/main.go
The server will start on the port specified by SERVER_PORT, by default :8080.
-
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" }
This project is licensed under the MIT License. See the LICENSE file for details.