Authorization Overview
The ESFA Backend API uses Bearer token authentication to secure all endpoints. This document explains how authentication and authorization work within the API ecosystem.
Authentication Architecture
The ESFA system uses a two-service authentication architecture:
Authentication Service: Issues Bearer tokens (separate service)
Backend API: Validates tokens and processes requests
Authorization Header Format
All protected Backend API requests must include the Authorization header:
Example:
Token Characteristics
Token Format
Type: JWT (JSON Web Token)
Algorithm: As specified by the Authentication Service
Encoding: Base64-encoded JWT format
Token Lifecycle
Lifetime: Short-lived (typically minutes to hours)
Refresh: Obtain new tokens when expired
Scope: Valid for all Backend API endpoints
Token Claims
Tokens contain claims that identify:
Client application
Expiration time
Issued at time
Token issuer
Security Requirements
Transmission Security
HTTPS Only: Always use HTTPS in production
Header Security: Never log or expose tokens
Storage: Store tokens securely (memory preferred over disk)
Token Handling
Validation: Backend validates every token on each request
Expiration: Tokens expire automatically for security
Revocation: Tokens cannot be revoked once issued (rely on expiration)
Authentication Flow
1. Initial Authentication
Response:
2. API Request with Token
3. Token Refresh (when expired)
Response Codes
Authentication Success
200 OK: Request processed successfully with valid token
Authentication Failures
401 Unauthorized
The request lacks valid authentication credentials.
Common causes:
Missing Authorization header
Invalid token format
Expired token
Invalid/corrupted token
Example Response:
Solutions:
Verify Authorization header is present
Check token format (must be
Bearer <token>)Obtain fresh token if expired
Validate token is not corrupted
403 Forbidden
Valid authentication but insufficient permissions (if applicable).
Best Practices
Token Management
Error Handling
Security Guidelines
Do's
✅ Always use HTTPS in production
✅ Store tokens in memory when possible
✅ Implement automatic token refresh
✅ Handle 401 errors gracefully
✅ Validate token expiration before requests
Don'ts
❌ Log or expose Bearer tokens
❌ Store tokens in client-side storage (browsers)
❌ Use HTTP for token transmission
❌ Hardcode tokens in source code
❌ Ignore token expiration
Troubleshooting
Common Issues
Issue: "Invalid or missing authentication token"
Cause: Missing or malformed Authorization header
Solution: Verify header format:
Authorization: Bearer <token>
Issue: Token expires frequently
Cause: Short token lifetime
Solution: Implement proactive token refresh before expiration
Issue: Authentication works in development but fails in production
Cause: HTTP vs HTTPS configuration
Solution: Ensure all production traffic uses HTTPS
Debugging Tips
Check Token Format: Ensure JWT structure (header.payload.signature)
Verify Expiration: Check token expiration claim
Network Inspection: Use browser dev tools or network monitoring
Service Status: Verify Authentication Service availability
Related Documentation
Authentication Machine Token: Detailed token request process
Usage Flow: Complete API workflow with examples
Error Handling: Comprehensive error response guide
Troubleshooting: Common issues and solutions