-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathkey.php
More file actions
executable file
·63 lines (52 loc) · 1.45 KB
/
key.php
File metadata and controls
executable file
·63 lines (52 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* @package Techjoomla.API
* @copyright Copyright (C) 2009-2017 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://techjoomla.com
* Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API)
* and the com_api extension by Brian Edgerton (http://www.edgewebworks.com)
*/
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
/**
* API resource class
*
* @since 1.0
*/
class ApiAuthenticationKey extends ApiAuthentication
{
protected $auth_method = null;
protected $domain_checking = null;
/**
* Authenticate the user using the key in the header or request
*
* @return int|boolean User id of the user or false
*/
public function authenticate()
{
$header_token = $this->getBearerToken();
$token = $this->loadTokenByHash($header_token);
if (isset($token->state) && $token->state == 1)
{
$userId = parent::getUserIdToImpersonate($token->userid);
return $userId ? $userId : $token->userid;
}
$this->setError(Text::_('COM_API_KEY_NOT_FOUND'));
return false;
}
/**
* Load a token row using hash
*
* @param STRING $hash The token hash
*
* @return OBJECT|boolean
*/
public function loadTokenByHash($hash)
{
$table = Table::getInstance('Key', 'ApiTable');
$table->loadByHash($hash);
return $table;
}
}