From efc564c7f4759a3ec3f06ab94c0720110bc63b84 Mon Sep 17 00:00:00 2001 From: Jepp9350 <2jepp9350@gmail.com> Date: Tue, 27 May 2025 08:32:57 +0200 Subject: [PATCH] Refactor Entra module to remove calendar retrieval and update user endpoint --- services/nginx/app/classes/entra.php | 45 +++++++------------ .../nginx/app/routes/moduleEntraRoute.php | 12 ++--- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/services/nginx/app/classes/entra.php b/services/nginx/app/classes/entra.php index 7070cb3c..3d9a1554 100644 --- a/services/nginx/app/classes/entra.php +++ b/services/nginx/app/classes/entra.php @@ -23,35 +23,6 @@ class entra $this->config = new entra_c(); } - public function get_calendars(): array|object - { - // List all the user calendars - $graphClient = $this->getGraphClient(); - $calendars = $graphClient->Calendars() - ->get() - ->wait() - ->getValue(); - //TODO: This does not work, need to find a way to get the calendars - $result = []; - return $result; - } - - public function getGraphClient(): GraphServiceClient - { - return new GraphServiceClient( - $this->getTokenRequestContext(), - ); - } - - public function getTokenRequestContext(): ClientCredentialContext - { - return new ClientCredentialContext( - $this->config->tenant_id->getVariableValue(), - $this->config->client_id->getVariableValue(), - $this->config->client_secret->getVariableValue() - ); - } - public function get_users($array = false): array|object { $graphClient = $this->getGraphClient(); @@ -74,4 +45,20 @@ class entra } return $result; } + + public function getGraphClient(): GraphServiceClient + { + return new GraphServiceClient( + $this->getTokenRequestContext(), + ); + } + + public function getTokenRequestContext(): ClientCredentialContext + { + return new ClientCredentialContext( + $this->config->tenant_id->getVariableValue(), + $this->config->client_id->getVariableValue(), + $this->config->client_secret->getVariableValue() + ); + } } \ No newline at end of file diff --git a/services/nginx/app/routes/moduleEntraRoute.php b/services/nginx/app/routes/moduleEntraRoute.php index df3a7679..9645f5da 100644 --- a/services/nginx/app/routes/moduleEntraRoute.php +++ b/services/nginx/app/routes/moduleEntraRoute.php @@ -19,21 +19,21 @@ class moduleEntraRoute $router, $response; - /** Modules > Entra > Calendar groups > GET */ - $this->get('/modules/entra/calendar-groups', function () { + /** Modules > Entra > Users > GET */ + $this->get('/modules/entra/users', function () { global $response; - self::requirePermission('modules_entra_calendar_groups'); + self::requirePermission('modules_entra_users'); $user = (new authentication())->get_user(); if ($user) { - $result = (new \classes\entra())->get_calendars(); + $result = (new \classes\entra())->get_users(); $response->success($result); } else { - (new logs_o())->add('modules_entra_calendar_groups', 'global', 1, 0, 'MODULES_ENTRA_CALENDAR_GROUPS', 'User accessed the calendar groups without being logged in'); + (new logs_o())->add('modules_entra_users', 'global', 1, 0, 'MODULES_ENTRA_users', 'User attempted to access Entra users without being logged in'); $response->error('Invalid session', 400); } }, [ - 'modules_entra_calendar_groups' => 'List calendar groups', + 'modules_entra_users' => 'List entra users', ] ); }