diff --git a/developer_manual/app_publishing_maintenance/upgrade-guide.rst b/developer_manual/app_publishing_maintenance/upgrade-guide.rst index ba90325e180..c128ce78de6 100644 --- a/developer_manual/app_publishing_maintenance/upgrade-guide.rst +++ b/developer_manual/app_publishing_maintenance/upgrade-guide.rst @@ -24,6 +24,11 @@ Last version with database.xml support and migration Nextcloud 21 is the last major release that supports an app's ``appinfo/database.xml`` to :ref:`define the database schema`. This is your last change to :ref:`automatically convert this deprecated file into the new migration classes`. +Replaced well-known handler API +******************************* + +There was an old, unused and inofficial mechanism to hook into well-known discovery via config settings. This includes ``host-meta``, ``host-meta.json``, ``nodeinfo`` and ``webfinger``. A :ref:`new public API replaces this mechanism` in Nextcloud 21. + Upgrading to Nextcloud 20 ------------------------- diff --git a/developer_manual/digging_deeper/index.rst b/developer_manual/digging_deeper/index.rst index 384cffa9d43..65728fe1405 100644 --- a/developer_manual/digging_deeper/index.rst +++ b/developer_manual/digging_deeper/index.rst @@ -25,3 +25,4 @@ Digging deeper two-factor-provider users dashboard + web_host_metadata diff --git a/developer_manual/digging_deeper/web_host_metadata.rst b/developer_manual/digging_deeper/web_host_metadata.rst new file mode 100644 index 00000000000..482025ddc2b --- /dev/null +++ b/developer_manual/digging_deeper/web_host_metadata.rst @@ -0,0 +1,149 @@ +.. _web-host-metadata: + +================= +Web Host Metadata +================= + +`RFC6415`_ defines how web hosts can expose their metadata through resources. Starting with Nextcloud 21, it's possible to register handlers for HTTP requests to the ``.well-known/*`` route. + +Writing a handler +----------------- + +A well known handler is a simple class that implements the ``\OCP\Http\WellKnown\IHandler`` interface. + +.. code-block:: php + + 'hello']), + ); + } + } + + +Example webfinger handler +^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following example shows how an app could react to `RFC6415`_ webfinger requests: + +.. code-block:: php + + urlGenerator = $urlGenerator; + } + + public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { + if ($service !== 'webfinger') { + // Not relevant to this handler + + return $previousResponse; + } + + $subject = $context->getHttpRequest()->getParam('resource', ''); + $href = $this->urlGenerator->linkToRouteAbsolute('myapp.example.test'); + + // Use the previous response and amend it, if possible + $response = $previousResponse; + if (!($response instanceof JrdResponse)) { + // We override null or any other types + $response = new JrdResponse($subject); + } + + return $response->addLink('self', 'application/activity+json', $href); + } + } + +Handler registration +-------------------- + +The handler class is registered via the :ref:`bootstrap mechanism` of the ``Application`` class. + +.. code-block:: php + + + registerWellKnownHandler(Handler::class); + } + + public function boot(IBootContext $context): void {} + + } + + + +.. _`RFC6415`: https://tools.ietf.org/html/rfc6415 +.. _`RFC7033`: https://tools.ietf.org/html/rfc7033 \ No newline at end of file