Authentication
Authentication
Section titled “Authentication”The UnboundBytes API supports multiple authentication methods to suit different use cases. This guide explains each method and when to use it.
Authentication Methods Overview
Section titled “Authentication Methods Overview”| Method | Use Case | Security Level |
|---|---|---|
| Bearer Token | Web applications, portals | High |
| HMAC Signature | Agent communication | Very High |
| API Key | Scripts, automation | Medium |
Bearer Token Authentication
Section titled “Bearer Token Authentication”Bearer tokens are JWT tokens issued by your identity provider (typically OIDC). This is the recommended method for web applications.
How It Works
Section titled “How It Works”- User authenticates with your identity provider
- Identity provider issues a JWT token
- Include the token in the
Authorizationheader - API validates the token and extracts user/tenant info
Request Format
Section titled “Request Format”GET /v1/devices HTTP/1.1Host: api.unboundbytes.comAuthorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...Content-Type: application/jsonSDK Usage
Section titled “SDK Usage”import { UnboundBytesClient } from '@unboundbytes/sdk';
const client = new UnboundBytesClient({ auth: { type: 'bearer', token: 'your-jwt-token' }});Token Refresh
Section titled “Token Refresh”The SDK supports automatic token refresh:
const client = new UnboundBytesClient({ auth: { type: 'bearer', token: currentToken, expiresAt: Date.now() + 3600000, // Token expires in 1 hour refreshHandler: async () => { // Called automatically when token is near expiry const response = await fetch('/api/auth/refresh'); const data = await response.json(); return { token: data.accessToken, expiresAt: Date.now() + data.expiresIn * 1000 }; } }});HMAC Signature Authentication
Section titled “HMAC Signature Authentication”HMAC authentication is required for agent-to-orchestrator communication. It provides cryptographic proof that requests are authentic and haven’t been tampered with.
How It Works
Section titled “How It Works”- Agent generates a timestamp
- Agent creates a message:
body + timestamp - Agent signs the message with HMAC-SHA256 using the shared secret
- Agent includes the signature and metadata in headers
- API validates the signature and timestamp
Request Format
Section titled “Request Format”POST /v1/devices/dev_xxx/heartbeat HTTP/1.1Host: api.unboundbytes.comContent-Type: application/jsonx-ub-agent-id: agt_xxxx-ub-tenant-id: ten_xxxx-ub-timestamp: 2025-01-01T00:00:00.000Zx-ub-signature: 8f4a2b1c3d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a
{"status": "online", "metrics": {...}}SDK Usage
Section titled “SDK Usage”import { UnboundBytesClient } from '@unboundbytes/sdk';
const client = new UnboundBytesClient({ auth: { type: 'hmac', agentId: 'agt_xxx', tenantId: 'ten_xxx', sharedSecret: 'your-shared-secret' }});
// The SDK automatically signs all requestsawait client.sendHeartbeat('dev_xxx', { cpu: 25.5, memory: 4096, disk: 50000, timestamp: new Date().toISOString()});Signature Verification
Section titled “Signature Verification”The server verifies requests by:
- Checking the timestamp is within 5 minutes of current time
- Reconstructing the expected signature
- Comparing signatures using constant-time comparison
Generating Signatures Manually
Section titled “Generating Signatures Manually”If not using the SDK, generate signatures like this:
import { createHmac } from 'crypto';
function generateSignature(body: string, timestamp: string, secret: string): string { const message = body + timestamp; return createHmac('sha256', secret) .update(message) .digest('hex');}
// Exampleconst body = JSON.stringify({ status: 'online' });const timestamp = new Date().toISOString();const signature = generateSignature(body, timestamp, sharedSecret);API Key Authentication
Section titled “API Key Authentication”API keys provide a simpler authentication method for scripts and automation tools.
Request Format
Section titled “Request Format”GET /v1/devices HTTP/1.1Host: api.unboundbytes.comx-api-key: key_xxxx-ub-tenant-id: ten_xxxContent-Type: application/jsonSDK Usage
Section titled “SDK Usage”import { UnboundBytesClient } from '@unboundbytes/sdk';
const client = new UnboundBytesClient({ auth: { type: 'apikey', apiKey: 'key_xxx', tenantId: 'ten_xxx' }});Security Best Practices
Section titled “Security Best Practices”Token Storage
Section titled “Token Storage”- Browser: Store tokens in memory or secure HTTP-only cookies
- Server: Use environment variables or secret management
- Never: Commit tokens to source control
Token Rotation
Section titled “Token Rotation”- Implement regular token refresh for long-running applications
- Rotate API keys periodically
- Revoke tokens immediately when compromised
Network Security
Section titled “Network Security”- Always use HTTPS
- Validate TLS certificates
- Use the latest TLS version (1.3 recommended)
Error Responses
Section titled “Error Responses”401 Unauthorized
Section titled “401 Unauthorized”Missing or invalid authentication:
{ "success": false, "error": { "code": "UNAUTHORIZED", "message": "Authentication required" }}403 Forbidden
Section titled “403 Forbidden”Valid authentication but insufficient permissions:
{ "success": false, "error": { "code": "FORBIDDEN", "message": "Access denied to this resource" }}Invalid Signature
Section titled “Invalid Signature”HMAC signature validation failed:
{ "success": false, "error": { "code": "INVALID_SIGNATURE", "message": "Request signature is invalid" }}Next Steps
Section titled “Next Steps”- API Overview - Explore the API structure
- API Explorer - Try the API interactively
- TypeScript SDK - Full SDK documentation