#48 [Admin Panel] API Key Management - Create API Key
Description
EditImplement POST /api/v1/admin/api-keys endpoint to create API keys for service accounts.
**API Specification:**
- Endpoint: POST /api/v1/admin/api-keys
- Permission Required: manage_users
- Request Body: {name, description?, permissions[]?, expires_at?, ip_whitelist[]?}
- Response: {api_key_id, api_key (shown once), name, permissions[], created_at}
**Requirements:**
- Generate secure API key (32-byte random, base64 encoded)
- API key shown ONLY on creation (cannot be retrieved later)
- Optional permission scoping (subset of available permissions)
- Optional IP whitelist restriction
- Optional expiration date
- Store hash of API key, not plaintext
**Database Schema (api_keys table):**
- api_key_id (UUID), tenant_id
- name, description
- key_hash (SHA256)
- key_prefix (first 8 chars for identification)
- permissions[] (JSONB)
- ip_whitelist[] (JSONB)
- created_at, expires_at, last_used_at
- created_by, is_active
**IMPORTANT:** Implement with ultra attention to details and correctness.
**BEFORE CLOSING:** Take screenshot showing API key creation. Add comment summarizing implementation.
Comments
Loading comments...
Context
Loading context...
Audit History
View AllLoading audit history...