From 6bf4313b03066afd922c55bf4b2eb4ffa7b8c1b7 Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Tue, 12 Mar 2024 13:46:30 +0300 Subject: [PATCH] Update php doc and properties types --- .../site/src/Repository/ClientRepository.php | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/com_oauthserver/site/src/Repository/ClientRepository.php b/com_oauthserver/site/src/Repository/ClientRepository.php index 7641e3d..8a33c57 100644 --- a/com_oauthserver/site/src/Repository/ClientRepository.php +++ b/com_oauthserver/site/src/Repository/ClientRepository.php @@ -28,9 +28,9 @@ class ClientRepository implements ClientRepositoryInterface } /** - * @param $clientIdentifier + * @param string $clientIdentifier * - * @return \League\OAuth2\Server\Entities\ClientEntityInterface|null + * @return ClientEntityInterface|null * @throws \Exception * @since version */ @@ -38,34 +38,37 @@ class ClientRepository implements ClientRepositoryInterface { $item = $this->clientModel->getItemByIdentifier($clientIdentifier); - if (empty($item->id)) + if ($item === false) { return null; } - return $this->buildClientEntity($item); + return $this->bind($item); } + /** + * @param $clientIdentifier + * @param $clientSecret + * @param $grantType + * + * @return bool + * @throws \Exception + * @since version + * @noinspection PhpPossiblePolymorphicInvocationInspection + */ public function validateClient($clientIdentifier, $clientSecret, $grantType): bool { $item = $this->clientModel->getItemByIdentifier($clientIdentifier); - if (empty($item->id)) + if ($item === false + || !$item->active + || !$this->isGrantSupported($item, $grantType)) { return false; } - if (!$item->active) - { - return false; - } - - if (!$this->isGrantSupported($item, $grantType)) - { - return false; - } - - if (!!$item->public || hash_equals((string) $item->secret, (string) $clientSecret)) + if (!!$item->public + || hash_equals((string) $item->secret, (string) $clientSecret)) { return true; } @@ -73,26 +76,46 @@ class ClientRepository implements ClientRepositoryInterface return false; } - private function buildClientEntity(\stdClass|CMSObject $client): Client + /** @noinspection PhpPossiblePolymorphicInvocationInspection */ + private function bind(CMSObject $client): Client { $clientEntity = new Client(); $clientEntity->setName($client->name); $clientEntity->setIdentifier($client->identifier); - $clientEntity->setRedirectUri(ArrayHelper::getColumn((array) $client->redirect_uris, 'uri')); + + if (!empty($client->redirect_uris)) + { + $redirect_uris = json_decode($client->redirect_uris, true, 3, JSON_OBJECT_AS_ARRAY); + $redirect_uris = ArrayHelper::getColumn($redirect_uris, 'uri'); + } + else + { + $redirect_uris = []; + } + $clientEntity->setRedirectUri($redirect_uris); + $clientEntity->setConfidential(!$client->public); - $clientEntity->setAllowPlainTextPkce((bool) $client->allow_plain_text_pkce); + $clientEntity->setAllowPlainTextPkce(!!$client->allow_plain_text_pkce); return $clientEntity; } - private function isGrantSupported(\stdClass|CMSObject $client, ?string $grant): bool + private function isGrantSupported(CMSObject $client, ?string $grant): bool { if (null === $grant) { return true; } - $grants = array_map('strval', (array) $client->grants); + if (!empty($client->grants)) + { + $grants = json_decode($client->grants, true, 3, JSON_OBJECT_AS_ARRAY); + $grants = ArrayHelper::getColumn($grants, 'grant'); + } + else + { + $grants = []; + } if (empty($grants)) {