feat(api): implement API key management and authentication enhancements
CI / changes (push) Successful in 7s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 25s
CI / web (push) Successful in 28s
CI / go (push) Failing after 24s
CI / bird2 (push) Has been skipped
CI / release (push) Has been skipped

- Added endpoints for managing API keys, including creation, retrieval, updating, and revocation.
- Introduced a new Auth session endpoint to retrieve current tenant and role information.
- Updated the authentication middleware to support API key-based authentication and track last used timestamps.
- Enhanced documentation to reflect new API key functionalities and usage guidelines.
- Improved logging for demo authentication scenarios.
This commit is contained in:
Denozordec
2026-05-21 11:26:17 +07:00
parent 880d77810a
commit 6329a4df27
28 changed files with 1682 additions and 39 deletions
@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS idx_api_key_tenant_active;
DROP INDEX IF EXISTS idx_api_key_token_hash;
DROP TABLE IF EXISTS api_key;
+19
View File
@@ -0,0 +1,19 @@
CREATE TABLE api_key (
id TEXT PRIMARY KEY,
tenant_id TEXT NOT NULL REFERENCES tenant (id) ON DELETE CASCADE,
name TEXT NOT NULL,
role TEXT NOT NULL,
token_prefix TEXT NOT NULL,
token_hash BLOB NOT NULL,
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
expires_at TEXT,
revoked_at TEXT,
last_used_at TEXT,
CHECK (role IN ('viewer', 'editor', 'operator', 'node')),
CHECK (length(trim(name)) > 0),
CHECK (length(token_hash) = 32)
);
CREATE UNIQUE INDEX idx_api_key_token_hash ON api_key (token_hash);
CREATE INDEX idx_api_key_tenant_active ON api_key (tenant_id) WHERE revoked_at IS NULL;