Authentication
The Turris Public API supports two authentication methods. Choose the one that best fits your use case.Authentication Methods
| Method | Best For | Security Level |
|---|---|---|
| OAuth (M2M) | Server-to-server integrations | High - JWT with expiration |
| Restricted Access Token | Simple integrations with IP restrictions | High - Token + IP allowlist |
Both methods provide the same level of access. OAuth is recommended for production integrations due to its token rotation capability.
OAuth Authentication (Recommended)
OAuth uses Machine-to-Machine (M2M) JWT tokens for authentication. This is the preferred method for production integrations.Step 1: Create API Client
- Navigate to API Settings in your Turris dashboard
- Click Create API Client
- Store your
client_idandclient_secretsecurely
Step 2: Get Access Token
Exchange your credentials for a JWT:Step 3: Use the Token
Include the token in theAuthorization header:
Token Lifecycle
| Property | Value |
|---|---|
| Time-to-Live (TTL) | 60 minutes |
| Refresh | Request new token before expiry |
Test Your Token
Verify your token is valid:Restricted Access Token
Restricted Access Tokens provide a simpler authentication method with IP-based security.Step 1: Create Token
- Navigate to API Settings in your Turris dashboard
- Click Create Restricted Access Token
- Add your server’s IP addresses to the allowlist
- Store your token securely
Step 2: Use the Token
Include the token in thex-restricted-access-token header:
Security Model
The Restricted Access Token guard performs three validations:- Token Presence - Checks for the
x-restricted-access-tokenheader - Token Validity - Validates the token against stored hashes
- IP Allowlist - Verifies the request originates from an allowed IP address
Test Your Token
Verify your token and IP are configured correctly:Fallback Behavior
When both authentication headers are provided, the API uses this priority:- OAuth is attempted first
- If OAuth fails and a Restricted Access Token is present, token authentication is attempted
Error Responses
401 Unauthorized
Missing or invalid credentials:403 Forbidden
IP not in allowlist (Restricted Access Token only):Best Practices
Store credentials securely
Store credentials securely
- Use environment variables or a secrets manager
- Never commit credentials to version control
- Rotate credentials periodically
Implement token caching
Implement token caching
- Cache OAuth tokens for their full TTL (60 minutes)
- Refresh tokens proactively before expiry
- Handle token refresh failures gracefully
Handle errors gracefully
Handle errors gracefully
- Implement retry logic for transient failures
- Log authentication errors for debugging
- Alert on repeated authentication failures