From 746d08c29f58a0abf2a95404c9ed28080fb8bd91 Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 2 Jan 2018 17:43:00 +0100 Subject: [PATCH] API now requires tokens --- classes/tokens.php | 12 ++++++------ index.php | 6 ------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/classes/tokens.php b/classes/tokens.php index 8b661bb..aa43de7 100644 --- a/classes/tokens.php +++ b/classes/tokens.php @@ -10,9 +10,9 @@ class Tokens{ /** * Check request client tokens * - * @return Boolean Depends of the validity of the tokens + * @return bool Depends of the validity of the tokens */ - public function checkClientRequestTokens(){ + public function checkClientRequestTokens() : bool{ if(!isset($_POST['serviceName']) OR !isset($_POST['serviceToken'])) return false; //No token specified @@ -34,11 +34,11 @@ class Tokens{ /** * Check client API credentials (tokens) * - * @param String $serviceName The name of the service - * @param String $token The service's token - * @return Boolean False or Tokens ID / Depending of validity of credentials + * @param string $serviceName The name of the service + * @param string $token The service's token + * @return bool / array False or Tokens ID / Depending of validity of credentials */ - private function validateClientTokens($serviceName, $token){ + private function validateClientTokens(string $serviceName, string $token) { //Prepare DataBase request $tableName = CS::get()->config->get("dbprefix")."API_ServicesToken"; $conditions = "WHERE serviceName = ? AND token = ?"; diff --git a/index.php b/index.php index 34cdb1a..caf80d4 100644 --- a/index.php +++ b/index.php @@ -27,12 +27,6 @@ if(!isset($_GET["format"])) //Specify we are on Comunic API Server header("Technology: Official Comunic API Server"); -//Set debug clients tokens -if($cs->config->get("site_mode") === "debug"){ //DEBUG ONLY - $_POST['serviceName'] = "testService"; - $_POST['serviceToken'] = "testPasswd"; -} - //Check client tokens if(!$cs->tokens->checkClientRequestTokens()) Rest_fatal_error(401, "Please check your client tokens!");