feat: implement initial read only access

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-07 21:58:35 -04:00
parent 661e0e1213
commit 92e85aed47
17 changed files with 863 additions and 4 deletions
+6 -1
View File
@@ -9,6 +9,11 @@ use RuntimeException;
class DiscoveryClient
{
public function fetch(ServerAddress $server): DiscoveryDocument
{
return DiscoveryDocument::parse($this->fetchXml($server), $server);
}
public function fetchXml(ServerAddress $server): string
{
$curl = curl_init($server->discoveryUrl());
$xml = '';
@@ -36,7 +41,7 @@ class DiscoveryClient
throw new RuntimeException('Discovery returned HTTP ' . $status
. ($status === 404 ? '. Enable WOPI and forward /hosting/discovery through the proxy.' : '. Expected HTTP 200; redirects are not followed.'));
}
return DiscoveryDocument::parse($xml, $server);
return $xml;
} finally {
curl_close($curl);
}
+8 -2
View File
@@ -14,7 +14,7 @@ final readonly class DiscoveryDocument
public const MAX_BYTES = 2 * 1024 * 1024;
/** @param list<Action> $actions */
private function __construct(public array $actions, public bool $hasProofKeys) {}
private function __construct(public array $actions, public bool $hasProofKeys, public array $proofKeys = []) {}
public static function parse(string $xml, ServerAddress $server): self
{
@@ -52,8 +52,14 @@ final readonly class DiscoveryDocument
throw new RuntimeException('Discovery has no external view/edit actions. Check WOPI enablement and forwarded HTTPS headers.');
}
$proof = $xpath->query('/wopi-discovery/proof-key')->item(0);
$keys = [];
if ($proof instanceof DOMElement) {
foreach (['modulus', 'exponent', 'oldmodulus', 'oldexponent'] as $attribute) {
$keys[$attribute] = $proof->getAttribute($attribute);
}
}
return new self($actions, $proof instanceof DOMElement
&& $proof->getAttribute('modulus') !== '' && $proof->getAttribute('exponent') !== '');
&& $proof->getAttribute('modulus') !== '' && $proof->getAttribute('exponent') !== '', $keys);
} finally {
libxml_clear_errors();
libxml_use_internal_errors($previous);