mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-23 22:34:50 +03:00
Minor improvements and explanations in the client model
This commit is contained in:
parent
4b9ebe81e4
commit
d87a9b1471
@ -68,12 +68,14 @@ class ClientModel extends AdminModel
|
|||||||
$data = $this->getItem();
|
$data = $this->getItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
$root = Uri::root();
|
if ($data)
|
||||||
$uri = new Uri($root);
|
{
|
||||||
|
$uri = new Uri(Uri::root());
|
||||||
|
|
||||||
$data->def('authorize_url', (string) $uri->setPath('login/oauth/authorize'));
|
$data->def('authorize_url', (string) $uri->setPath('login/oauth/authorize'));
|
||||||
$data->def('token_url', (string) $uri->setPath('login/oauth/token'));
|
$data->def('token_url', (string) $uri->setPath('login/oauth/token'));
|
||||||
$data->def('profile_url', (string) $uri->setPath('login/oauth/profile'));
|
$data->def('profile_url', (string) $uri->setPath('login/oauth/profile'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->preprocessData('com_oauthserver.client', $data);
|
$this->preprocessData('com_oauthserver.client', $data);
|
||||||
|
|
||||||
@ -82,17 +84,14 @@ class ClientModel extends AdminModel
|
|||||||
|
|
||||||
public function validate($form, $data, $group = null): bool|array
|
public function validate($form, $data, $group = null): bool|array
|
||||||
{
|
{
|
||||||
|
// Since the client’s identifier and secret key are created on the server and completely
|
||||||
|
// exclude the user’s influence on their value, we remove them from the request to eliminate
|
||||||
|
// any possibility of substitution of this data.
|
||||||
unset($data['identifier'], $data['secret']);
|
unset($data['identifier'], $data['secret']);
|
||||||
unset($data['authorize_url'], $data['token_url'], $data['profile_url']);
|
|
||||||
|
|
||||||
return parent::validate($form, $data, $group);
|
return parent::validate($form, $data, $group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($data)
|
|
||||||
{
|
|
||||||
return parent::save($data); // TODO: Change the autogenerated stub
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ClientTable $table
|
* @param ClientTable $table
|
||||||
*
|
*
|
||||||
@ -103,29 +102,22 @@ class ClientModel extends AdminModel
|
|||||||
protected function prepareTable($table): void
|
protected function prepareTable($table): void
|
||||||
{
|
{
|
||||||
$app = Factory::getApplication();
|
$app = Factory::getApplication();
|
||||||
$input = $app->getInput();
|
|
||||||
$task = strtolower($input->getCmd('task', ''));
|
|
||||||
|
|
||||||
if (empty($table->id))
|
if ($table->id > 0)
|
||||||
{
|
{
|
||||||
$table->identifier = $this->generateNewIdentifier();
|
$table->identifier = $this->generateNewIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($task === 'save2reset' || empty($table->id))
|
if (empty($table->secret)
|
||||||
{
|
&& !$table->public
|
||||||
$table->secret = '';
|
&& ($table->id > 0 || $app->getInput()->get('task') == 'save2reset'))
|
||||||
}
|
|
||||||
|
|
||||||
if (!!$table->public)
|
|
||||||
{
|
|
||||||
$table->secret = '';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (empty($table->secret))
|
|
||||||
{
|
{
|
||||||
$table->secret = $this->generateNewSecret();
|
$table->secret = $this->generateNewSecret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($table->public)
|
||||||
|
{
|
||||||
|
$table->secret = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
|
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
|
||||||
@ -133,7 +125,18 @@ class ClientModel extends AdminModel
|
|||||||
parent::prepareTable($table);
|
parent::prepareTable($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateNewHash($field, $algo = 'sha256', $length = 16)
|
/**
|
||||||
|
* Generate a hash value of string for table field and check it unique
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param string $algo
|
||||||
|
* @param int $length
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
* @since version
|
||||||
|
*/
|
||||||
|
protected function generateNewHash(string $field, string $algo = 'sha256', int $length = 16): string
|
||||||
{
|
{
|
||||||
$hash = hash($algo, Crypt::genRandomBytes($length));
|
$hash = hash($algo, Crypt::genRandomBytes($length));
|
||||||
$table = $this->getTable();
|
$table = $this->getTable();
|
||||||
@ -146,11 +149,25 @@ class ClientModel extends AdminModel
|
|||||||
return $hash;
|
return $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate unique hash value for client identifier
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
* @since version
|
||||||
|
*/
|
||||||
protected function generateNewIdentifier(): string
|
protected function generateNewIdentifier(): string
|
||||||
{
|
{
|
||||||
return $this->generateNewHash('identifier', 'md5');
|
return $this->generateNewHash('identifier', 'md5');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate unique hash value for client secret key
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
* @since version
|
||||||
|
*/
|
||||||
protected function generateNewSecret(): string
|
protected function generateNewSecret(): string
|
||||||
{
|
{
|
||||||
return $this->generateNewHash('secret', 'sha512', 32);
|
return $this->generateNewHash('secret', 'sha512', 32);
|
||||||
|
Loading…
Reference in New Issue
Block a user