2017-05-04 17:46:59 -04:00
< ? php
2019-12-03 13:57:53 -05:00
2018-06-13 15:25:21 -04:00
declare ( strict_types = 1 );
2019-12-03 13:57:53 -05:00
2017-05-04 17:46:59 -04:00
/**
2024-05-30 14:13:41 -04:00
* SPDX - FileCopyrightText : 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2017-05-04 17:46:59 -04:00
*/
namespace OCA\OAuth2\Controller ;
2026-06-15 04:45:13 -04:00
use OCA\OAuth2\Service\ClientService ;
2017-05-04 17:46:59 -04:00
use OCP\AppFramework\Controller ;
2018-06-26 09:27:20 -04:00
use OCP\AppFramework\Http ;
2026-03-19 09:49:11 -04:00
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired ;
2018-06-08 03:52:27 -04:00
use OCP\AppFramework\Http\JSONResponse ;
2018-06-26 09:27:20 -04:00
use OCP\IL10N ;
2017-05-04 17:46:59 -04:00
use OCP\IRequest ;
class SettingsController extends Controller {
2023-05-22 09:39:56 -04:00
public function __construct (
string $appName ,
IRequest $request ,
private IL10N $l ,
2026-06-15 04:45:13 -04:00
private readonly ClientService $clientService ,
2017-05-12 10:14:32 -04:00
) {
2017-05-04 17:46:59 -04:00
parent :: __construct ( $appName , $request );
}
2026-03-19 09:49:11 -04:00
#[PasswordConfirmationRequired(strict: true)]
2018-06-08 03:52:27 -04:00
public function addClient ( string $name ,
string $redirectUri ) : JSONResponse {
2018-09-03 18:58:44 -04:00
if ( filter_var ( $redirectUri , FILTER_VALIDATE_URL ) === false ) {
2018-06-30 02:49:44 -04:00
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 );
2018-06-26 09:27:20 -04:00
}
2026-06-15 04:45:13 -04:00
$result = $this -> clientService -> addClient ( $name , $redirectUri );
2018-06-08 03:52:27 -04:00
return new JSONResponse ( $result );
2017-05-04 17:46:59 -04:00
}
2026-03-19 09:49:11 -04:00
#[PasswordConfirmationRequired]
2018-06-08 03:52:27 -04:00
public function deleteClient ( int $id ) : JSONResponse {
2026-06-15 04:45:13 -04:00
$this -> clientService -> deleteClient ( $id );
2018-06-08 03:52:27 -04:00
return new JSONResponse ([]);
}
2017-05-04 17:46:59 -04:00
}