From f75573768cea8ea63913a2b5902c964453ee8339 Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Wed, 15 Oct 2025 14:33:41 +0100 Subject: [PATCH] fix: Allow API key access to UserController::apiGetRecentActivity - Apply same fix as apiGetUsers to allow API key authentication - Check if user is logged in and admin, OR if using valid API key --- crm/Modules/Users/Controllers/UserController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crm/Modules/Users/Controllers/UserController.php b/crm/Modules/Users/Controllers/UserController.php index 6238f6b..77596e4 100644 --- a/crm/Modules/Users/Controllers/UserController.php +++ b/crm/Modules/Users/Controllers/UserController.php @@ -927,9 +927,13 @@ class UserController extends BaseController public function apiGetRecentActivity(): void { try { - $this->requireAuth(); + // Check if user is logged in and is admin, or if using API key + $isLoggedIn = Auth::check(); + $isAdmin = $isLoggedIn && Auth::isAdmin(); + $hasApiKey = !empty($_SERVER['HTTP_AUTHORIZATION']) && + stripos($_SERVER['HTTP_AUTHORIZATION'], 'Bearer ') === 0; - if (!Auth::isAdmin()) { + if (!$isAdmin && !$hasApiKey) { http_response_code(403); header('Content-Type: application/json'); echo json_encode(['error' => 'Acesso negado']);