ApiKeyService
class ApiKeyService (View source)
Service for managing API keys
Methods
ApiKeyService constructor
Get all API keys the current user has access to with creator usernames
Create a new API key
Update an existing API key
Delete an API key
Regenerate the secret key for an API key
Toggle the disabled status of an API key
Authenticate a request using an API key
Get user ID from API key without setting session (stateless).
Get the api_keys row id from a raw secret key without setting session (stateless).
Resolve the permission scope of an API key (stateless, no session writes).
Details
PDO
getDb()
Get the database connection for debugging
__construct(ApiKeyRepositoryInterface $apiKeyRepository, PDO $db, ConfigurationManager $config, MessageService $messageService, LoggerInterface|null $logger = null, UserContextService|null $userContextService = null)
ApiKeyService constructor
array
getAllApiKeys()
Get all API keys the current user has access to with creator usernames
ApiKey|null
getApiKey(int $id)
Get a specific API key if the current user has access to it
ApiKey|null
createApiKey(string $name, DateTime|null $expiresAt = null, bool $isReadonly = false, array|null $allowedOperations = null, array $zoneIds = [])
Create a new API key
ApiKey|null
updateApiKey(int $id, string $name, DateTime|null $expiresAt = null, bool $disabled = false, bool $isReadonly = false, array|null $allowedOperations = null, array|null $zoneIds = null)
Update an existing API key
bool
deleteApiKey(int $id)
Delete an API key
ApiKey|null
regenerateSecretKey(int $id)
Regenerate the secret key for an API key
ApiKey|null
toggleApiKey(int $id, bool $disabled)
Toggle the disabled status of an API key
bool
authenticate(string $secretKey)
Authenticate a request using an API key
int
getUserIdFromApiKey(string $secretKey)
Get user ID from API key without setting session (stateless).
int|null
getIdFromApiKey(string $secretKey)
Get the api_keys row id from a raw secret key without setting session (stateless).
Used for audit logging so a request can be traced back to a specific key.
ApiKeyScope|null
getScopeFromApiKey(string $secretKey)
Resolve the permission scope of an API key (stateless, no session writes).
Returns null when the key is missing/invalid or the API is disabled, in which case the caller should fall back to an unrestricted scope (the key is already rejected by authentication). A key with no restrictions yields a scope where every zone and operation is allowed.