diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 1e3d43ed9db..d453d141546 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -18,7 +18,7 @@ use \Luracast\Restler\iAuthenticate; use \Luracast\Restler\Resources; use \Luracast\Restler\Defaults; -use Luracast\Restler\RestException; +use \Luracast\Restler\RestException; /** @@ -44,24 +44,14 @@ class DolibarrApiAccess implements iAuthenticate */ public static $user = ''; - // @codingStandardsIgnoreStart - - /** - * @return string string to be used with WWW-Authenticate header - * @example Basic - * @example Digest - * @example OAuth - */ - public function __getWWWAuthenticateString(); - /** * Check access * - * @return boolean + * @return bool + * @throws RestException */ - public function _isAllowed() - { - // @codingStandardsIgnoreEnd + public function __isAllowed() + { global $db; $stored_key = ''; @@ -74,7 +64,8 @@ class DolibarrApiAccess implements iAuthenticate $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE u.api_key = '".$db->escape($_GET['api_key'])."'"; - if ($db->query($sql)) + $result = $db->query($sql); + if ($result) { if ($db->num_rows($result)) { @@ -116,6 +107,12 @@ class DolibarrApiAccess implements iAuthenticate } // @codingStandardsIgnoreStart + /** + * @return string string to be used with WWW-Authenticate header + * @example Basic + * @example Digest + * @example OAuth + */ public function __getWWWAuthenticateString() { return ''; @@ -123,12 +120,13 @@ class DolibarrApiAccess implements iAuthenticate // @codingStandardsIgnoreEnd /** - * Verify access - * - * @param array $m Properties of method - * - * @access private - */ + * Verify access + * + * @param array $m Properties of method + * + * @access private + * @return bool + */ public static function verifyAccess(array $m) { $requires = isset($m['class']['DolibarrApiAccess']['properties']['requires']) diff --git a/htdocs/public/api/index.php b/htdocs/public/api/index.php index d5065e45a32..352849af15c 100644 --- a/htdocs/public/api/index.php +++ b/htdocs/public/api/index.php @@ -47,8 +47,8 @@ if (empty($conf->global->MAIN_MODULE_API)) exit; } -use Luracast\Restler\Defaults; -Defaults::setProperty('authenticationMethod','_isAllowed'); +use \Luracast\Restler\Defaults; +Defaults::setProperty('authenticationMethod','__isAllowed'); $api = new DolibarrApi($db); @@ -125,4 +125,4 @@ foreach ($modulesdir as $dir) } } -$api->r->handle(); //serve the response \ No newline at end of file +$api->r->handle(); //serve the response