Overview
The Football Kit Archive API supports optional API key authentication. By default, authentication is disabled, making all endpoints publicly accessible. You can enable authentication for production deployments or to restrict access.Enabling Authentication
API key authentication is controlled by theDJANGO_API_ENABLE_AUTH environment variable.
Configuration
Set the environment variable to enable authentication:Truetrue1yes
Code Reference
Fromfkapi/api.py:89:
Using API Keys
When authentication is enabled, you must include your API key in the request header.Header Format
Example Request
Python Example
JavaScript Example
Creating API Keys
API keys are managed through the Django admin interface or Django Ninja API Key package.Using Django Admin
- Start your Django server
- Navigate to the admin interface:
http://localhost:8000/admin/ - Log in with superuser credentials
- Go to the API Keys section
- Click Add API Key
- Enter a name and save
- Copy the generated API key (it won’t be shown again)
Using Django Shell
Public Endpoints
Some endpoints remain public even when authentication is enabled:Health Check
The health check endpoint is always public:fkapi/api.py:271:
Authentication Errors
Missing API Key
When authentication is enabled and no API key is provided: Status Code:401 Unauthorized
Response:
Invalid API Key
When an invalid or expired API key is provided: Status Code:401 Unauthorized
Response:
Example with Error
Best Practices
Security Recommendations
- Rotate Keys Regularly: Create new API keys periodically and revoke old ones
- Use Environment Variables: Store API keys in environment variables, not in code
- Limit Scope: Create separate API keys for different applications or environments
- Monitor Usage: Track API key usage through logs and metrics
- HTTPS Only: Always use HTTPS in production to prevent key interception
Environment Variables
Testing Authentication
Verify Authentication is Disabled
Verify Authentication is Enabled
Related Documentation
Rate Limiting
Learn about API rate limits and quotas
Error Handling
Understand authentication error responses