Login
Authentication
Login
Authenticate users with AWS Cognito and obtain JWT access tokens
POST
Login
Overview
The login endpoint authenticates users against AWS Cognito User Pool and returns JWT tokens for API access. It uses theADMIN_USER_PASSWORD_AUTH flow with email-based authentication.
Authentication Flow:
- Email and password are sent to AWS Cognito
- Cognito validates credentials
- Returns JWT access token and refresh token
- ID token is decoded to extract user information
- Admin status is determined based on email
Request
Body Parameters
User’s email address (treated as username). The API handles URL decoding and trimming automatically.Example:
user@igad.intUser’s password. Must meet Cognito password requirements:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
Request Example
Response
Success Response (200 OK)
JWT access token for authenticating API requests. Valid for 1 hour (3600 seconds).Format: Bearer token (JWT)
Refresh token for obtaining new access tokens without re-authentication. Valid for 30 days.Note: Only returned on initial login, not on password change required scenarios.
Always returns
"bearer". Use in Authorization header as Bearer {access_token}.User information extracted from Cognito ID token.
Token expiration time in seconds. Default is 3600 (1 hour).
Present when user must change password on first login or admin-forced password reset.If true:
access_tokenwill be emptysessionfield contains session token for password change- Client must call
/api/auth/complete-password-changewith session token
Session token for completing password change challenge. Only present when
requires_password_change is true.Echo of username/email. Present in password change required scenarios.
Human-readable message. Present when
requires_password_change is true.Successful Login Example
Password Change Required Example
Error Responses
401 Unauthorized - Invalid Credentials
Returned when username/password combination is incorrect.NotAuthorizedException
401 Unauthorized - User Not Found
Returned when user does not exist in Cognito User Pool.UserNotFoundException
500 Internal Server Error - Authentication Error
Returned for other Cognito authentication failures.UserNotConfirmedException- Email not verifiedPasswordResetRequiredException- Admin-forced password resetTooManyRequestsException- Rate limit exceeded
500 Internal Server Error - Generic Failure
Returned for unexpected errors.Implementation Details
AWS Cognito Integration
The endpoint uses the following Cognito configuration:- Region:
us-east-1 - Auth Flow:
ADMIN_USER_PASSWORD_AUTH - User Pool ID: From
COGNITO_USER_POOL_IDenvironment variable - Client ID: From
COGNITO_CLIENT_IDenvironment variable
backend/app/tools/auth/routes.py:39
Token Handling
Cognito returns three tokens:- Access Token - Used for API authentication (1 hour expiry)
- ID Token - Contains user claims (decoded for user info)
- Refresh Token - Used to obtain new access tokens (30 days expiry)
sub→user_idemail→emailname→name
Admin Role Assignment
Admin status is determined by checking email against hardcoded list:backend/app/tools/auth/routes.py:97
Admin role assignment is currently hardcoded. Consider moving to Cognito User Groups for production.
Password Change Challenge
When Cognito returnsChallengeName: NEW_PASSWORD_REQUIRED:
- User is in
FORCE_CHANGE_PASSWORDstate (first login or admin reset) - Response includes
sessiontoken - Client must call
/api/auth/complete-password-changewith:usernamesessionnew_password
backend/app/tools/auth/routes.py:67
Usage Example
cURL
JavaScript (Fetch)
Python (Requests)
Related Endpoints
- POST /api/auth/refresh-token - Refresh access token using refresh token
- POST /api/auth/complete-password-change - Complete password change challenge
- GET /api/auth/me - Get current user information
- POST /api/auth/logout - Logout user session
Security Considerations
Token Storage
Recommended: Store in httpOnly secure cookies Alternative: localStorage with XSS protections Avoid: Regular cookies accessible to JavaScriptRate Limiting
Cognito enforces rate limits. HandleTooManyRequestsException with exponential backoff.
Email Handling
The API handles:- URL-encoded emails (
user%40igad.int→user@igad.int) - Leading/trailing whitespace
- Case-insensitive email matching
backend/app/tools/auth/routes.py:44