Skip to content

Commit

Permalink
Merge pull request #9830 from nextcloud/feature/noid/oauth_vue_redire…
Browse files Browse the repository at this point in the history
…ct_validate

Migrate OAuth Admin settings to vue
  • Loading branch information
MorrisJobke committed Jun 19, 2018
2 parents 8646f01 + f520a6b commit c3aea9c
Show file tree
Hide file tree
Showing 18 changed files with 6,136 additions and 151 deletions.
25 changes: 25 additions & 0 deletions apps/oauth2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
all: dev-setup build-js-production

dev-setup: clean clean-dev npm-init

npm-init:
npm install

npm-update:
npm update

build-js:
npm run dev

build-js-production:
npm run build

watch-js:
npm run watch

clean:
rm -f js/oauth2.js
rm -f js/oauth2.map

clean-dev:
rm -rf node_modules
11 changes: 8 additions & 3 deletions apps/oauth2/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
'routes' => [
[
'name' => 'Settings#addClient',
'url' => '/settings',
'url' => '/clients',
'verb' => 'POST',
],
[
'name' => 'Settings#getClients',
'url' => '/clients',
'verb' => 'GET',
],
[
'name' => 'Settings#deleteClient',
'url' => '/clients/{id}/delete',
'verb' => 'POST'
'url' => '/clients/{id}',
'verb' => 'DELETE'
],
[
'name' => 'LoginRedirector#authorize',
Expand Down
15 changes: 15 additions & 0 deletions apps/oauth2/css/setting-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
opacity: 0.3;
cursor: pointer;
}

#oauth2 .icon-toggle,
#oauth2 .icon-delete {
display: inline-block;
width: 16px;
height: 16px;
padding: 10px;
vertical-align: middle;
}

#oauth2 .grid td code {
display: inline-block;
vertical-align: middle;
padding: 3px;
}
37 changes: 37 additions & 0 deletions apps/oauth2/js/oauth2.js

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions apps/oauth2/js/setting-admin.js

This file was deleted.

59 changes: 36 additions & 23 deletions apps/oauth2/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
Expand Down Expand Up @@ -26,14 +27,11 @@
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;

class SettingsController extends Controller {
/** @var IURLGenerator */
private $urlGenerator;
/** @var ClientMapper */
private $clientMapper;
/** @var ISecureRandom */
Expand All @@ -48,53 +46,68 @@ class SettingsController extends Controller {
/**
* @param string $appName
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param ClientMapper $clientMapper
* @param ISecureRandom $secureRandom
* @param AccessTokenMapper $accessTokenMapper
* @param DefaultTokenMapper $defaultTokenMapper
*/
public function __construct($appName,
public function __construct(string $appName,
IRequest $request,
IURLGenerator $urlGenerator,
ClientMapper $clientMapper,
ISecureRandom $secureRandom,
AccessTokenMapper $accessTokenMapper,
DefaultTokenMapper $defaultTokenMapper
) {
parent::__construct($appName, $request);
$this->urlGenerator = $urlGenerator;
$this->secureRandom = $secureRandom;
$this->clientMapper = $clientMapper;
$this->accessTokenMapper = $accessTokenMapper;
$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);
}
}
30 changes: 5 additions & 25 deletions apps/oauth2/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
Expand All @@ -21,46 +22,25 @@

namespace OCA\OAuth2\Settings;

use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;

class Admin implements ISettings {
/** @var ClientMapper */
private $clientMapper;

/**
* @param ClientMapper $clientMapper
*/
public function __construct(ClientMapper $clientMapper) {
$this->clientMapper = $clientMapper;
}

/**
* @return TemplateResponse
*/
public function getForm() {
public function getForm(): TemplateResponse {
return new TemplateResponse(
'oauth2',
'admin',
[
'clients' => $this->clientMapper->getClients(),
],
[],
''
);
}

/**
* {@inheritdoc}
*/
public function getSection() {
public function getSection(): string {
return 'security';
}

/**
* {@inheritdoc}
*/
public function getPriority() {
public function getPriority(): int {
return 0;
}
}
Loading

0 comments on commit c3aea9c

Please sign in to comment.