API now requires tokens

This commit is contained in:
Pierre 2018-01-02 17:43:00 +01:00
parent cbfc390c1a
commit 746d08c29f
2 changed files with 6 additions and 12 deletions

View File

@ -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 = ?";

View File

@ -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!");