Browse Source
fix(oauth2): retain support for legacy ownCloud clients
fix(oauth2): retain support for legacy ownCloud clients
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>pull/50858/head
No known key found for this signature in database
GPG Key ID: 27137D9E7D273FB2
17 changed files with 264 additions and 13 deletions
-
3apps/dav/appinfo/v1/webdav.php
-
10apps/dav/lib/Connector/Sabre/BearerAuth.php
-
3apps/dav/lib/Server.php
-
8apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
-
4apps/oauth2/appinfo/info.xml
-
1apps/oauth2/composer/composer/autoload_classmap.php
-
1apps/oauth2/composer/composer/autoload_static.php
-
76apps/oauth2/lib/Command/ImportLegacyOcClient.php
-
15apps/oauth2/lib/Controller/LoginRedirectorController.php
-
9apps/oauth2/openapi.json
-
84apps/oauth2/tests/Controller/LoginRedirectorControllerTest.php
-
20core/Controller/ClientFlowLoginController.php
-
2core/templates/loginflow/authpicker.php
-
1core/templates/loginflow/grant.php
-
21lib/private/Repair/Owncloud/MigrateOauthTables.php
-
9openapi.json
-
10tests/Core/Controller/ClientFlowLoginControllerTest.php
@ -0,0 +1,76 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/** |
|||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
|
|||
namespace OCA\OAuth2\Command; |
|||
|
|||
use OCA\OAuth2\Db\Client; |
|||
use OCA\OAuth2\Db\ClientMapper; |
|||
use OCP\IConfig; |
|||
use OCP\Security\ICrypto; |
|||
use Symfony\Component\Console\Command\Command; |
|||
use Symfony\Component\Console\Input\InputArgument; |
|||
use Symfony\Component\Console\Input\InputInterface; |
|||
use Symfony\Component\Console\Output\OutputInterface; |
|||
|
|||
class ImportLegacyOcClient extends Command { |
|||
private const ARGUMENT_CLIENT_ID = 'client-id'; |
|||
private const ARGUMENT_CLIENT_SECRET = 'client-secret'; |
|||
|
|||
public function __construct( |
|||
private readonly IConfig $config, |
|||
private readonly ICrypto $crypto, |
|||
private readonly ClientMapper $clientMapper, |
|||
) { |
|||
parent::__construct(); |
|||
} |
|||
|
|||
protected function configure(): void { |
|||
$this->setName('oauth2:import-legacy-oc-client'); |
|||
$this->setDescription('This command is only required to be run on instances which were migrated from ownCloud without the oauth2.enable_oc_clients system config! Import a legacy Oauth2 client from an ownCloud instance and migrate it. The data is expected to be straight out of the database table oc_oauth2_clients.'); |
|||
$this->addArgument( |
|||
self::ARGUMENT_CLIENT_ID, |
|||
InputArgument::REQUIRED, |
|||
'Value of the "identifier" column', |
|||
); |
|||
$this->addArgument( |
|||
self::ARGUMENT_CLIENT_SECRET, |
|||
InputArgument::REQUIRED, |
|||
'Value of the "secret" column', |
|||
); |
|||
} |
|||
|
|||
public function isEnabled(): bool { |
|||
return $this->config->getSystemValueBool('oauth2.enable_oc_clients', false); |
|||
} |
|||
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int { |
|||
/** @var string $clientId */ |
|||
$clientId = $input->getArgument(self::ARGUMENT_CLIENT_ID); |
|||
|
|||
/** @var string $clientSecret */ |
|||
$clientSecret = $input->getArgument(self::ARGUMENT_CLIENT_SECRET); |
|||
|
|||
// Should not happen but just to be sure
|
|||
if (empty($clientId) || empty($clientSecret)) { |
|||
return 1; |
|||
} |
|||
|
|||
$hashedClientSecret = bin2hex($this->crypto->calculateHMAC($clientSecret)); |
|||
|
|||
$client = new Client(); |
|||
$client->setName('ownCloud Desktop Client'); |
|||
$client->setRedirectUri('http://localhost:*'); |
|||
$client->setClientIdentifier($clientId); |
|||
$client->setSecret($hashedClientSecret); |
|||
$this->clientMapper->insert($client); |
|||
|
|||
$output->writeln('<info>Client imported successfully</info>'); |
|||
return 0; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue