diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-08 09:52:27 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-06-19 11:42:41 +0200 |
commit | d2d1e8e3750eb1c5f8049aa5d0e7326f8b49a659 (patch) | |
tree | d47b15245bfe9b238ca02ac97bd2a5e794f8af6c /apps/oauth2/lib | |
parent | 7b8063a2424ea9f9d87493a23074b62afdd57854 (diff) | |
download | nextcloud-server-d2d1e8e3750eb1c5f8049aa5d0e7326f8b49a659.tar.gz nextcloud-server-d2d1e8e3750eb1c5f8049aa5d0e7326f8b49a659.zip |
Migrate OAuth Admin settings to vue
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/oauth2/lib')
-rw-r--r-- | apps/oauth2/lib/Controller/SettingsController.php | 51 | ||||
-rw-r--r-- | apps/oauth2/lib/Settings/Admin.php | 4 |
2 files changed, 36 insertions, 19 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); } } diff --git a/apps/oauth2/lib/Settings/Admin.php b/apps/oauth2/lib/Settings/Admin.php index 07c3fe733ad..7460f86ca53 100644 --- a/apps/oauth2/lib/Settings/Admin.php +++ b/apps/oauth2/lib/Settings/Admin.php @@ -43,9 +43,7 @@ class Admin implements ISettings { return new TemplateResponse( 'oauth2', 'admin', - [ - 'clients' => $this->clientMapper->getClients(), - ], + [], '' ); } |