mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-24 02:44:51 +03:00
Создание и сохранение клиента
This commit is contained in:
parent
39a878f2c8
commit
6e14adfc86
@ -4,10 +4,17 @@
|
||||
<inlinehelp button="show"/>
|
||||
</config>
|
||||
<fieldset name="global">
|
||||
<field
|
||||
name="id"
|
||||
type="number"
|
||||
label="JGLOBAL_FIELD_ID_LABEL"
|
||||
default="0"
|
||||
readonly="true"
|
||||
class="readonly"
|
||||
/>
|
||||
<field name="name"
|
||||
type="text"
|
||||
label="COM_OAUTHSERVER_CLIENT_NAME_LABEL"
|
||||
description="COM_OAUTHSERVER_NAME_DESCRIPTION"
|
||||
required="1"
|
||||
/>
|
||||
<field name="public"
|
||||
@ -15,7 +22,7 @@
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="COM_OAUTHSERVER_CLIENT_PUBLIC_LABEL"
|
||||
description="COM_OAUTHSERVER_CLIENT_PUBLIC_DESCRIPTION"
|
||||
filter="boolean"
|
||||
filter="integer"
|
||||
default="0">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
@ -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">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
@ -40,12 +47,10 @@
|
||||
<field name="identifier"
|
||||
type="text"
|
||||
readonly="1"
|
||||
label="COM_OAUTHSERVER_CLIENT_IDENTIFIER_LABEL"
|
||||
description="COM_OAUTHSERVER_CLIENT_IDENTIFIER_DESCRIPTION"/>
|
||||
label="COM_OAUTHSERVER_CLIENT_IDENTIFIER_LABEL"/>
|
||||
<field name="secret"
|
||||
type="text"
|
||||
readonly="1"
|
||||
label="COM_OAUTHSERVER_CLIENT_SECRET_LABEL"
|
||||
description="COM_OAUTHSERVER_CLIENT_SECRET_DESCRIPTION"/>
|
||||
label="COM_OAUTHSERVER_CLIENT_SECRET_LABEL"/>
|
||||
</fieldset>
|
||||
</form>
|
@ -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 = "Публичный"
|
||||
|
||||
COM_OAUTHSERVER_SAVE_AND_RESET = "Сохранить и сбросить"
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
* @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));
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,22 @@ $wa->useScript('keepalive')
|
||||
|
||||
<form action="<?php echo Route::_('index.php?option=com_oauthserver&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="client-form" aria-label="<?php echo Text::_('COM_OAUTHSERVER_CLIENT_FORM_' . ((int) $this->item->id === 0 ? 'NEW' : 'EDIT'), true); ?>" class="form-validate">
|
||||
|
||||
<?php echo LayoutHelper::render('joomla.edit.title_alias', $this); ?>
|
||||
|
||||
<div class="main-card">
|
||||
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', ['active' => 'details', 'recall' => true, 'breakpoint' => 768]); ?>
|
||||
|
||||
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'details', Text::_('COM_BANNERS_BANNER_DETAILS')); ?>
|
||||
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'details', Text::_('COM_OAUTHSERVER_CLIENT_DETAILS')); ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<fieldset id="fieldset-publishingdata" class="options-form">
|
||||
<legend><?php echo Text::_('COM_OAUTHSERVER_CLIENT'); ?></legend>
|
||||
<div>
|
||||
<?php echo $this->form->renderFieldset('global');?>
|
||||
<?php echo $this->form->renderField('name'); ?>
|
||||
<?php echo $this->form->renderField('public'); ?>
|
||||
<?php echo $this->form->renderField('redirect_uri'); ?>
|
||||
<?php echo $this->form->renderField('allow_plain_text_pkce'); ?>
|
||||
<?php echo $this->form->renderField('identifier'); ?>
|
||||
<?php echo $this->form->renderField('secret'); ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user