C2S: Posting is now possible

This commit is contained in:
Michael 2023-02-12 14:18:03 +00:00
parent 02f6d0e5f9
commit edb1ce0417
5 changed files with 243 additions and 23 deletions

View file

@ -26,6 +26,7 @@ use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
/**
* ActivityPub Outbox
@ -55,4 +56,30 @@ class Outbox extends BaseApi
System::jsonExit($outbox, 'application/activity+json');
}
protected function post(array $request = [])
{
self::checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
$postdata = Network::postdata();
if (empty($postdata) || empty($this->parameters['nickname'])) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$owner = User::getOwnerDataByNick($this->parameters['nickname']);
if (empty($owner)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
if ($owner['uid'] != $uid) {
throw new \Friendica\Network\HTTPException\ForbiddenException();
}
$activity = json_decode($postdata, true);
if (empty($activity)) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
ActivityPub\Receiver::processC2SActivity($activity, $uid, self::getCurrentApplication() ?? []);
}
}

View file

@ -96,7 +96,7 @@ class Whoami extends BaseApi
'oauthRegistrationEndpoint' => DI::baseUrl() . '/api/v1/apps',
'oauthTokenEndpoint' => DI::baseUrl() . '/oauth/token',
'sharedInbox' => DI::baseUrl() . '/inbox',
'uploadMedia' => DI::baseUrl() . '/api/upload_media' // @todo Endpoint does not exist at the moment
// 'uploadMedia' => DI::baseUrl() . '/api/upload_media' // @todo Endpoint does not exist at the moment
];
$data['generator'] = ActivityPub\Transmitter::getService();