Authenticates a user with email and password. Returns Cognito access/id/refresh tokens on success, or a NEW_PASSWORD_REQUIRED challenge on first login when an admin has created the account with a temporary password.
Authentication
This is a public endpoint that does not require authentication.
Rate Limiting
This endpoint is rate-limited to 5 requests per minute per IP address.
Request Body
User email address (case-insensitive, will be lowercased automatically)Must be a valid email format.Example: [email protected]
User passwordMust be at least 8 characters long.Example: MyP@ssw0rd!
Request Example
curl -X POST https://api.example.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "MyP@ssw0rd!"
}'
Response
Success Response (200 OK)
The response varies depending on whether this is a first-time login:
Standard Login Success
Cognito JWT access token used for API authenticationPass this token in the Authorization: Bearer <token> header for authenticated requests.
Cognito refresh token used to obtain new access tokensUse this with the /api/auth/refresh-token endpoint when the access token expires.
Token expiration time in secondsTypically 3600 (1 hour).
Indicates whether a password change is requiredWill be false for standard login success.
{
"accessToken": "eyJraWQiOiJxYz...",
"refreshToken": "eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ...",
"expiresIn": 3600,
"requiresPasswordChange": false
}
First-Time Login (Password Change Required)
When an admin creates a user account with a temporary password, the first login returns a challenge:
Set to true to indicate password change is required
Session token for completing the password change challengeMust be provided to the /api/auth/complete-password-change endpoint.
Username (email) of the account
{
"requiresPasswordChange": true,
"session": "AYABeD...",
"username": "[email protected]"
}
Error Responses
Validation error — Invalid email format or password too short{
"statusCode": 400,
"message": ["email must be an email", "password must be longer than or equal to 8 characters"],
"error": "Bad Request"
}
Invalid credentials — Email or password is incorrectThe response is intentionally generic to prevent user enumeration attacks.{
"statusCode": 401,
"message": "Invalid credentials",
"error": "Unauthorized"
}
Rate limit exceeded — More than 5 requests in 1 minute{
"statusCode": 429,
"message": "Too many requests",
"error": "Too Many Requests"
}
Notes
- Email addresses are automatically lowercased and trimmed for consistency
- The endpoint returns generic error messages on authentication failure to prevent user enumeration
- Access tokens are JWTs that expire after 1 hour (3600 seconds)
- Refresh tokens are long-lived and can be used to obtain new access tokens without re-entering credentials
- On first login with a temporary password, you must complete the password change flow using
/api/auth/complete-password-change