Auth Service
Purpose
auth-service owns authentication data, password hashing, JWT issuance, refresh-token-backed sessions, and logout flows.
Responsibilities
- Register users
- Authenticate credentials
- Issue JWT access tokens
- Create and rotate refresh-token sessions
- Revoke a single session or all sessions
- Call
user-serviceto create the profile record after registration
Dependencies
- Port:
8081 - Database:
bookstore_auth_db - Downstream HTTP:
user-service - Security: Spring Security + JWT
REST APIs
| Method | Path | Auth | Description |
|---|---|---|---|
POST | /auth/register | No | Create auth user and user profile |
POST | /auth/login | No | Authenticate and issue tokens |
POST | /auth/logout | No body auth, refresh token required | Revoke one refresh token |
POST | /auth/logout-all | Yes | Revoke all sessions for current user |
POST | /auth/refresh | No | Rotate refresh token and issue a new access token |
Key DTOs
RegisterRequestDto: email, password, firstName, lastName, phoneNumber, dateOfBirth, addressRegisterResponseDto: userId, email, messageLoginRequestDto: email, password, deviceIdLoginResponseDto: accessToken, refreshToken, expiresInRefreshTokenRequestDto: refreshToken
Database tables
auth_users
user_idemailroleactivepasswordcreated_atupdated_at
refresh_tokens
session_iduser_idtoken(stored hash)device_iddevice_namecreated_atlast_used_atexpires_atrevoked_at
Indexes exist on:
user_iddevice_idtoken(unique)
Entity relationships
Security
Public routes in SecurityConfig:
/auth/login/auth/register/auth/refresh/auth/logout
Authenticated route:
/auth/logout-all
Passwords are encoded with BCryptPasswordEncoder.
Internal flow
Error handling
- Duplicate email ->
DuplicateResourceException - Unknown user during login/refresh ->
ResourceNotFoundException - Invalid or revoked refresh token -> refresh flow fails