본문으로 건너뛰기

API Keys

Your integration team needs to connect ProBeya to your MES (Manufacturing Execution System), feed KPI data from your Historian, and sync action items with your corporate ServiceNow instance. API keys provide programmatic access for these integrations with the same security model used by GitHub Personal Access Tokens and Stripe API keys -- keys shown once, bcrypt-hashed storage, prefix-based lookup, and scoped permissions.

API access requires the Pro plan or higher (feature gate level 2).

API Key vs. OAuth vs. SSO: Choosing the Right Auth Model​

CriterionAPI KeysOAuth 2.0 (SSO)Session (Browser)
Best forServer-to-server integrations, CI/CD, scriptsUser-facing apps with delegated accessInteractive browser use
Credential typeLong-lived bearer tokenShort-lived access token + refresh tokenSession cookie
User contextBound to the creating userBound to the authenticating userActive session user
Scope controlGranular per-key scopesDefined by OAuth scopesFull user permissions
RotationManual or scheduledAutomatic via refresh tokensAutomatic via session renewal
GxP audit trailAPI key ID logged per requestUser ID logged per requestUser ID logged per action
RevocationImmediate, irreversibleToken expiry + revocation endpointSession termination
Recommendation for Pharma Integrations

Use API keys for headless integrations (MES sync, LIMS data feed, CI/CD pipelines). Use SSO for interactive applications where a human user is present. Never embed API keys in client-side JavaScript or mobile app code.

Key Architecture​

ProBeya API keys follow a defense-in-depth design:

PropertyValueSecurity Rationale
Formatprobeya_sk_live_{40 hex chars}Identifiable in logs and config files without exposing the secret
Entropy160 bits (20 random bytes)Exceeds NIST SP 800-132 recommendation of 128 bits
Storagebcrypt hash (10 salt rounds)Even if the database is compromised, plaintext keys cannot be recovered
Lookup8-char hex prefix for DB queryNarrows search to ~1 row per prefix (out of ~4 billion possible prefixes)
Generationcrypto.randomBytes() (OS CSPRNG)Cryptographically secure, backed by /dev/urandom on Linux
VisibilityFull key shown once at creationSame pattern as Stripe, GitHub, AWS -- forces immediate secure storage

Available Scopes​

Scopes restrict what an API key can access. An empty scope array means full access (all scopes granted).

ScopeDescriptionPharma Use Case
read:itemsRead items, boards, projectsMES dashboard pulling board status
write:itemsCreate, update, delete itemsAutomated deviation import from TrackWise
read:kpisRead KPI definitions and valuesHistorian feeding data to analytics dashboard
write:kpisRecord KPI values, set targetsAutomated OEE data ingestion from MES
read:actionsRead action itemsServiceNow integration pulling open actions
write:actionsCreate, update action itemsAutomated CAPA creation from quality events
read:searchExecute search queriesEnterprise search integration
read:dashboardRead dashboard statisticsExecutive reporting portal
read:notificationsRead notificationsMobile app notification feed

Getting Started​

  1. Navigate to Settings > API Keys.
  2. Click Create API Key.
  3. Enter a descriptive name (1--100 characters, e.g., "MES Integration - Brussels Site").
  4. Select scopes to restrict permissions (leave empty for full access).
  5. Optionally set an expiration date (ISO 8601 format).
  6. Click Create and copy the key immediately -- it will not be shown again.
경고

API key management requires the manage_settings permission, which is restricted to org_owner, tenant_admin, and site_admin roles (hierarchy level <= 10). This prevents lower-privilege users from generating programmatic access tokens that could bypass UI-level restrictions.

Key Lifecycle​

StateDescriptionSecurity Behavior
ActiveKey is validAuthenticates API requests; lastUsedAt updated on each use
ExpiredPast expiration dateAutomatically rejected with 401 Unauthorized
RevokedManually revoked by adminPermanently rejected; revocation is irreversible
DeletedRecord removed from databaseKey hash and metadata permanently purged

Authentication Flow​

When an external client makes an API request:

Client → Authorization: Bearer probeya_sk_live_a1b2c3d4...
↓
Server → Extract 8-char prefix ("a1b2c3d4")
↓
Server → Query DB: WHERE prefix = "a1b2c3d4" AND organizationId = ctx.orgId
↓
Server → bcrypt.compare(fullKey, storedHash)
↓
Server → Check expiry, revocation status, and scopes
↓
Server → Execute request with the key creator's user context

Key Rotation​

The Rotate action atomically revokes the current key and creates a new one in a single database transaction:

  1. Click Rotate next to the key you want to rotate.
  2. Copy the new key immediately.
  3. Update the key in your integration or CI/CD system.
  4. The old key is immediately revoked and will no longer authenticate.

Enterprise Rotation Policy​

For GxP-validated environments, establish a key rotation policy in your SOP:

Risk LevelRotation FrequencyRationale
Critical integrations (MES, LIMS)Every 90 daysLimits exposure window for compromised keys
Non-critical integrations (dashboards)Every 180 daysLower risk, reduced operational overhead
Temporary project keysSet expiration date at creationAutomatic expiry eliminates forgotten keys
Post-incidentImmediatelyAny suspected compromise requires immediate rotation

Scope Design for Integration Teams​

Pattern 1: MES Integration (Read/Write KPIs + Read Items)​

Name: "MES Integration - Brussels OEE Feed"
Scopes: ["write:kpis", "read:kpis", "read:items"]
Expiry: 90 days

Pattern 2: Executive Dashboard (Read Only)​

Name: "Portfolio Dashboard - C-Suite"
Scopes: ["read:dashboard", "read:kpis", "read:items"]
Expiry: 180 days

Pattern 3: CI/CD Pipeline (Full Access)​

Name: "GitHub Actions - Deployment Pipeline"
Scopes: [] (full access)
Expiry: 30 days
경고

Full-access keys (scopes: []) should be rare and tightly controlled. Prefer scoped keys that follow the principle of least privilege. Document each full-access key's justification in your change control record.

Permissions & Security​

  • API key management is done via session authentication (the settings UI), not via API keys themselves. You cannot create or revoke keys using another API key -- this prevents automated privilege escalation.
  • All operations are scoped to the current organization for multi-tenant isolation.
  • All CRUD operations are logged to the audit trail for compliance.
  • API keys cannot access features above the organization's plan level.

Troubleshooting​

SymptomCauseResolution
401 UnauthorizedKey is expired, revoked, or malformedCheck key status in Settings > API Keys; create a new key if needed
403 ForbiddenKey lacks the required scope, or feature is above plan levelCreate a new key with broader scopes, or upgrade the plan
Key not shown after creationPage was refreshed before copyingCreate a new key (the old one's plaintext is permanently lost)
Cannot create keysUser lacks manage_settings permissionAsk an org_owner or tenant_admin to create the key
429 Too Many RequestsRate limit exceededImplement exponential backoff in your integration client

Recovery Procedures​

ScenarioResolution
API key compromisedImmediately revoke the key in Settings > API Keys. Create a new key. Review the audit log for unauthorized activity.
Integration broke after key rotationVerify the new key is correctly deployed in the integration system. Check for cached old keys in CI/CD secrets.
All API keys accidentally revokedCreate new keys. Revocation is irreversible -- there is no undo.
Key creator left the organizationThe key remains valid until explicitly revoked. Audit all keys owned by departing users and revoke/rotate as needed.
  • Webhooks -- Push event notifications to external systems (complement to pull-based API access).
  • Connectors -- Pre-built bidirectional sync with SAP, TrackWise, and other pharma systems.
  • Integrations -- Slack and Teams notification integrations.
  • Audit Log -- API key creation, usage, revocation, and deletion events are logged.
  • Security Settings -- Session policies and 2FA enforcement.