summaryrefslogtreecommitdiffstats
path: root/apps/oauth2/lib/Controller/SettingsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/oauth2/lib/Controller/SettingsController.php')
-rw-r--r--apps/oauth2/lib/Controller/SettingsController.php51
1 files changed, 35 insertions, 16 deletions
diff --git a/apps/oauth2/lib/Controller/SettingsController.php b/apps/oauth2/lib/Controller/SettingsController.php
index f9ded6c0968..202db0b1835 100644
--- a/apps/oauth2/lib/Controller/SettingsController.php
+++ b/apps/oauth2/lib/Controller/SettingsController.php
@@ -26,6 +26,7 @@ use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -54,7 +55,7 @@ class SettingsController extends Controller {
* @param AccessTokenMapper $accessTokenMapper
* @param DefaultTokenMapper $defaultTokenMapper
*/
- public function __construct($appName,
+ public function __construct(string $appName,
IRequest $request,
IURLGenerator $urlGenerator,
ClientMapper $clientMapper,
@@ -70,31 +71,49 @@ class SettingsController extends Controller {
$this->defaultTokenMapper = $defaultTokenMapper;
}
- /**
- * @param string $name
- * @param string $redirectUri
- * @return RedirectResponse
- */
- public function addClient($name,
- $redirectUri) {
+ public function addClient(string $name,
+ string $redirectUri): JSONResponse {
$client = new Client();
$client->setName($name);
$client->setRedirectUri($redirectUri);
$client->setSecret($this->secureRandom->generate(64, self::validChars));
$client->setClientIdentifier($this->secureRandom->generate(64, self::validChars));
- $this->clientMapper->insert($client);
- return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security'));
+ $client = $this->clientMapper->insert($client);
+
+ $result = [
+ 'id' => $client->getId(),
+ 'name' => $client->getName(),
+ 'redirectUri' => $client->getRedirectUri(),
+ 'clientId' => $client->getClientIdentifier(),
+ 'clientSecret' => $client->getSecret(),
+ ];
+
+ return new JSONResponse($result);
}
- /**
- * @param int $id
- * @return RedirectResponse
- */
- public function deleteClient($id) {
+ public function deleteClient(int $id): JSONResponse {
$client = $this->clientMapper->getByUid($id);
$this->accessTokenMapper->deleteByClientId($id);
$this->defaultTokenMapper->deleteByName($client->getName());
$this->clientMapper->delete($client);
- return new RedirectResponse($this->urlGenerator->getAbsoluteURL('/index.php/settings/admin/security'));
+ return new JSONResponse([]);
+ }
+
+ public function getClients(): JSONResponse {
+ $clients = $this->clientMapper->getClients();
+
+ $result = [];
+
+ foreach ($clients as $client) {
+ $result[] = [
+ 'id' => $client->getId(),
+ 'name' => $client->getName(),
+ 'redirectUri' => $client->getRedirectUri(),
+ 'clientId' => $client->getClientIdentifier(),
+ 'clientSecret' => $client->getSecret(),
+ ];
+ }
+
+ return new JSONResponse($result);
}
}