<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
return (int)self::$current_user_id;
}
+ public static function setCurrentUserID(int $uid = null)
+ {
+ self::$current_user_id = $uid;
+ }
+
/**
* Fetch a dummy application token
*
return [];
}
- if (!empty(self::$current_token)) {
- return self::$current_token;
- }
+ //if (!empty(self::$current_token)) {
+ // return self::$current_token;
+ //}
$source = $_REQUEST['source'] ?? '';
private static function getUserIdByAuth(bool $do_login = true):int
{
$a = DI::app();
- Session::set('allow_api', false);
self::$current_user_id = 0;
// workaround for HTTP-auth in CGI mode
return 0;
}
Logger::debug('Access denied', ['parameters' => $_SERVER]);
- header('WWW-Authenticate: Basic realm="Friendica"');
+ // Checking for commandline for the tests, we have to avoid to send a header
+ if (php_sapi_name() !== 'cli') {
+ header('WWW-Authenticate: Basic realm="Friendica"');
+ }
throw new UnauthorizedException("This API requires login");
}
DI::auth()->setForUser($a, $record, false, false, $login_refresh);
- Session::set('allow_api', true);
-
Hook::callAll('logged_in', $record);
- if (Session::get('allow_api')) {
- self::$current_user_id = local_user();
- } else {
- self::$current_user_id = 0;
- }
+ self::$current_user_id = local_user();
+
return self::$current_user_id;
}
}