juggl/public/api/services/authenticator.inc.php

27 lines
859 B
PHP
Raw Normal View History

2021-01-03 12:29:41 +01:00
<?php
require_once(__DIR__."/dbOperations.inc.php");
2021-02-18 14:03:59 +01:00
require_once(__DIR__."/paramCleaner.inc.php");
require_once(__DIR__."/jugglDbApi.inc.php");
2021-01-03 12:29:41 +01:00
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'));
}
2021-02-18 14:03:59 +01:00
function isSseAuthenticated($user_id, $sse_key) {
$params = new ParamCleaner(["sse_key" => $sse_key]);
return validatedSseKey($user_id, $params);
}
2021-01-03 12:29:41 +01:00
}
?>