Authentication Documentation
Overview
The Loxone MCP Server supports multiple authentication methods to work with different Loxone Miniserver versions and deployment scenarios.
Authentication Methods
1. Unified API Key Authentication (Recommended)
The new unified authentication system provides enterprise-grade security with API key management, role-based access control, and comprehensive audit logging.
Setup Guide: See UNIFIED_AUTH_SETUP.md for detailed instructions.
Key Features:
- SSH-style secure credential storage
- Role-based access control (Admin, Operator, Monitor, Device, Custom)
- Rate limiting and brute-force protection (blocks after 4 failed attempts)
- IP whitelisting with CIDR notation support (e.g.,
192.168.1.0/24
) - Comprehensive audit logging
- API key rotation and expiration
- Automatic background cache refresh
Usage:
# HTTP Header
curl -H "Authorization: Bearer lmk_live_your_api_key" http://localhost:3001/api/devices
# Query Parameter
curl http://localhost:3001/api/devices?api_key=lmk_live_your_api_key
2. Loxone Token Authentication (Native)
For direct integration with Loxone Miniserver’s native authentication system. Supports Loxone V10+ with RSA encryption and JWT tokens.
Documentation: See TOKEN_AUTHENTICATION.md for implementation details.
Features:
- Full Loxone token flow implementation
- RSA public key exchange
- HMAC-SHA256 signature generation
- JWT token management with automatic refresh
- AES session key encryption
- WebSocket token authentication (shares tokens with HTTP client)
Usage:
let config = LoxoneConfig {
auth_method: AuthMethod::Token,
// ... other config
};
3. Basic HTTP Authentication (Legacy)
For older Loxone Miniservers (V8 and below) or simple deployments.
Features:
- Standard HTTP Basic authentication
- Compatible with all Miniserver versions
- Simple username/password credentials
Usage:
let config = LoxoneConfig {
auth_method: AuthMethod::Basic,
// ... other config
};
Security Best Practices
For Production Deployments
- Use Unified API Key Authentication
- Provides the best security and control
- Enables role-based access control
- Includes audit logging
- Enable HTTPS/TLS
- Always use encrypted connections in production
- Configure proper SSL certificates
- Implement Rate Limiting
- Built into unified auth system
- Prevents brute-force attacks
- Regular Key Rotation
- Rotate API keys periodically
- Remove unused keys promptly
- Configure IP Whitelisting
- Restrict API keys to specific IP ranges
- Use CIDR notation for subnets:
# Allow specific IP loxone-mcp-auth update key_id --ip-whitelist "192.168.1.100" # Allow subnet loxone-mcp-auth update key_id --ip-whitelist "192.168.1.0/24" # Allow multiple ranges loxone-mcp-auth update key_id --ip-whitelist "192.168.1.0/24,10.0.0.0/16"
For Development
- Use Memory Storage
export LOXONE_AUTH_STORAGE=memory
- Create Development Keys
loxone-mcp-auth create --name "Dev Key" --role operator
Authentication Flow Comparison
Feature | Unified API Key | Loxone Token | Basic Auth |
---|---|---|---|
Security Level | High | High | Medium |
Miniserver Version | All | V10+ | All |
Role-Based Access | ✅ | ❌ | ❌ |
Audit Logging | ✅ | ❌ | ❌ |
Rate Limiting | ✅ | ❌ | ❌ |
IP Whitelisting | ✅ (CIDR) | ❌ | ❌ |
WebSocket Support | ✅ | ✅ | ✅ |
Key Rotation | ✅ | ✅ | ❌ |
Background Cache | ✅ | ❌ | ❌ |
Setup Complexity | Low | Medium | Low |
Migration Guide
From Environment Variables
If you were using HTTP_API_KEY
environment variable:
- Create a new API key:
loxone-mcp-auth create --name "Migrated Key" --role admin
-
Update your application to use the new key
- Remove the old environment variable:
unset HTTP_API_KEY
From Basic Auth to Unified Auth
- Keep basic auth for Loxone communication
- Add unified auth for client access:
// Loxone connection still uses basic auth let loxone_config = LoxoneConfig { auth_method: AuthMethod::Basic, // ... }; // Client access uses unified auth // Configured automatically via middleware
Troubleshooting
Common Issues
- “Authentication failed”
- Verify API key is correct
- Check key hasn’t expired
- Ensure proper role permissions
- “Rate limited”
- Too many failed attempts (5 attempts in 15 minutes)
- Wait 30 minutes before retrying
- “Permission denied”
- Key lacks required role
- Check with
loxone-mcp-auth list
Debug Mode
Enable debug logging:
export RUST_LOG=debug
cargo run --bin loxone-mcp-server
API Reference
Authentication Endpoints
GET /api/auth/verify
- Verify current authenticationGET /api/auth/permissions
- List current permissionsPOST /api/auth/refresh
- Refresh token (Loxone tokens only)
Headers
Authorization: Bearer {api_key}
- Unified API keyAuthorization: LoxToken {token}
- Loxone JWT tokenAuthorization: Basic {base64}
- HTTP Basic auth