mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
API now requires tokens
This commit is contained in:
parent
cbfc390c1a
commit
746d08c29f
@ -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 = ?";
|
||||
|
@ -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!");
|
||||
|
Loading…
Reference in New Issue
Block a user