nextcloud/apps/oauth2/lib/Controller/SettingsController.php
Carl Schwan 6621a534c3 feat(oauth2): Add commands for adding and deleting clients
Refactor the code for doing that from the controller to a seperate
service.

Signed-off-by: Carl Schwan <carlschwan@kde.org>
2026-06-15 16:30:49 +00:00

46 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\OAuth2\Controller;
use OCA\OAuth2\Service\ClientService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IL10N;
use OCP\IRequest;
class SettingsController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private IL10N $l,
private readonly ClientService $clientService,
) {
parent::__construct($appName, $request);
}
#[PasswordConfirmationRequired(strict: true)]
public function addClient(string $name,
string $redirectUri): JSONResponse {
if (filter_var($redirectUri, FILTER_VALIDATE_URL) === false) {
return new JSONResponse(['message' => $this->l->t('Your redirect URL needs to be a full URL for example: https://yourdomain.com/path')], Http::STATUS_BAD_REQUEST);
}
$result = $this->clientService->addClient($name, $redirectUri);
return new JSONResponse($result);
}
#[PasswordConfirmationRequired]
public function deleteClient(int $id): JSONResponse {
$this->clientService->deleteClient($id);
return new JSONResponse([]);
}
}