API access when using LDAP authentication

This commit is contained in:
Ultra2D
2016-03-07 14:07:51 +01:00
parent 5e57a026e9
commit 322053c827
2 changed files with 7 additions and 2 deletions

View File

@ -15,12 +15,15 @@
require_once '../includes/functions.php';
require_once '../includes/component.php';
require_once '../includes/device-groups.inc.php';
if (file_exists('../html/includes/authentication/'.$config['auth_mechanism'].'.inc.php')) {
include '../html/includes/authentication/'.$config['auth_mechanism'].'.inc.php';
}
function authToken(\Slim\Route $route) {
$app = \Slim\Slim::getInstance();
$token = $app->request->headers->get('X-Auth-Token');
if (isset($token) && !empty($token)) {
$username = dbFetchCell('SELECT `U`.`username` FROM `api_tokens` AS AT JOIN `users` AS U ON `AT`.`user_id`=`U`.`user_id` WHERE `AT`.`token_hash`=?', array($token));
$username = get_user(dbFetchCell('SELECT `AT`.`user_id` FROM `api_tokens` AS AT WHERE `AT`.`token_hash`=?', array($token)));
if (!empty($username)) {
$authenticated = true;
}

View File

@ -189,7 +189,9 @@ function can_update_users() {
function get_user($user_id) {
// not supported
foreach (get_userlist() as $users) {
if ($users['user_id'] === $user_id) return $users['username'];
}
return 0;
}