-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
- Loading branch information
1 parent
f07c9bb
commit 0037bb3
Showing
6 changed files
with
82 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace OCA\Social\WellKnown; | ||
|
||
use OCA\Social\Db\CacheActorsRequest; | ||
use OCA\Social\Exceptions\CacheActorDoesNotExistException; | ||
use OCA\Social\Service\CacheActorService; | ||
use OCA\Social\Service\ConfigService; | ||
use OCA\Social\Service\FediverseService; | ||
use OCP\Http\WellKnown\IHandler; | ||
use OCP\Http\WellKnown\IRequestContext; | ||
use OCP\Http\WellKnown\IResponse; | ||
use OCP\Http\WellKnown\JrdResponse; | ||
use OCP\IURLGenerator; | ||
|
||
class WebfingerHandler implements IHandler { | ||
private IURLGenerator $urlGenerator; | ||
private CacheActorsRequest $cacheActorsRequest; | ||
private CacheActorService $cacheActorService; | ||
private FediverseService $fediverseService; | ||
private ConfigService $configService; | ||
|
||
public function __construct( | ||
IURLGenerator $urlGenerator, CacheActorsRequest $cacheActorsRequest, | ||
CacheActorService $cacheActorService, FediverseService $fediverseService, | ||
ConfigService $configService | ||
) { | ||
|
||
$this->urlGenerator = $urlGenerator; | ||
$this->cacheActorsRequest = $cacheActorsRequest; | ||
$this->cacheActorService = $cacheActorService; | ||
$this->fediverseService = $fediverseService; | ||
$this->configService = $configService; | ||
} | ||
|
||
public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { | ||
// See https://docs.joinmastodon.org/spec/webfinger/ | ||
|
||
$this->fediverseService->jailed(); | ||
$subject = $context->getHttpRequest()->getParam('resource'); | ||
|
||
if (strpos($subject, 'acct:') === 0) { | ||
$subject = substr($subject, 5); | ||
} | ||
|
||
try { | ||
$actor = $this->cacheActorService->getFromLocalAccount($subject); | ||
} catch (CacheActorDoesNotExistException $e) { | ||
$actor = $this->cacheActorsRequest->getFromId($subject); | ||
if (!$actor->isLocal()) { | ||
throw new CacheActorDoesNotExistException(); | ||
} | ||
} | ||
|
||
$response = new JrdResponse($subject); | ||
|
||
// ActivityPub profile | ||
$href = $this->configService->getSocialUrl() . '@' . $actor->getPreferredUsername(); | ||
$href = rtrim($href, '/'); | ||
$response->addAlias($href); | ||
$response->addLink('self', 'application/activity+json', $href); | ||
|
||
// Nextcloud profile page | ||
$profilePageUrl = $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', [ | ||
'targetUserId' => $actor->getPreferredUsername() | ||
]); | ||
$response->addAlias($profilePageUrl); | ||
$response->addLink('http://webfinger.net/rel/profile-page', 'text/html', $profilePageUrl); | ||
|
||
// Ostatus subscribe url | ||
// JrdResponse doesn't support template | ||
// $subscribe = $this->urlGenerator->linkToRouteAbsolute('social.OStatus.subscribe') . '?uri={uri}'; | ||
// $response->addLink('http://ostatus.org/schema/1.0/subscribe', $subscribe); | ||
|
||
return $response; | ||
} | ||
} |
Oops, something went wrong.