Configuration Methods
The Wacht Rust SDK supports multiple configuration methods to suit different deployment scenarios.Environment Variables (Recommended)
The simplest way to configure the SDK is using environment variables:Manual Configuration
For more control, configure the SDK programmatically:With Public Key
If you have the JWT public key, provide it directly:Auto-fetch Public Key
The SDK can automatically fetch the public key from your deployment:Configuration Options
WachtConfig Structure
Methods
Creates a new configuration with API key and frontend host.
Creates configuration from environment variables. Requires
WACHT_API_KEY and WACHT_FRONTEND_HOST.Sets the JWT public signing key for token validation.
Fetches the public key from the
/.well-known/jwk endpoint.Global Client Configuration
The SDK maintains a global HTTP client with:- Connection Pooling - Reuses connections for better performance
- Default Headers - Automatically includes authentication
- Retry Logic - Built-in retry for transient failures
- Timeout Configuration - Reasonable defaults for API calls
Accessing the Global Client
Authentication Configuration
For API Calls
When initialized, the SDK automatically adds authentication headers:For JWT Validation
The public key is used to validate incoming JWT tokens:Best Practices
Development Environment
Use a.env file for local development:
dotenv crate:
Production Environment
- Use environment variables from your deployment platform
- Never hardcode API keys in source code
- Validate configuration at startup
- Monitor initialization errors
Configuration Validation
Troubleshooting
Common Configuration Issues
Missing API Key
Missing API Key
Error:
WACHT_API_KEY must be setSolution: Ensure the environment variable is set:Invalid Frontend Host
Invalid Frontend Host
Error:
Failed to fetch public keySolution: Verify the frontend host URL:- Include the protocol (
https://) - Remove trailing slashes
- Ensure the host is accessible
Public Key Format
Public Key Format
Error:
Invalid public key formatSolution: The public key must be in PEM format:Already Initialized
Already Initialized
Error:
Wacht SDK already initializedSolution: The SDK can only be initialized once. Check with is_initialized() before calling init().Next Steps
- Environment Variables - Detailed environment setup
- Authentication - JWT validation configuration
- Error Handling - Handle configuration errors
