28 $this->db = $service->getDb();
40 if (!isset($options[
"login"]) || !is_string($options[
"login"])) {
41 throw new \Exception(
"Missing required parameter login", self::ERR_INVALID_ARGUMENT);
43 if (!isset($options[
"secret"]) || !is_string($options[
"secret"])) {
44 throw new \Exception(
"Missing required parameter secret", self::ERR_INVALID_ARGUMENT);
46 if (!preg_match(
"#^[0-9a-zA-Z]{32}$#", $options[
"secret"])) {
47 return new Alternc_Api_Response(array(
"code" => self::ERR_INVALID_SECRET,
"message" =>
"Invalid shared secret syntax"));
50 if (!preg_match(
"#^[0-9a-zA-Z-]{1,32}$#", $options[
"login"])) {
51 return new Alternc_Api_Response(array(
"code" => self::ERR_INVALID_LOGIN,
"message" =>
"Invalid login"));
54 $stmt = $this->db->prepare(
"SELECT m.enabled,m.uid,m.login,m.su FROM membres m, sharedsecret s WHERE s.uid=m.uid AND m.login=? AND s.secret=?;");
55 $stmt->execute(array($options[
"login"], $options[
"secret"]));
56 $me = $stmt->fetch(PDO::FETCH_OBJ);
58 return new Alternc_Api_Response(array(
"code" => self::ERR_INVALID_AUTH,
"message" =>
"Invalid shared secret"));
60 return new Alternc_Api_Response(array(
"code" => self::ERR_DISABLED_ACCOUNT,
"message" =>
"Account is disabled"));
63 array(
"uid" => (
int) $me->uid,
"isAdmin" => ($me->su != 0)), $this->db
72 return array(
"fields" => array(
"login" =>
"AlternC user account",
"secret" =>
"API Key, Shared secrets, valid for this account, stored in sharedsecret table."),
73 "description" =>
"Authenticate against an Api Key, also called SharedSecret. distinct from the account's password, can be plenty and revoked independently"
Authentication API used by server to authenticate a user using a SHARED SECRET (ApiKey)
const ERR_INVALID_ARGUMENT
__construct($service)
Constructor of the Shared Secret Api Auth.
const ERR_DISABLED_ACCOUNT
auth($options)
Authenticate a user.
instructions()
instructions on how to use this Auth class
Standard Response object for the AlternC API.
Service API used by server to export API methods this class can be used to implement an API service /...
static tokenGenerate($options, $db)
Create a new token in the DB for the associated user/admin.
Authentication API used by server to authenticate a user using a specific method.