Authentication¶
Switchboard supports two authentication methods: JWT tokens and API keys.
JWT Authentication¶
Register¶
Create a new account.
Request:
Response:
{
"success": true,
"data": {
"user": {
"id": "user_abc123",
"email": "user@example.com",
"name": "John Doe"
},
"token": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "rt_abc123..."
}
}
Login¶
Authenticate and receive tokens.
Request:
Response:
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"refreshToken": "rt_abc123...",
"expiresIn": 3600
}
}
Using JWT Tokens¶
Include the token in the Authorization header:
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
https://api.switchboard.dev/api/v1/deployments
Refresh Token¶
Refresh an expired JWT token.
Request:
Response:
API Key Authentication¶
API keys are recommended for server-to-server communication.
Create API Key¶
Request:
Response:
{
"success": true,
"data": {
"id": "key_abc123",
"name": "Production Server",
"key": "cs_live_abc123...", // Only shown once!
"permissions": ["deploy", "read", "billing"],
"createdAt": "2024-01-15T10:30:00Z"
}
}
Save Your API Key
The full API key is only shown once at creation. Store it securely.
Using API Keys¶
Include the API key in the X-API-Key header:
List API Keys¶
Response:
{
"success": true,
"data": [
{
"id": "key_abc123",
"name": "Production Server",
"lastUsed": "2024-01-15T12:00:00Z",
"createdAt": "2024-01-15T10:30:00Z"
}
]
}
Revoke API Key¶
Permissions¶
API keys can have specific permissions:
| Permission | Description |
|---|---|
deploy | Create and manage deployments |
read | Read deployments and transactions |
billing | Access billing and usage information |
admin | Full access (all permissions) |
Security Best Practices¶
- Use HTTPS - Always use encrypted connections
- Rotate Keys - Regularly rotate API keys
- Minimum Permissions - Grant only required permissions
- Secure Storage - Store keys in environment variables or secrets managers
- Monitor Usage - Review API key usage regularly
Error Responses¶
Invalid Credentials¶
{
"success": false,
"error": {
"code": "INVALID_CREDENTIALS",
"message": "Invalid email or password"
}
}
Expired Token¶
Invalid API Key¶
{
"success": false,
"error": {
"code": "INVALID_API_KEY",
"message": "API key is invalid or revoked"
}
}
SDK Authentication¶
When using the SDK, authentication is handled automatically: