Skip to content

Authentication

Primatomic uses JWT (JSON Web Tokens) for API authentication. This document specifies the authentication requirements and token lifecycle.

All authenticated endpoints require a valid JWT token in the Authorization header. Requests without a valid token receive a 401 Unauthorized response.

Section titled “API Key Exchange (Recommended for Services)”

Services and automated clients should use API key exchange. POST the API key to obtain a JWT:

Terminal window
curl -X POST https://api.primatomic.com/auth/token \
-H "Content-Type: application/json" \
-d '{"api_key": "pk_live_abc123..."}'

The service responds with:

{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}

Interactive users can authenticate with email and password:

Terminal window
curl -X POST https://api.primatomic.com/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "your_password"
}'

Login fails with 403 Forbidden if the email address has not been verified.

Include the token in the Authorization header using the Bearer scheme:

Terminal window
curl https://api.primatomic.com/logs \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."
PropertySpecification
LifetimeTokens expire after 3600 seconds (1 hour)
RenewalObtain a new token before expiry
RevocationTokens associated with revoked API keys are rejected

Implement automatic token refresh:

  1. On receiving 401 Unauthorized, request a new token
  2. Refresh tokens proactively before expiry
  3. Do not cache tokens beyond their expiry time

Authenticated clients can create additional API keys:

Terminal window
curl -X POST https://api.primatomic.com/keys \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "production-service"}'

The service responds with the plaintext key:

{
"api_key_id": "550e8400-e29b-41d4-a716-446655440000",
"name": "production-service",
"key": "pk_live_abc123...",
"created_at": "2024-01-19T12:00:00Z"
}

Specify an expiration period:

Terminal window
curl -X POST https://api.primatomic.com/keys \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "temp-key", "expires_in_days": 30}'

Keys with expiration automatically become invalid after the specified period.

Terminal window
curl https://api.primatomic.com/keys \
-H "Authorization: Bearer $TOKEN"

The response does not include plaintext key values.

Terminal window
curl -X DELETE https://api.primatomic.com/keys/550e8400-e29b-41d4-a716-446655440000 \
-H "Authorization: Bearer $TOKEN"

Revoked keys immediately cease to function. Tokens previously issued for revoked keys are rejected.

RequirementLevelDescription
Key StorageRequiredAPI keys should be stored securely (e.g., secrets manager, environment variables)
Client-Side ExposureProhibitedAPI keys should not be exposed in client-side code or version control
Key RotationRecommendedKeys should be rotated periodically
NamingRecommendedKeys should use descriptive names indicating service/environment
ExpirationRecommendedTemporary access should use keys with expiration
MonitoringRecommendedUsage should be monitored via /billing/usage for anomalies
StatusConditionClient Action
401Invalid, expired, or revoked token/keyObtain a new token
403Email not verified (login)Verify email before retry
429Rate limit exceededRespect Retry-After header