Authentication methods
Basic Auth
Username and password authentication. Good for development and simple integrations.
API Key
Long-lived tokens for server-to-server communication. Recommended for production.
Basic Auth
The simplest authentication method using username and password.Basic Auth credentials are sent with every request. The SDK handles Base64 encoding automatically.
When to use
- Local development
- Simple scripts and automation
- Testing environments
Limitations
- Credentials sent with every request
- Password rotation requires code changes
- Not ideal for distributed systems
API Key Auth
API keys are long-lived tokens generated in the Komga UI. They’re the recommended authentication method for production applications.Generate an API key
When to use
- Production applications
- CI/CD pipelines
- Server-to-server integrations
- Long-running services
Benefits
- Revocable without password changes
- Scoped permissions possible
- Audit trail in Komga
- No password exposure
OAuth providers
Discover configured OAuth/OpenID Connect providers:Session cookie conversion
If you authenticate with a session header and need a cookie for browser-based clients:Logout
Komga supports logout via both GET and POST. Use POST when possible.Security best practices
Use environment variables
.env
lib/komga.ts
Rotate credentials regularly
API key rotation strategy
API key rotation strategy
- Generate a new API key in Komga
- Update your application with the new key
- Verify the application works with the new key
- Delete the old API key in Komga
Handling expired API keys
Handling expired API keys
If your API key is revoked or expired, generate a new one in the Komga UI and update your application:
Disable debug in production
Use HTTPS in production
- Production
- Development
Comparison table
| Method | Security | Ease of Use | Best For |
|---|---|---|---|
| Basic Auth | Medium | Easy | Development, scripts |
| API Key | High | Medium | Production, automation |
Troubleshooting
401 Unauthorized
401 Unauthorized
403 Forbidden
403 Forbidden
Causes:
- User lacks permission for the requested resource
- API key has insufficient scope
- Check user permissions in Komga
- Verify the user can access the library/book
- Use an admin account for full access
Connection refused
Connection refused
Causes:
- Komga server not running
- Wrong baseUrl
- Firewall blocking connection
- Verify Komga is running
- Check baseUrl includes correct port
- Test with curl or browser
Next steps
Configuration
Configure timeouts, retries, and other client options.
Best Practices
Learn security best practices for production.