Files
nextcloud-server-mirror/lib/public/OCM/Events/LocalOCMDiscoveryEvent.php
Micke Nordin ec9666640b feat(OCM): Make it possible to have a spec compliant discovery
The current discovery document have non standard elements, which are
required for backwards compatibility with old Nextcloud versions.

There may however be deployments, that are up to date, and do not require
backwards compatibility but instead value spec compliance and adding two
new knobs to LocalOCMDiscoveryEvent can make that happen.

The new knobs are removeVersion which removes the non standard version
field from the discovery and sets the correct apiVersion instead.
Nextcloud prior to version 28 had an equality check for apiVersion and
the hard coded string `1.0-proposal1` which is not at all the version
that Nextcloud actually supports.

Along side this change a new function removePublicKey is also added. The
publicKey in the discovery document is no longer used with the RFC9421
style http-signatures, and only the old legacy signatures use that key,
since version 35 Nextcloud supports RFC9421 signatures, and the legacy
publicKey can now be removed from the discovery if you don't require
backwards compatibility with older Nextcloud versions.

Fixes: #52754

Signed-off-by: Micke Nordin <kano@sunet.se>
2026-08-31 15:14:45 +02:00

98 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\OCM\Events;
use OCP\AppFramework\Attribute\Listenable;
use OCP\EventDispatcher\Event;
use OCP\OCM\IOCMProvider;
/**
* Use this event to register additional resources before the API returns
* them in the OCM provider list and capability
*
* @since 33.0.0
*
*/
#[Listenable(since: '33.0.0')]
class LocalOCMDiscoveryEvent extends Event {
/**
* @param IOCMProvider $provider
* @since 33.0.0
*/
public function __construct(
private readonly IOCMProvider $provider,
) {
parent::__construct();
}
/**
* Add a new OCM capability to the discovery data of local instance
*
* @since 33.0.0
*/
public function addCapability(string $capability): void {
$this->provider->setCapabilities([$capability]);
}
/**
* @param string $name
* @param list<string> $shareTypes List of supported share recipients, e.g. 'user', 'group', …
* @param array<string, string> $protocols List of supported protocols and their location,
* e.g. ['webdav' => '/remote.php/webdav/']
* @since 33.0.0
*/
public function registerResourceType(string $name, array $shareTypes, array $protocols): void {
$resourceType = $this->provider->createNewResourceType();
$resourceType->setName($name)
->setShareTypes($shareTypes)
->setProtocols($protocols);
$this->provider->addResourceType($resourceType);
}
/**
* Returns the ocm provider.
*
* @return IOCMProvider
*
* @since 35.0.0
*/
public function getProvider(): IOCMProvider {
return $this->provider;
}
/**
* Remove the non-standard publicKey field from OCM discovery
*
* @since 35.0.0
*/
public function removePublicKey(): void {
$this->provider->removePublicKey();
}
/**
* Remove the non-standard version field from OCM discovery
*
* @since 35.0.0
*/
public function removeVersion(): void {
$this->provider->removeVersion();
}
/**
* Set the apiVersion
*
* @param string $version
*
* @since 35.0.0
*/
public function setApiVersion(string $version): void {
$this->provider->setApiVersion($version);
}
}