From 0aa1b5a9613f55953f44ccd73a7270863341836c Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Mon, 11 Mar 2024 02:06:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2?= =?UTF-8?q?=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrator/forms/client.xml | 38 +++++++++++++++--- .../language/ru-RU/ru-RU.com_oauthserver.ini | 13 +++++-- .../administrator/src/Model/ClientModel.php | 39 +++++++++++++++++-- .../administrator/tmpl/client/edit.php | 30 ++++++++++---- 4 files changed, 100 insertions(+), 20 deletions(-) diff --git a/com_oauthserver/administrator/forms/client.xml b/com_oauthserver/administrator/forms/client.xml index db5be5e..4ee64eb 100644 --- a/com_oauthserver/administrator/forms/client.xml +++ b/com_oauthserver/administrator/forms/client.xml @@ -12,20 +12,29 @@ readonly="true" class="readonly" /> + + + + - - + + +
+ + + +
diff --git a/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini b/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini index c8b6a38..6011fb7 100644 --- a/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini +++ b/com_oauthserver/administrator/language/ru-RU/ru-RU.com_oauthserver.ini @@ -16,11 +16,14 @@ COM_OAUTHSERVER_CLIENT_EDIT = "Редактирование клиента" COM_OAUTHSERVER_CLIENT_DETAILS = "Основные параметры" COM_OAUTHSERVER_CLIENT = "Клиент" +COM_OAUTHSERVER_CLIENT_CONNECTIONS_TITLE = "Параметры подключения клиента" +COM_OAUTHSERVER_SERVER_CONNECTIONS_TITLE = "Параметры подключения сервера" COM_OAUTHSERVER_CLIENT_NAME_LABEL = "Имя клиента" -COM_OAUTHSERVER_CLIENT_PUBLIC_LABEL = "Публичный клиент" -COM_OAUTHSERVER_CLIENT_PUBLIC_DESCRIPTION = "Клиент, у которого нет секрета (Ключа клиента)" -COM_OAUTHSERVER_CLIENT_REDIRECT_URI_LABEL = "Callback/Redirect URL" +COM_OAUTHSERVER_CLIENT_TYPE_LABEL = "Тип клиента" +COM_OAUTHSERVER_CLIENT_TYPE_PUBLIC = "Общедоступный" +COM_OAUTHSERVER_CLIENT_TYPE_CONFIDENTIAL = "Конфиденциальный" +COM_OAUTHSERVER_CLIENT_REDIRECT_URI_LABEL = "Допустимые значения Callback/Redirect URL" COM_OAUTHSERVER_CLIENT_REDIRECT_URI_DESCRIPTION = "Устанавливает URL, на который будет производиться перенаправление клиента, после аутентификации. Если задать этот параметр, то Redirect URI в запросе будет проигнорирован." COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_LABEL = "Разрешить «простой» метод запроса PKCE" COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_DESCRIPTION = "Разрешить клиенту создавать запрос PKCE на предоставление кода авторизации с помощью «простого» метода запроса кода." @@ -32,6 +35,10 @@ COM_OAUTHSERVER_CLIENTS_HEADING_IDENTIFIER = "ID клиента" COM_OAUTHSERVER_CLIENTS_HEADING_SECRET = "Ключ" COM_OAUTHSERVER_CLIENTS_HEADING_PUBLIC = "Публичный" +COM_OAUTHSERVER_CLIENT_AUTHORIZE_URL_LABEL = "URL авторизации" +COM_OAUTHSERVER_CLIENT_TOKEN_URL_LABEL = "URL токена" +COM_OAUTHSERVER_CLIENT_PROFILE_URL_LABEL = "URL профиля" + COM_OAUTHSERVER_SAVE_AND_RESET = "Сохранить и сбросить" COM_OAUTHSERVER_CLIENTS = "Клиенты" diff --git a/com_oauthserver/administrator/src/Model/ClientModel.php b/com_oauthserver/administrator/src/Model/ClientModel.php index e90f572..b9967bf 100644 --- a/com_oauthserver/administrator/src/Model/ClientModel.php +++ b/com_oauthserver/administrator/src/Model/ClientModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\Crypt\Crypt; use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Uri\Uri; use Webmasterskaya\Component\OauthServer\Administrator\Table\ClientTable; \defined('_JEXEC') or die; @@ -67,6 +68,13 @@ class ClientModel extends AdminModel $data = $this->getItem(); } + $root = Uri::root(); + $uri = new Uri($root); + + $data->def('authorize_url', (string) $uri->setPath('login/oauth/authorize')); + $data->def('token_url', (string) $uri->setPath('login/oauth/token')); + $data->def('profile_url', (string) $uri->setPath('login/oauth/profile')); + $this->preprocessData('com_oauthserver.client', $data); return $data; @@ -75,10 +83,16 @@ class ClientModel extends AdminModel public function validate($form, $data, $group = null): bool|array { unset($data['identifier'], $data['secret']); + unset($data['authorize_url'], $data['token_url'], $data['profile_url']); return parent::validate($form, $data, $group); } + public function save($data) + { + return parent::save($data); // TODO: Change the autogenerated stub + } + /** * @param ClientTable $table * @@ -92,10 +106,14 @@ class ClientModel extends AdminModel $input = $app->getInput(); $task = strtolower($input->getCmd('task', '')); - if ($task === 'save2reset' || empty($table->id)) + if (empty($table->id)) { $table->identifier = $this->generateNewIdentifier(); - $table->secret = !!$table->public ? '' : $this->generateNewSecret(); + } + + if ($task === 'save2reset' || empty($table->id)) + { + $table->secret = ''; } if (!!$table->public) @@ -115,13 +133,26 @@ class ClientModel extends AdminModel parent::prepareTable($table); } + protected function generateNewHash($field, $algo = 'sha256', $length = 16) + { + $hash = hash($algo, Crypt::genRandomBytes($length)); + $table = $this->getTable(); + + if ($table->load([$field => $hash])) + { + return $this->generateNewHash($field, $algo, $length); + } + + return $hash; + } + protected function generateNewIdentifier(): string { - return hash('md5', Crypt::genRandomBytes(16)); + return $this->generateNewHash('identifier', 'md5'); } protected function generateNewSecret(): string { - return hash('sha512', Crypt::genRandomBytes(32)); + return $this->generateNewHash('secret', 'sha512', 32); } } diff --git a/com_oauthserver/administrator/tmpl/client/edit.php b/com_oauthserver/administrator/tmpl/client/edit.php index 8bd0e4f..e1a53d3 100644 --- a/com_oauthserver/administrator/tmpl/client/edit.php +++ b/com_oauthserver/administrator/tmpl/client/edit.php @@ -9,6 +9,7 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; defined('_JEXEC') or die; @@ -28,24 +29,39 @@ $wa->useScript('keepalive') aria-label="item->id === 0 ? 'NEW' : 'EDIT'), true); ?>" class="form-validate"> + +
'details', 'recall' => true, 'breakpoint' => 768]); ?>
-
-
- +
+
+
- form->renderField('name'); ?> - form->renderField('public'); ?> - form->renderField('redirect_uris'); ?> - form->renderField('allow_plain_text_pkce'); ?> form->renderField('identifier'); ?> form->renderField('secret'); ?> + form->renderField('redirect_uris'); ?>
+
+ + +
+ form->renderField('authorize_url'); ?> + form->renderField('token_url'); ?> + form->renderField('profile_url'); ?> +
+
+
+
+
+ + form->renderField('active'); ?> + form->renderField('public'); ?> +