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
This commit is contained in:
1 parent
f88fc2412b
commit
298ed9cf32
1 file changed
+7
-1
@@ -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']);
|
||||
|
||||
Reference in new issue
Block a user