From 298ed9cf325f5b4ebe34594a93c47fcf66be9e67 Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Wed, 15 Oct 2025 14:33:03 +0100 Subject: [PATCH] fix: Allow API key access to UserController::apiGetUsers - Check if user is logged in and admin, OR if using valid API key - This allows API access with Bearer token authentication - Fixes 'Acesso negado' error for API key requests --- crm/Modules/Users/Controllers/UserController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crm/Modules/Users/Controllers/UserController.php b/crm/Modules/Users/Controllers/UserController.php index be928d5..6238f6b 100644 --- a/crm/Modules/Users/Controllers/UserController.php +++ b/crm/Modules/Users/Controllers/UserController.php @@ -373,7 +373,13 @@ class UserController extends BaseController public function apiGetUsers(): void { try { - if (!Auth::isAdmin()) { + // 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 (!$isAdmin && !$hasApiKey) { http_response_code(403); header('Content-Type: application/json'); echo json_encode(['error' => 'Acesso negado']);