generated from Nodarx/template
feat: implement initial read only access
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user