Support signed outbox requests
This commit is contained in:
parent
a5be6f9276
commit
bdd834d313
3 changed files with 27 additions and 13 deletions
|
@ -22,10 +22,10 @@
|
||||||
namespace Friendica\Module;
|
namespace Friendica\Module;
|
||||||
|
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Core\System;
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
use Friendica\Util\HTTPSignature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Outbox
|
* ActivityPub Outbox
|
||||||
|
@ -48,11 +48,8 @@ class Outbox extends BaseModule
|
||||||
|
|
||||||
$page = $_REQUEST['page'] ?? null;
|
$page = $_REQUEST['page'] ?? null;
|
||||||
|
|
||||||
/// @todo Add Authentication to enable fetching of non public content
|
$requester = HTTPSignature::getSigner('', $_SERVER);
|
||||||
// $requester = HTTPSignature::getSigner('', $_SERVER);
|
$outbox = ActivityPub\Transmitter::getOutbox($owner, $page, $requester);
|
||||||
|
|
||||||
$outbox = ActivityPub\Transmitter::getOutbox($owner, $page);
|
|
||||||
|
|
||||||
header('Content-Type: application/activity+json');
|
header('Content-Type: application/activity+json');
|
||||||
echo json_encode($outbox);
|
echo json_encode($outbox);
|
||||||
exit();
|
exit();
|
||||||
|
|
|
@ -142,19 +142,36 @@ class Transmitter
|
||||||
* Public posts for the given owner
|
* Public posts for the given owner
|
||||||
*
|
*
|
||||||
* @param array $owner Owner array
|
* @param array $owner Owner array
|
||||||
* @param integer $page Page numbe
|
* @param integer $page Page number
|
||||||
|
* @param string $requester URL of requesting account
|
||||||
*
|
*
|
||||||
* @return array of posts
|
* @return array of posts
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function getOutbox($owner, $page = null)
|
public static function getOutbox($owner, $page = null, $requester = '')
|
||||||
{
|
{
|
||||||
$public_contact = Contact::getIdForURL($owner['url']);
|
$public_contact = Contact::getIdForURL($owner['url']);
|
||||||
|
$condition = ['uid' => 0, 'contact-id' => $public_contact,
|
||||||
|
'private' => [Item::PUBLIC, Item::UNLISTED]];
|
||||||
|
|
||||||
|
if (!empty($requester)) {
|
||||||
|
$requester_id = Contact::getIdForURL($requester, $owner['uid']);
|
||||||
|
if (!empty($requester_id)) {
|
||||||
|
$permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']);
|
||||||
|
if (!empty($permissionSets)) {
|
||||||
|
$condition = ['uid' => $owner['uid'], 'origin' => true,
|
||||||
|
'psid' => array_merge($permissionSets->column('id'),
|
||||||
|
[DI::permissionSet()->getIdFromACL($owner['uid'], '', '', '', '')])];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$condition = array_merge($condition,
|
||||||
|
['author-id' => $public_contact,
|
||||||
|
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
|
||||||
|
'deleted' => false, 'visible' => true, 'moderated' => false]);
|
||||||
|
|
||||||
$condition = ['uid' => 0, 'contact-id' => $public_contact, 'author-id' => $public_contact,
|
|
||||||
'private' => [Item::PUBLIC, Item::UNLISTED], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
|
|
||||||
'deleted' => false, 'visible' => true, 'moderated' => false];
|
|
||||||
$count = DBA::count('item', $condition);
|
$count = DBA::count('item', $condition);
|
||||||
|
|
||||||
$data = ['@context' => ActivityPub::CONTEXT];
|
$data = ['@context' => ActivityPub::CONTEXT];
|
||||||
|
|
|
@ -484,7 +484,7 @@ class HTTPSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
$headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI'];
|
$headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . parse_url($http_headers['REQUEST_URI'], PHP_URL_PATH);
|
||||||
|
|
||||||
// First take every header
|
// First take every header
|
||||||
foreach ($http_headers as $k => $v) {
|
foreach ($http_headers as $k => $v) {
|
||||||
|
|
Loading…
Reference in a new issue