juggl/public/api/services/authenticator.inc.php
2021-02-18 14:03:59 +01:00

27 lines
No EOL
859 B
PHP

<?php
require_once(__DIR__."/dbOperations.inc.php");
require_once(__DIR__."/paramCleaner.inc.php");
require_once(__DIR__."/jugglDbApi.inc.php");
class Authenticator {
function isApiKeyAuthenticated($api_key, $user_id) {
$db = new DbOperations();
$db->select("api_keys", ["enabled"]);
$db->where("api_key", Comparison::EQUAL, $api_key);
$db->where("user_id", Comparison::EQUAL, $user_id);
$result = $db->execute();
return count($result) == 1 && $result[0]['enabled'];
}
function isAuthenticated($params) {
return $this->isApiKeyAuthenticated($params->get('api_key'), $params->get('user_id'));
}
function isSseAuthenticated($user_id, $sse_key) {
$params = new ParamCleaner(["sse_key" => $sse_key]);
return validatedSseKey($user_id, $params);
}
}
?>