Skip to content

Authentication

Cohera supports multiple authentication methods to fit different use cases. Choose the method that best fits your application.

MethodBest ForSecurity Level
API KeysServer-to-server, scripts, CLIHigh
OAuth2User-facing applicationsHighest
JWT TokensMicroservices, short-lived accessHigh

API keys are the simplest way to authenticate with Cohera. They’re ideal for server-side applications, scripts, and development.

  1. Log in to your Cohera Dashboard
  2. Go to Settings > API Keys
  3. Click Create New Key
  4. Select the appropriate scopes
  5. Set an expiration date (optional but recommended)
  6. Copy and securely store the key
from cohera import Cohera
# Via environment variable (recommended)
import os
os.environ["COHERA_API_KEY"] = "ck_live_..."
client = Cohera()
# Via constructor
client = Cohera(api_key="ck_live_...")

Control what your API key can access:

ScopeDescription
read:certificatesRead certificate data
write:certificatesCreate and update certificates
read:suppliersRead supplier data
write:suppliersCreate and update suppliers
read:productsRead product data
write:productsCreate and update products
adminFull access to all resources

OAuth2 is recommended for applications that act on behalf of users. It provides the highest level of security and allows users to control their data access.

┌──────────┐ ┌──────────┐ ┌──────────┐
│ User │────>│ Your App │────>│ Cohera │
└──────────┘ └──────────┘ └──────────┘
│ │ │
│ 1. Login │ │
│───────────────>│ │
│ │ 2. Redirect │
│ │───────────────>│
│ │ │
│ 3. Authorize │<───────────────│
│<───────────────│ │
│ │ │
│ │ 4. Token │
│ │<───────────────│
│ │ │
│ 5. Access │ │
│<───────────────│ │
└──────────────────────────────────────┘
  1. Register your application in the Developer Console
  2. Configure your redirect URIs
  3. Note your Client ID and Client Secret
  4. Implement the authorization flow
from cohera import Cohera
from cohera.auth import OAuth2
# Step 1: Get authorization URL
oauth = OAuth2(
client_id="your-client-id",
client_secret="your-client-secret",
redirect_uri="https://yourapp.com/callback"
)
auth_url = oauth.get_authorization_url(
scopes=["read:certificates", "read:suppliers"]
)
# Redirect user to auth_url
# Step 2: Handle callback
code = request.args.get("code") # From callback
tokens = oauth.exchange_code(code)
# Step 3: Use the access token
client = Cohera(access_token=tokens.access_token)
certificates = client.certificates.list()
# Step 4: Refresh when needed
if tokens.is_expired:
tokens = oauth.refresh_token(tokens.refresh_token)

JWT tokens are used for service-to-service authentication and short-lived access. They’re signed tokens that contain claims about the authenticated entity.

from cohera import Cohera
from cohera.auth import ServiceAccount
# Load service account credentials
sa = ServiceAccount.from_file("service-account.json")
# Generate a JWT
token = sa.generate_token(
scopes=["read:certificates"],
expires_in=3600 # 1 hour
)
# Use the token
client = Cohera(access_token=token)

Cohera JWTs contain the following claims:

{
"iss": "cohera.io",
"sub": "sa_abc123",
"aud": "https://api.cohera.io",
"exp": 1699999999,
"iat": 1699996399,
"scopes": ["read:certificates", "read:suppliers"],
"org_id": "org_xyz789"
}
  1. Never commit credentials - Use environment variables or secret managers
  2. Rotate keys regularly - Set expiration dates and rotate keys periodically
  3. Use least privilege - Only request scopes your application needs
  4. Monitor usage - Review API key usage in the dashboard
  5. Revoke unused keys - Delete keys that are no longer needed
Terminal window
# .env file (never commit this!)
COHERA_API_KEY=ck_live_...
COHERA_CLIENT_ID=your-client-id
COHERA_CLIENT_SECRET=your-client-secret

We recommend using a secret manager in production:

  • AWS Secrets Manager
  • Google Secret Manager
  • HashiCorp Vault
  • Azure Key Vault

All authentication methods are subject to rate limits:

TierRequests/minRequests/day
Free601,000
Pro60050,000
EnterpriseCustomCustom

Rate limit headers are included in every response:

X-RateLimit-Limit: 600
X-RateLimit-Remaining: 599
X-RateLimit-Reset: 1699999999