allow other apps to register webfinger

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1749/head
Maxence Lange 2023-06-20 09:02:58 -01:00
rodzic 6f51c1b29a
commit cbeefae898
18 zmienionych plików z 76 dodań i 46 usunięć

Wyświetl plik

@ -6,7 +6,7 @@
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
<description><![CDATA[
** Disclaimer: this is an BETA version **
** Disclaimer: this is a BETA version **
**🎉 Nextcloud becomes part of the federated social networks!**

Wyświetl plik

@ -53,10 +53,13 @@ require_once __DIR__ . '/../../vendor/autoload.php';
* @package OCA\Social\AppInfo
*/
class Application extends App implements IBootstrap {
public const APP_NAME = 'social';
public const APP_ID = 'social';
public const APP_NAME = 'Social';
public const APP_SUBJECT = 'http://nextcloud.com/';
public const APP_REL = 'https://apps.nextcloud.com/apps/social';
public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);
parent::__construct(self::APP_ID, $params);
}
public function register(IRegistrationContext $context): void {

Wyświetl plik

@ -89,7 +89,7 @@ class ActivityPubController extends Controller {
ConfigService $configService,
LoggerInterface $logger
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->socialPubController = $socialPubController;
$this->fediverseService = $fediverseService;

Wyświetl plik

@ -113,7 +113,7 @@ class ApiController extends Controller {
PostService $postService,
ConfigService $configService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->urlGenerator = $urlGenerator;
$this->userSession = $userSession;

Wyświetl plik

@ -91,7 +91,7 @@ class LocalController extends Controller {
BoostService $boostService, LikeService $likeService, DocumentService $documentService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->userId = $userId;
$this->cacheActorService = $cacheActorService;

Wyświetl plik

@ -90,7 +90,7 @@ class NavigationController extends Controller {
CheckService $checkService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->userId = $userId;
$this->l10n = $l10n;
@ -140,8 +140,8 @@ class NavigationController extends Controller {
if ($cloudAddress !== null) {
$this->configService->setCloudUrl($cloudAddress);
} else {
$this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData);
return new TemplateResponse(Application::APP_NAME, 'main');
$this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', $serverData);
return new TemplateResponse(Application::APP_ID, 'main');
}
}
}
@ -172,8 +172,8 @@ class NavigationController extends Controller {
$serverData['checks'] = $checks;
}
$this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData);
return new TemplateResponse(Application::APP_NAME, 'main');
$this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', $serverData);
return new TemplateResponse(Application::APP_ID, 'main');
}
private function setupCloudAddress(): string {

Wyświetl plik

@ -71,7 +71,7 @@ class OAuthController extends Controller {
LoggerInterface $logger,
IInitialState $initialState
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
@ -187,7 +187,7 @@ class OAuthController extends Controller {
$client = $this->clientService->getFromClientId($client_id);
$this->initialState->provideInitialState('appName', $client->getAppName());
return new TemplateResponse(Application::APP_NAME, 'oauth2', [
return new TemplateResponse(Application::APP_ID, 'oauth2', [
'request' =>
[
'clientId' => $client_id,

Wyświetl plik

@ -64,7 +64,7 @@ class OStatusController extends Controller {
IRequest $request, IInitialStateService $initialStateService, CacheActorService $cacheActorService, AccountService $accountService,
CurlService $curlService, MiscService $miscService, IUserSession $userSession
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->initialStateService = $initialStateService;
$this->cacheActorService = $cacheActorService;

Wyświetl plik

@ -56,7 +56,7 @@ class QueueController extends Controller {
IRequest $request, RequestQueueService $requestQueueService, ActivityService $activityService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->requestQueueService = $requestQueueService;
$this->activityService = $activityService;

Wyświetl plik

@ -74,7 +74,7 @@ class SocialPubController extends Controller {
CacheActorService $cacheActorService, AccountService $accountService, StreamService $streamService,
ConfigService $configService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->userId = $userId;
$this->initialStateService = $initialStateService;
@ -113,7 +113,7 @@ class SocialPubController extends Controller {
$this->initialStateService->provideInitialState('social', 'serverData', [
'public' => true,
]);
$page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data);
$page = new PublicTemplateResponse(Application::APP_ID, 'main', $data);
$page->setStatus($status);
$page->setHeaderTitle($this->l10n->t('Social'));
@ -190,10 +190,10 @@ class SocialPubController extends Controller {
'application' => 'Social'
];
$this->initialStateService->provideInitialState(Application::APP_NAME, 'item', $stream);
$this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', [
$this->initialStateService->provideInitialState(Application::APP_ID, 'item', $stream);
$this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', [
'public' => ($this->userId === null),
]);
return new TemplateResponse(Application::APP_NAME, 'main', $data);
return new TemplateResponse(Application::APP_ID, 'main', $data);
}
}

Wyświetl plik

@ -79,7 +79,7 @@ class SocialWidget implements IWidget {
* @inheritDoc
*/
public function load(): void {
\OCP\Util::addScript(Application::APP_NAME, 'social-dashboard');
\OCP\Util::addStyle(Application::APP_NAME, 'dashboard');
\OCP\Util::addScript(Application::APP_ID, 'social-dashboard');
\OCP\Util::addStyle(Application::APP_ID, 'dashboard');
}
}

Wyświetl plik

@ -76,7 +76,7 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getID(): string {
return Application::APP_NAME;
return Application::APP_ID;
}
/**
@ -97,11 +97,11 @@ class Notifier implements INotifier {
* @throws InvalidArgumentException
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== Application::APP_NAME) {
if ($notification->getApp() !== Application::APP_ID) {
throw new InvalidArgumentException();
}
$l10n = $this->factory->get(Application::APP_NAME, $languageCode);
$l10n = $this->factory->get(Application::APP_ID, $languageCode);
$notification->setIcon(
$this->url->getAbsoluteURL($this->url->imagePath('social', 'social_dark.svg'))

Wyświetl plik

@ -97,7 +97,7 @@ class ContactsMenuProvider implements IProvider {
'social.ActivityPub.actorAlias', ['username' => $actor->getPreferredUsername()]
);
$action = $this->actionFactory->newLinkAction($icon, $action, $link, Application::APP_NAME);
$action = $this->actionFactory->newLinkAction($icon, $action, $link, Application::APP_ID);
$entry->addAction($action);
} catch (Exception $e) {
return;

Wyświetl plik

@ -132,7 +132,7 @@ class ConfigService {
$defaultValue = $this->defaults[$key];
}
return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
return $this->config->getAppValue(Application::APP_ID, $key, $defaultValue);
}
/**
@ -148,7 +148,7 @@ class ConfigService {
$defaultValue = $this->defaults[$key];
}
return (int)$this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
return (int)$this->config->getAppValue(Application::APP_ID, $key, $defaultValue);
}
/**
@ -160,7 +160,7 @@ class ConfigService {
* @return void
*/
public function setAppValue($key, $value) {
$this->config->setAppValue(Application::APP_NAME, $key, $value);
$this->config->setAppValue(Application::APP_ID, $key, $value);
}
/**
@ -171,7 +171,7 @@ class ConfigService {
* @return string
*/
public function deleteAppValue($key) {
return $this->config->deleteAppValue(Application::APP_NAME, $key);
return $this->config->deleteAppValue(Application::APP_ID, $key);
}
/**
@ -190,7 +190,7 @@ class ConfigService {
$defaultValue = '';
if ($app === '') {
$app = Application::APP_NAME;
$app = Application::APP_ID;
if (array_key_exists($key, $this->defaults)) {
$defaultValue = $this->defaults[$key];
}
@ -209,7 +209,7 @@ class ConfigService {
* @throws PreConditionNotMetException
*/
public function setUserValue($key, $value) {
return $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
return $this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
}
/**
@ -221,7 +221,7 @@ class ConfigService {
* @return string
*/
public function getValueForUser($userId, $key) {
return $this->config->getUserValue($userId, Application::APP_NAME, $key);
return $this->config->getUserValue($userId, Application::APP_ID, $key);
}
/**
@ -235,7 +235,7 @@ class ConfigService {
* @throws PreConditionNotMetException
*/
public function setValueForUser($userId, $key, $value) {
return $this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
return $this->config->setUserValue($userId, Application::APP_ID, $key, $value);
}
@ -268,7 +268,7 @@ class ConfigService {
*
*/
public function unsetAppConfig() {
$this->config->deleteAppValues(Application::APP_NAME);
$this->config->deleteAppValues(Application::APP_ID);
}

Wyświetl plik

@ -62,7 +62,7 @@ class InstanceService {
public function createLocal(): Instance {
$instance = new Instance();
$instance->setLocal(true)
->setVersion($this->config->getAppValue(Application::APP_NAME, 'installed_version', '0.0'))
->setVersion($this->config->getAppValue(Application::APP_ID, 'installed_version', '0.0'))
->setApprovalRequired(false)
->setDescription($this->config->getAppValue('theming', 'slogan', 'a safe home for your data'))
->setTitle($this->config->getAppValue('theming', 'name', 'Nextcloud Social'));

Wyświetl plik

@ -58,7 +58,7 @@ class MiscService {
*/
public function log(string $message, $level = 2) {
$data = array(
'app' => Application::APP_NAME,
'app' => Application::APP_ID,
'level' => $level
);

Wyświetl plik

@ -581,7 +581,7 @@ class SignatureService {
private static function getContextCacheFolder(): ISimpleFolder {
$path = 'context';
$appData = Server::get(IAppDataFactory::class)->get(Application::APP_NAME);
$appData = Server::get(IAppDataFactory::class)->get(Application::APP_ID);
try {
$folder = $appData->getFolder($path);
} catch (NotFoundException $e) {

Wyświetl plik

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Social\WellKnown;
use OCA\Social\AppInfo\Application;
use OCA\Social\Db\CacheActorsRequest;
use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
@ -76,21 +77,29 @@ class WebfingerHandler implements IHandler {
try {
$this->fediverseService->jailed();
} catch (UnauthorizedFediverseException $e) {
return null;
return $previousResponse;
}
$response = null;
switch (strtolower($service)) {
case 'webfinger':
return $this->handleWebfinger($context);
$response = $this->handleWebfinger($context, $previousResponse);
break;
case 'nodeinfo':
return $this->handleNodeInfo($context);
$response = $this->handleNodeInfo($context);
break;
case 'host-meta':
return $this->handleHostMeta($context);
$response = $this->handleHostMeta($context);
break;
}
return null;
if ($response !== null) {
return $response;
}
return $previousResponse;
}
@ -101,16 +110,34 @@ class WebfingerHandler implements IHandler {
*
* @return IResponse|null
*/
public function handleWebfinger(IRequestContext $context): ?IResponse {
public function handleWebfinger(IRequestContext $context, ?IResponse $previousResponse): ?IResponse {
$subject = $context->getHttpRequest()->getParam('resource') ?? '';
if (strpos($subject, 'acct:') === 0) {
if (str_starts_with($subject, 'acct:')) {
$subject = substr($subject, 5);
}
if ($subject === Application::APP_SUBJECT) {
if ($previousResponse !== null && method_exists($previousResponse, 'addLink')) {
$previousResponse->addLink(
Application::APP_REL,
'application/json',
$this->urlGenerator->linkToRouteAbsolute('social.Navigation.navigate'),
[],
[
'app' => Application::APP_ID,
'name' => Application::APP_NAME,
'version' => $this->configService->getAppValue('installed_version'),
]
);
}
return $previousResponse;
}
$actor = null;
try {
$actor = $this->cacheActorService->getFromLocalAccount($subject);
} catch (ActorDoesNotExistException | SocialAppConfigException $e) {
} catch (ActorDoesNotExistException|SocialAppConfigException $e) {
return null;
} catch (CacheActorDoesNotExistException $e) {
}