diff --git a/com_oauthserver/administrator/forms/client.xml b/com_oauthserver/administrator/forms/client.xml index f8688c6..eebb39a 100644 --- a/com_oauthserver/administrator/forms/client.xml +++ b/com_oauthserver/administrator/forms/client.xml @@ -4,10 +4,17 @@
+ @@ -32,7 +39,7 @@ layout="joomla.form.field.radio.switcher" label="COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_LABEL" description="COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_DESCRIPTION" - filter="boolean" + filter="integer" default="1"> @@ -40,12 +47,10 @@ + label="COM_OAUTHSERVER_CLIENT_IDENTIFIER_LABEL"/> + label="COM_OAUTHSERVER_CLIENT_SECRET_LABEL"/>
\ No newline at end of file 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 c541565..3fa3704 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 @@ -1,4 +1,24 @@ +COM_OAUTHSERVER = "OAuth сервер" + +COM_OAUTHSERVER_CLIENT_EDIT = "Редактирование клиента" + +COM_OAUTHSERVER_CLIENT_DETAILS = "Основные параметры" + +COM_OAUTHSERVER_CLIENT = "Клиент" + +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_REDIRECT_URI_DESCRIPTION = "Устанавливает URL, на который будет производиться перенаправление клиента, после аутентификации. Если задать этот параметр, то Redirect URI в запросе будет проигнорирован." +COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_LABEL = "Разрешить «простой» метод запроса PKCE" +COM_OAUTHSERVER_CLIENT_ALLOW_PLAIN_TEXT_PKCE_DESCRIPTION = "Разрешить клиенту создавать запрос PKCE на предоставление кода авторизации с помощью «простого» метода запроса кода." +COM_OAUTHSERVER_CLIENT_IDENTIFIER_LABEL = "ID клиента" +COM_OAUTHSERVER_CLIENT_SECRET_LABEL = "Ключ клиента" + COM_OAUTHSERVER_CLIENTS_HEADING_NAME = "Клиент" COM_OAUTHSERVER_CLIENTS_HEADING_IDENTIFIER = "ID клиента" COM_OAUTHSERVER_CLIENTS_HEADING_SECRET = "Ключ" -COM_OAUTHSERVER_CLIENTS_HEADING_PUBLIC = "Публичный" \ No newline at end of file +COM_OAUTHSERVER_CLIENTS_HEADING_PUBLIC = "Публичный" + +COM_OAUTHSERVER_SAVE_AND_RESET = "Сохранить и сбросить" \ No newline at end of file diff --git a/com_oauthserver/administrator/src/Controller/ClientController.php b/com_oauthserver/administrator/src/Controller/ClientController.php index 9bd94d5..69f2edd 100644 --- a/com_oauthserver/administrator/src/Controller/ClientController.php +++ b/com_oauthserver/administrator/src/Controller/ClientController.php @@ -2,7 +2,11 @@ namespace Webmasterskaya\Component\OauthServer\Administrator\Controller; +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Form\FormFactoryInterface; use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\Input\Input; class ClientController extends FormController { @@ -14,4 +18,21 @@ class ClientController extends FormController * @since 1.0.0 */ protected $text_prefix = 'COM_OAUTHSERVER_CLIENT'; + + /** + * @param array $config + * @param \Joomla\CMS\MVC\Factory\MVCFactoryInterface|null $factory + * @param \Joomla\CMS\Application\CMSApplication|null $app + * @param \Joomla\Input\Input|null $input + * @param \Joomla\CMS\Form\FormFactoryInterface|null $formFactory + * @throws \Exception + * @since version + */ + public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null, FormFactoryInterface $formFactory = null) + { + parent::__construct($config, $factory, $app, $input, $formFactory); + + $this->registerTask('save2reset', 'save'); + } + } \ No newline at end of file diff --git a/com_oauthserver/administrator/src/Model/ClientModel.php b/com_oauthserver/administrator/src/Model/ClientModel.php index 14645d6..6587258 100644 --- a/com_oauthserver/administrator/src/Model/ClientModel.php +++ b/com_oauthserver/administrator/src/Model/ClientModel.php @@ -2,19 +2,20 @@ namespace Webmasterskaya\Component\OauthServer\Administrator\Model; +use Joomla\CMS\Crypt\Crypt; +use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; use Joomla\CMS\MVC\Model\AdminModel; class ClientModel extends AdminModel { /** - * Model context string. + * The type alias for this content type. * - * @var string - * - * @since 1.0.0 + * @var string + * @since version */ - protected string $context = 'com_oauthserver.client'; + public $typeAlias = 'com_oauthserver.client'; /** * Client item. @@ -34,7 +35,81 @@ class ClientModel extends AdminModel */ public function getForm($data = [], $loadData = true): Form|bool { - return $this->loadForm('com_oauthserver.client', 'client', - ['control' => 'jform', 'load_data' => $loadData]); + $form = $this->loadForm('com_oauthserver.client', 'client', ['control' => 'jform', 'load_data' => $loadData]); + + if (empty($form)) { + return false; + } + + return $form; + } + + /** + * Method to get the data that should be injected in the form. + * + * @return mixed The data for the form. + * + * @throws \Exception + * @since version + */ + protected function loadFormData(): mixed + { + // Check the session for previously entered form data. + $data = Factory::getApplication()->getUserState('com_oauthserver.edit.client.data', []); + + if (empty($data)) { + $data = $this->getItem(); + } + + $this->preprocessData('com_oauthserver.client', $data); + + return $data; + } + + public function validate($form, $data, $group = null): bool|array + { + unset($data['identifier'], $data['secret']); + + return parent::validate($form, $data, $group); + } + + /** + * @param \Webmasterskaya\Component\OauthServer\Administrator\Table\ClientTable $table + * @return void + * @throws \Exception + * @since version + */ + protected function prepareTable($table): void + { + $app = Factory::getApplication(); + $input = $app->getInput(); + $task = strtolower($input->getCmd('task', '')); + + if ($task === 'save2reset' || empty($table->id)) { + $table->identifier = $this->generateNewIdentifier(); + $table->secret = $table->public ? '' : $this->generateNewSecret(); + } + + if ($table->public) { + $table->secret = ''; + } else { + if (empty($table->secret)) { + $table->secret = $this->generateNewSecret(); + } + } + + $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES); + + parent::prepareTable($table); + } + + protected function generateNewIdentifier(): string + { + return hash('md5', Crypt::genRandomBytes(16)); + } + + protected function generateNewSecret(): string + { + return hash('sha512', Crypt::genRandomBytes(32)); } } \ No newline at end of file diff --git a/com_oauthserver/administrator/src/Table/ClientTable.php b/com_oauthserver/administrator/src/Table/ClientTable.php index bcd04a0..a6d0fdb 100644 --- a/com_oauthserver/administrator/src/Table/ClientTable.php +++ b/com_oauthserver/administrator/src/Table/ClientTable.php @@ -5,6 +5,17 @@ namespace Webmasterskaya\Component\OauthServer\Administrator\Table; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; +/** + * @property int $id + * @property string $name + * @property string $identifier + * @property string|null $secret + * @property bool $public + * @property string|null $redirect_uri + * @property bool $allow_plain_text_pkce + * + * @since version + */ class ClientTable extends Table { /** diff --git a/com_oauthserver/administrator/src/View/Client/HtmlView.php b/com_oauthserver/administrator/src/View/Client/HtmlView.php index bdd21d2..e5d7fb6 100644 --- a/com_oauthserver/administrator/src/View/Client/HtmlView.php +++ b/com_oauthserver/administrator/src/View/Client/HtmlView.php @@ -116,8 +116,9 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView $childBar->save2new('client.save2new'); } $childBar - ->standardButton('save-reset', 'COM_OAUTHSERVER_CLIENT_SAVE_AND_RESET') + ->standardButton('save-reset', 'COM_OAUTHSERVER_SAVE_AND_RESET') ->task('client.save2reset') + ->icon('icon-sync') ->formValidation(true); } } diff --git a/com_oauthserver/administrator/tmpl/client/edit.php b/com_oauthserver/administrator/tmpl/client/edit.php index 2700610..5780e54 100644 --- a/com_oauthserver/administrator/tmpl/client/edit.php +++ b/com_oauthserver/administrator/tmpl/client/edit.php @@ -19,19 +19,22 @@ $wa->useScript('keepalive')
- -
'details', 'recall' => true, 'breakpoint' => 768]); ?> - +
- form->renderFieldset('global');?> + form->renderField('name'); ?> + form->renderField('public'); ?> + form->renderField('redirect_uri'); ?> + form->renderField('allow_plain_text_pkce'); ?> + form->renderField('identifier'); ?> + form->renderField('secret'); ?>