API: New classes for OAuth and basic auth

This commit is contained in:
Michael 2021-06-08 06:32:24 +00:00
parent 246aa293d1
commit acbe9ebf9e
9 changed files with 346 additions and 178 deletions

View file

@ -35,16 +35,15 @@ class Index extends BaseApi
{
public static function rawContent(array $parameters = [])
{
if (self::login(self::SCOPE_READ) === false) {
throw new HTTPException\ForbiddenException();
}
self::login(self::SCOPE_READ);
$uid = self::getCurrentUserID();
$request = self::getRequest([
'since_id' => 0,
'count' => 0,
]);
$condition = ["`id` > ? AND `uid` = ?", $request['since_id'], self::$current_user_id];
$condition = ["`id` > ? AND `uid` = ?", $request['since_id'], $uid];
$params = ['limit' => $request['count']];
$events = DBA::selectToArray('event', [], $condition, $params);

View file

@ -37,16 +37,15 @@ class Show extends BaseApi
{
public static function rawContent(array $parameters = [])
{
if (self::login(self::SCOPE_READ) === false) {
throw new HTTPException\ForbiddenException();
}
self::login(self::SCOPE_READ);
$uid = self::getCurrentUserID();
// retrieve general information about profiles for user
$directory = DI::config()->get('system', 'directory');
$profile = Profile::getByUID(self::$current_user_id);
$profile = Profile::getByUID($uid);
$profileFields = DI::profileField()->select(['uid' => self::$current_user_id, 'psid' => PermissionSet::PUBLIC]);
$profileFields = DI::profileField()->select(['uid' => $uid, 'psid' => PermissionSet::PUBLIC]);
$profile = self::formatProfile($profile, $profileFields);
@ -58,7 +57,7 @@ class Show extends BaseApi
}
// return settings, authenticated user and profiles data
$self = Contact::selectFirst(['nurl'], ['uid' => self::$current_user_id, 'self' => true]);
$self = Contact::selectFirst(['nurl'], ['uid' => $uid, 'self' => true]);
$result = [
'multi_profiles' => false,

View file

@ -54,7 +54,7 @@ abstract class ContactEndpoint extends BaseApi
*/
protected static function getUid(int $contact_id = null, string $screen_name = null)
{
$uid = self::$current_user_id;
$uid = self::getCurrentUserID();
if ($contact_id || $screen_name) {
// screen_name trumps user_id when both are provided
@ -129,7 +129,7 @@ abstract class ContactEndpoint extends BaseApi
protected static function ids($rel, int $uid, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $stringify_ids = false)
{
$hide_friends = false;
if ($uid != self::$current_user_id) {
if ($uid != self::getCurrentUserID()) {
$profile = Profile::getByUID($uid);
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Profile not found'));