mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #56341 from nextcloud/backport/55648/stable32
[stable32] fix(ocm): align discovery process with OCM spec
This commit is contained in:
commit
1195fa3ec5
1 changed files with 34 additions and 10 deletions
|
|
@ -103,22 +103,46 @@ class OCMDiscoveryService implements IOCMDiscoveryService {
|
|||
if ($this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates') === true) {
|
||||
$options['verify'] = false;
|
||||
}
|
||||
$response = $client->get($remote . '/ocm-provider/', $options);
|
||||
$urls = [
|
||||
$remote . '/.well-known/ocm',
|
||||
$remote . '/ocm-provider',
|
||||
];
|
||||
|
||||
$body = null;
|
||||
if ($response->getStatusCode() === Http::STATUS_OK) {
|
||||
$body = $response->getBody();
|
||||
// update provider with data returned by the request
|
||||
$provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []);
|
||||
$this->cache->set($remote, $body, 60 * 60 * 24);
|
||||
$this->remoteProviders[$remote] = $provider;
|
||||
return $provider;
|
||||
|
||||
foreach ($urls as $url) {
|
||||
$exception = null;
|
||||
$body = null;
|
||||
$status = null;
|
||||
try {
|
||||
$response = $client->get($url, $options);
|
||||
if ($response->getStatusCode() === Http::STATUS_OK) {
|
||||
$body = $response->getBody();
|
||||
$status = $response->getStatusCode();
|
||||
// update provider with data returned by the request
|
||||
$provider->import(json_decode($body, true, 8, JSON_THROW_ON_ERROR) ?? []);
|
||||
$this->cache->set($remote, $body, 60 * 60 * 24);
|
||||
$this->remoteProviders[$remote] = $provider;
|
||||
return $provider;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->debug("Tried unsuccesfully to do discovery at: {$url}", [
|
||||
'exception' => $e,
|
||||
'remote' => $remote
|
||||
]);
|
||||
// We want to throw only the last exception
|
||||
$exception = $e;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($exception) {
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
|
||||
throw new OCMProviderException('invalid remote ocm endpoint');
|
||||
} catch (JsonException|OCMProviderException) {
|
||||
$this->cache->set($remote, false, 5 * 60);
|
||||
throw new OCMProviderException('data returned by remote seems invalid - status:' . $response->getStatusCode() . ' - ' . ($body ?? ''));
|
||||
throw new OCMProviderException('data returned by remote seems invalid - status: ' . ($status ?? '') . ' - body: ' . ($body ?? ''));
|
||||
} catch (\Exception $e) {
|
||||
$this->cache->set($remote, false, 5 * 60);
|
||||
$this->logger->warning('error while discovering ocm provider', [
|
||||
|
|
|
|||
Loading…
Reference in a new issue