diff --git a/src/FederationServer/Classes/Enums/Method.php b/src/FederationServer/Classes/Enums/Method.php index 098e0db..49cff40 100644 --- a/src/FederationServer/Classes/Enums/Method.php +++ b/src/FederationServer/Classes/Enums/Method.php @@ -250,6 +250,7 @@ $path === '/operators' && $requestMethod === 'GET' => Method::LIST_OPERATORS, $path === '/operators' && $requestMethod === 'POST' => Method::CREATE_OPERATOR, $path === '/operators/self' && $requestMethod === 'GET' => Method::GET_SELF_OPERATOR, + $path === '/operators/refresh' && $requestMethod === 'POST' => Method::REFRESH_OPERATOR_API_KEY, preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'GET' => Method::GET_OPERATOR, preg_match('#^/operators/([a-fA-F0-9\-]{36,})$#', $path) && $requestMethod === 'DELETE' => Method::DELETE_OPERATOR, preg_match('#^/operators/([a-fA-F0-9\-]{36,})/enable$#', $path) && $requestMethod === 'POST' => Method::ENABLE_OPERATOR, diff --git a/src/FederationServer/FederationServer.php b/src/FederationServer/FederationServer.php index a9954b9..8298bac 100644 --- a/src/FederationServer/FederationServer.php +++ b/src/FederationServer/FederationServer.php @@ -3,6 +3,7 @@ namespace FederationServer; use Exception; + use FederationServer\Classes\Enums\HttpResponseCode; use FederationServer\Classes\Enums\Method; use FederationServer\Classes\Logger; use FederationServer\Classes\RequestHandler; @@ -151,7 +152,7 @@ $operator = self::getAuthenticatedOperator(); if ($operator === null) { - throw new RequestException('Authentication required', 401); + throw new RequestException('Authentication required', HttpResponseCode::UNAUTHORIZED); } return $operator; diff --git a/src/FederationServer/Methods/Operators/ManageBlacklistPermission.php b/src/FederationServer/Methods/Operators/ManageBlacklistPermission.php index 89355cc..1ff1075 100644 --- a/src/FederationServer/Methods/Operators/ManageBlacklistPermission.php +++ b/src/FederationServer/Methods/Operators/ManageBlacklistPermission.php @@ -17,7 +17,7 @@ */ public static function handleRequest(): void { - $authenticatedOperator = FederationServer::getAuthenticatedOperator(); + $authenticatedOperator = FederationServer::requireAuthenticatedOperator(); if(!$authenticatedOperator->canManageOperators()) { throw new RequestException('Insufficient permissions manage permissions', 403); diff --git a/src/FederationServer/Methods/Operators/ManageClientPermission.php b/src/FederationServer/Methods/Operators/ManageClientPermission.php index 5b83a6e..2d1c802 100644 --- a/src/FederationServer/Methods/Operators/ManageClientPermission.php +++ b/src/FederationServer/Methods/Operators/ManageClientPermission.php @@ -17,7 +17,7 @@ */ public static function handleRequest(): void { - $authenticatedOperator = FederationServer::getAuthenticatedOperator(); + $authenticatedOperator = FederationServer::requireAuthenticatedOperator(); if(!$authenticatedOperator->canManageOperators()) { throw new RequestException('Insufficient permissions manage permissions', 403); diff --git a/src/FederationServer/Methods/Operators/ManageOperatorsPermission.php b/src/FederationServer/Methods/Operators/ManageOperatorsPermission.php index 461a2e0..56a9dcd 100644 --- a/src/FederationServer/Methods/Operators/ManageOperatorsPermission.php +++ b/src/FederationServer/Methods/Operators/ManageOperatorsPermission.php @@ -17,7 +17,7 @@ */ public static function handleRequest(): void { - $authenticatedOperator = FederationServer::getAuthenticatedOperator(); + $authenticatedOperator = FederationServer::requireAuthenticatedOperator(); if(!$authenticatedOperator->canManageOperators()) { throw new RequestException('Insufficient permissions manage permissions', 403); diff --git a/src/FederationServer/Methods/Operators/RefreshOperatorApiKey.php b/src/FederationServer/Methods/Operators/RefreshOperatorApiKey.php index 18d8e7e..dfca264 100644 --- a/src/FederationServer/Methods/Operators/RefreshOperatorApiKey.php +++ b/src/FederationServer/Methods/Operators/RefreshOperatorApiKey.php @@ -16,9 +16,7 @@ */ public static function handleRequest(): void { - $authenticatedOperator = FederationServer::getAuthenticatedOperator(); - - $operatorUuid = null; + $authenticatedOperator = FederationServer::requireAuthenticatedOperator(); if(preg_match('#^/operators/([a-fA-F0-9\-]{36,})/refresh$#', FederationServer::getPath(), $matches)) { $operatorUuid = $matches[1];