Authentication
The WispHub API uses API key authentication to secure access to the WispHub Net infrastructure. This page explains how authentication works and how to configure it properly.Authentication Flow
The WispHub middleware API itself does not require authentication from clients. It acts as a trusted proxy that authenticates to WispHub Net on behalf of clients.
Configuration
Environment Variables
Authentication credentials are configured via environment variables:.env
Settings Management
Credentials are loaded using Pydantic Settings:app/core/config.py
Authentication Headers
All requests to WispHub Net include the API key in theAuthorization header:
app/services/clients_service.py
Security Best Practices
Restrict File Permissions
Ensure the This makes it readable only by the file owner.
.env file has restricted permissions:Use Secrets Management in Production
For production deployments, use proper secrets management:
- Docker: Use Docker secrets or environment variables
- Kubernetes: Use Kubernetes secrets
- Cloud: Use AWS Secrets Manager, Azure Key Vault, or Google Secret Manager
Rotate Keys Regularly
Establish a key rotation policy:
- Generate new API keys quarterly
- Invalidate old keys after migration
- Maintain audit log of key usage
Docker Deployment
When deploying with Docker, pass environment variables securely:Using —env-file (Development)
Using Docker Secrets (Production)
docker-compose.yml
Error Handling
Invalid API Key
If the API key is invalid, WispHub Net returns a 401 or 403 error:Missing API Key
If theWISPHUB_NET_KEY environment variable is not set, the application will fail to start:
Testing Authentication
For testing purposes, you can mock the authentication:tests/conftest.py
respx to mock WispHub Net responses:
tests/api/test_clients.py
API Key Permissions
The WispHub API key must have the following permissions in WispHub Net:Required Permissions
Required Permissions
- Read Clients (
api/clientes/): View client information - Update Clients (
api/clientes/{id}/perfil/): Update client profiles - Read Plans (
api/plan-internet/): View internet plans - Read/Write Tickets (
api/tickets/): Create and view support tickets - Read Tasks (
api/tasks/): View task information
Rate Limiting
WispHub Net may impose rate limits on API key usage:- Typical limit: 1000 requests per hour
- Burst limit: 100 requests per minute
- Without cache: ~6,000 requests/hour for 100 users
- With cache: ~12 requests/hour for 100 users
The 5-minute cache TTL for clients and 15-minute TTL for plans effectively keeps the API well under typical rate limits.
Troubleshooting
Issue: “401 Unauthorized” errors
Cause: Invalid or expired API key Solution:- Verify the API key in your
.envfile - Check that the key hasn’t been revoked in WispHub Net
- Ensure no extra whitespace in the environment variable
Issue: “403 Forbidden” errors
Cause: API key lacks required permissions Solution: Contact your WispHub administrator to grant the necessary permissions to your API key.Issue: Application won’t start
Cause: MissingWISPHUB_NET_KEY environment variable
Solution: Ensure the .env file exists and contains the required variable:
Related Configuration
For complete configuration details, see:Environment Configuration
All available environment variables
Docker Deployment
Deploying with Docker and secrets
