. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Tools\OAuthServer\Repository; use Espo\ORM\SthCollection; use Espo\Tools\OAuthServer\Utils\IdentifierHasher; use Espo\ORM\EntityManager; use Espo\Tools\OAuthServer\Entities\RefreshToken; use SensitiveParameter; class RefreshTokenRepository { public function __construct( private EntityManager $entityManager, private IdentifierHasher $hasher, ) {} public function getActiveByIdentifier(#[SensitiveParameter] string $identifier): ?RefreshToken { $hash = $this->hasher->hash($identifier); return $this->entityManager ->getRDBRepositoryByClass(RefreshToken::class) ->where([ RefreshToken::FIELD_HASH => $hash, RefreshToken::FIELD_STATUS => RefreshToken::STATUS_ACTIVE, ]) ->findOne(); } /** * @return SthCollection */ public function findActiveForClientIdAndUser(string $clientId, string $userId): SthCollection { return $this->entityManager->getRDBRepositoryByClass(RefreshToken::class) ->where([ RefreshToken::FIELD_STATUS => RefreshToken::STATUS_ACTIVE, RefreshToken::FIELD_CLIENT . 'Id' => $clientId, RefreshToken::FIELD_USER . 'Id' => $userId, ]) ->sth() ->find(); } }