Skip to content

Commit 1b8505a

Browse files
enriquepablomickenordin
authored andcommitted
fix: backwards compatibility for shares from instances before upgrading
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
1 parent 8ec6ad9 commit 1b8505a

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

apps/cloud_federation_api/lib/Controller/RequestHandlerController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
175175
}
176176

177177
$cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
178+
$shareWithCloudId = $shareWith; // preserve full cloud ID for factory capability discovery
178179
$shareWith = $cloudId->getUser();
179180

180181
if ($shareType === 'user') {
@@ -219,7 +220,10 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
219220

220221
try {
221222
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
222-
$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
223+
// Pass the original cloud ID so the factory can discover capabilities without warning.
224+
// Then reset shareWith to the local username that shareReceived() needs for user lookup.
225+
$share = $this->factory->getCloudFederationShare($shareWithCloudId, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
226+
$share->setShareWith($shareWith);
223227
$share->setProtocol($protocol);
224228
$provider->shareReceived($share);
225229
} catch (ProviderDoesNotExistsException|ProviderCouldNotAddShareException $e) {

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function shareReceived(ICloudFederationShare $share): string {
182182
$externalShare->setRemote($remote);
183183
$externalShare->setRemoteId($remoteId);
184184
$externalShare->setShareToken($token); // refresh token (sharedSecret)
185-
$externalShare->setPassword($accessToken); // access token (empty if no token exchange)
185+
$externalShare->setAccessToken($accessToken ?: null);
186186
$externalShare->setName($name);
187187
$externalShare->setOwner($owner);
188188
$externalShare->setShareType($shareType);

apps/files_sharing/lib/External/MountProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function getMount(IUser $user, array $data, IStorageFactory $storageFact
5959

6060
public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
6161
$qb = $this->connection->getQueryBuilder();
62-
$qb->select('id', 'remote', 'share_token', 'password', 'mountpoint', 'owner')
62+
$qb->select('id', 'remote', 'share_token', 'password', 'access_token', 'access_token_expires', 'mountpoint', 'owner')
6363
->from('share_external')
6464
->where($qb->expr()->eq('user', $qb->createNamedParameter($user->getUID())))
6565
->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED, IQueryBuilder::PARAM_INT)));
@@ -99,7 +99,7 @@ public function getMountsForPath(
9999
}
100100

101101
$qb = $this->connection->getQueryBuilder();
102-
$qb->select('id', 'remote', 'share_token', 'password', 'mountpoint', 'owner')
102+
$qb->select('id', 'remote', 'share_token', 'password', 'access_token', 'access_token_expires', 'mountpoint', 'owner')
103103
->from('share_external')
104104
->where($qb->expr()->eq('user', $qb->createNamedParameter($user->getUID())))
105105
->andWhere($qb->expr()->eq('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED, IQueryBuilder::PARAM_INT)));

apps/files_sharing/lib/External/Storage.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,16 @@ public function __construct($options) {
8383
$webDavEndpoint = $ocmProvider->extractProtocolEntry('file', 'webdav');
8484
$remote = $ocmProvider->getEndPoint();
8585
$authType = \Sabre\DAV\Client::AUTH_BASIC;
86-
$capabilities = $ocmProvider->getCapabilities();
87-
if (in_array('exchange-token', $capabilities)) {
88-
$authType = \OC\Files\Storage\BearerAuthAwareSabreClient::AUTH_BEARER;
89-
}
9086
} catch (OCMProviderException|OCMArgumentException $e) {
9187
$this->logger->notice('exception while retrieving webdav endpoint', ['exception' => $e]);
9288
$webDavEndpoint = '/public.php/webdav';
9389
$remote = $this->cloudId->getRemote();
9490
$authType = \Sabre\DAV\Client::AUTH_BASIC;
9591
}
9692

97-
// If we have a stored access token, use Bearer auth regardless of discovery.
98-
// This handles the case where the share was created with must-exchange-token.
93+
// Only use Bearer auth when an access token is already stored.
94+
// Shares created before the exchange-token capability was introduced have no
95+
// stored token and must keep using basic auth for backwards compatibility.
9996
if (!empty($options['access_token'])) {
10097
$authType = \OC\Files\Storage\BearerAuthAwareSabreClient::AUTH_BEARER;
10198
}

0 commit comments

Comments
 (0)