Skip to main content

Overview

FootyCollect API uses token-based authentication provided by Django REST Framework. Each user can have a unique authentication token that must be included in the HTTP headers for protected endpoints.

Authentication Methods

The API supports two authentication methods:
Most API clients should use Token Authentication. Session authentication is primarily for browser-based interactions and the Django admin interface.

Obtaining an Authentication Token

To obtain an authentication token, send a POST request to the token endpoint with your username and password.

Endpoint

Request

Response

Success (200 OK)
Error (400 Bad Request)
Store your authentication token securely. Never expose tokens in client-side code, version control, or public repositories.

Using the Authentication Token

Once you have a token, include it in the Authorization header of your API requests using the Token scheme.

Header Format

Example Requests

Response

Authentication Errors

Missing Token

If you attempt to access a protected endpoint without a token: Response (401 Unauthorized)

Invalid Token

If you provide an invalid or expired token: Response (401 Unauthorized)

Insufficient Permissions

If your token is valid but you lack permissions: Response (403 Forbidden)

Django Allauth Integration

FootyCollect uses django-allauth for account management, which provides:
  • Email verification for new accounts
  • Password reset functionality
  • Social authentication (Google OAuth)
  • Multi-factor authentication (MFA) support
  • Account lockout after failed login attempts

Account Security

The following security measures are enforced:
API token authentication bypasses some django-allauth features like MFA. For maximum security, ensure tokens are stored securely and rotated regularly.

Token Management

Token Persistence

Tokens are stored in the database and persist until explicitly deleted. Each user has one token that remains valid indefinitely unless revoked.

Regenerating Tokens

To regenerate a token (e.g., if compromised), delete the existing token through the Django admin interface:
  1. Navigate to /admin/authtoken/tokenproxy/
  2. Find the user’s token
  3. Delete it
  4. Obtain a new token via /api/auth-token/
Deleting a token will immediately invalidate all API requests using that token. Ensure your applications are updated with the new token.

Best Practices

  • Use environment variables or secure credential storage
  • Never commit tokens to version control
  • Never expose tokens in client-side code
  • Use HTTPS to prevent token interception
  • Implement token rotation for long-running applications
  • Regenerate tokens if you suspect compromise
  • Delete tokens for deactivated users
  • Implement proper error handling for 401 responses
  • Provide a mechanism to reauthenticate
  • Log authentication failures for monitoring
  • Always use HTTPS to encrypt token transmission
  • Configure SECURE_SSL_REDIRECT = True in Django settings
  • Set appropriate security headers

Example: Complete Authentication Flow

Here’s a complete example demonstrating authentication and API usage:

Next Steps

Now that you understand authentication, learn about: