. // }}} /** * OAuth2 implementation for GNU social * * @package OAuth2 * @category API * * @author Diogo Peralta Cordeiro * @author Hugo Sales * @copyright 2022 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace Plugin\OAuth2\Repository; use App\Core\DB; use App\Util\Exception\NotFoundException; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use Plugin\OAuth2\Entity; class Client implements ClientRepositoryInterface { /** * @param string $clientIdentifier * @param null|string $clientSecret * @param null|string $grantType */ public function validateClient($clientIdentifier, $clientSecret, $grantType): bool { try { /** @var Entity\Client $client */ $client = $this->getClientEntity($clientIdentifier); if ($client->getIsConfidential() && $clientSecret !== $client->getSecret()) { return false; } } catch (NotFoundException) { return false; } return true; } /** * @throws \App\Util\Exception\DuplicateFoundException * @throws NotFoundException */ public function getClientEntity($clientIdentifier): ?ClientEntityInterface { return DB::findOneBy(Entity\Client::class, ['id' => $clientIdentifier]); } }