This commit introduces the Entra module, enabling configuration management and handling callbacks for Microsoft's authorization. It includes new classes, routes, and configuration variables to support integration, ensuring flexibility and logging support for related operations.
64 lines
2.9 KiB
PHP
64 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
use classes\authentication;
|
|
use objects\logs_o;
|
|
use traits\route_t;
|
|
|
|
|
|
class callbackMicrosoftRoute
|
|
{
|
|
use route_t;
|
|
|
|
public function run(): void
|
|
{
|
|
$this->post('/callback/microsoft/token', function () {
|
|
// Require the user to be logged in
|
|
global $response;
|
|
self::requirePermission('callback_microsoft_token');
|
|
$user = (new authentication())->get_user();
|
|
// Check if the request was successful
|
|
if (!$user) {
|
|
// Log the incident
|
|
(new logs_o())->add('user_callback', 'global', 0, 0, 'USER_CALLBACK_MICROSOFT_TOKEN', 'User not logged in');
|
|
$response->error('Invalid session', 400);
|
|
}
|
|
// Require the parameters:
|
|
// client_info
|
|
// code
|
|
// session_state
|
|
// state
|
|
self::requireParameters(['client_info', 'code', 'session_state', 'state']);
|
|
// Check if the parameters are valid
|
|
self::requireType((string)self::getParameter('client_info'), self::type_string());
|
|
self::requireType((string)self::getParameter('code'), self::type_string());
|
|
self::requireType((string)self::getParameter('session_state'), self::type_string());
|
|
self::requireType((string)self::getParameter('state'), self::type_string());
|
|
// Check if the parameters are valid
|
|
$client_info = (string)self::getParameter('client_info');
|
|
$code = (string)self::getParameter('code');
|
|
$session_state = (string)self::getParameter('session_state');
|
|
$state = (string)self::getParameter('state');
|
|
// Check if the parameters are valid
|
|
if (empty($client_info) || empty($code) || empty($session_state) || empty($state)) {
|
|
(new logs_o())->add('user_callback', 'global', 0, $user->id, 'USER_CALLBACK_MICROSOFT_TOKEN', 'Invalid parameters');
|
|
$response->error('Invalid parameters', 400);
|
|
}
|
|
|
|
// Log the incident
|
|
(new logs_o())->add('user_callback', 'global', 1, $user->id, 'USER_CALLBACK_MICROSOFT_TOKEN', 'Successfully received callback from Microsoft');
|
|
// Save the parameters to the database
|
|
$user->keys->setValue('microsoft_client_info', $client_info);
|
|
$user->keys->setValue('microsoft_code', $code);
|
|
$user->keys->setValue('microsoft_session_state', $session_state);
|
|
$user->keys->setValue('microsoft_state', $state);
|
|
// Return a success message
|
|
$response->success(['message' => 'Successfully received callback from Microsoft', 'client_info' => $client_info, 'code' => $code, 'session_state' => $session_state, 'state' => $state]);
|
|
},
|
|
[
|
|
'callback_microsoft_token' => 'Callback Microsoft token (Set the token)',
|
|
]
|
|
);
|
|
}
|
|
} |