Authentication API¶
User registration, login, and token management endpoints.
Endpoints¶
Register New User¶
Create a new customer account.
Endpoint: POST /api/v1/customers/register
Authentication: None required
Request Body:
Validation: - Email: Must be valid email format, unique - Username: 6-12 characters, unique - Password: Min 8 chars, must contain uppercase, lowercase, number
Success Response (201):
Error Responses:
400 Bad Request:
Example cURL:
curl -X POST http://localhost:8080/api/v1/customers/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"username": "myuser",
"password": "SecurePass123"
}'
Login¶
Authenticate and receive JWT token.
Endpoint: POST /api/v1/customers/login
Authentication: None required
Request Body:
Success Response (200):
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIiwiZXhwIjoxNjQyNjg0ODAwfQ.signature",
"token_type": "bearer"
}
Error Responses:
401 Unauthorized:
Example cURL:
curl -X POST http://localhost:8080/api/v1/customers/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123"
}'
Token Usage:
Store the access_token and include in subsequent requests:
Token Expiration: 30 minutes
Security¶
Password Hashing¶
- Algorithm: bcrypt
- Automatic salting
- Stored hashed, never plain text
JWT Tokens¶
- Algorithm: HS256
- Secret key from environment
- 30-minute expiration
- No refresh tokens (yet)