Skip to main content

Auth Service โ€“ API Reference ๐Ÿ”

This document describes the public authentication APIs exposed by the Auth Service in ShopVerse.

All authentication APIs are accessed via the API Gateway.


๐ŸŒ Base URLโ€‹


/api/auth


๐Ÿ” Authentication Overviewโ€‹

  • Auth Service issues JWT tokens
  • JWT is validated at the API Gateway
  • Downstream services rely on trusted headers
  • Tokens follow a stateless authentication model

๐Ÿ“Œ Register Userโ€‹

Create a new user account.

โžค Endpointโ€‹


POST /api/auth/register

โžค Request Bodyโ€‹

{
"fullName": "John Doe",
"email": "john@example.com",
"phoneNo": "9876543210",
"password": "StrongPassword123"
}

โžค Success Response (201 CREATED)โ€‹

{
"message": "User registered successfully"
}

โžค Error Responsesโ€‹

StatusReason
400Invalid input
409Email already exists
500Internal server error

๐Ÿ”‘ Login Userโ€‹

Authenticate user and issue JWT token.

โžค Endpointโ€‹

POST /api/auth/login

โžค Request Bodyโ€‹

{
"email": "john@example.com",
"password": "StrongPassword123"
}

โžค Success Response (200 OK)โ€‹

{
"token": "eyJhbGciOiJIUzUxMiJ9...",
"type": "Bearer"
}

โžค Error Responsesโ€‹

StatusReason
401Invalid credentials
404User not found
500Internal server error

๐Ÿงพ JWT Token Detailsโ€‹

Token Formatโ€‹

Authorization: Bearer <JWT_TOKEN>

JWT Claimsโ€‹

{
"sub": "john@example.com",
"role": "CUSTOMER",
"name": "John Doe",
"iat": 1710000000,
"exp": 1710003600
}
ClaimDescription
subUser email (identity)
roleUser role
expToken expiration

๐Ÿ”„ Authentication Flow Summaryโ€‹


๐Ÿ“ก Events Publishedโ€‹

EventTopicDescription
USER_REGISTEREDauth-eventsNew user registration
USER_LOGINauth-eventsUser login activity

These events are consumed by:

  • Notification Service
  • Analytics Service

๐Ÿ›ก๏ธ Security Notesโ€‹

  • Passwords are never stored or logged in plain text
  • BCrypt is used for password hashing
  • JWT uses HS512 signing
  • Token expiration is enforced
  • Auth APIs are rate-limit ready

โš ๏ธ Common Issuesโ€‹

โŒ Invalid Tokenโ€‹

  • Token expired or tampered
  • Re-login required

โŒ Multiple Login Attemptsโ€‹

  • Invalid credentials return generic error
  • Prevents user enumeration

๐Ÿ“Œ Summaryโ€‹

The Auth API provides:

  • Secure user authentication
  • Stateless JWT-based authorization
  • Clean integration with API Gateway
  • Event-driven extensibility

It serves as the entry point for security in ShopVerse.