ClientRepository.php in Simple OAuth (OAuth2) & OpenID Connect 5.x
File
src/Repositories/ClientRepository.php
View source
<?php
namespace Drupal\simple_oauth\Repositories;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Password\PasswordInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use Drupal\simple_oauth\Entities\ClientEntity;
class ClientRepository implements ClientRepositoryInterface {
protected $entityTypeManager;
protected $passwordChecker;
public function __construct(EntityTypeManagerInterface $entity_type_manager, PasswordInterface $password_checker) {
$this->entityTypeManager = $entity_type_manager;
$this->passwordChecker = $password_checker;
}
public function getClientEntity($client_identifier) {
$client_drupal_entities = $this->entityTypeManager
->getStorage('consumer')
->loadByProperties([
'uuid' => $client_identifier,
]);
if (empty($client_drupal_entities)) {
return NULL;
}
$client_drupal_entity = reset($client_drupal_entities);
return new ClientEntity($client_drupal_entity);
}
public function validateClient($client_identifier, $client_secret, $grant_type) {
$client_drupal_entities = $this->entityTypeManager
->getStorage('consumer')
->loadByProperties([
'uuid' => $client_identifier,
]);
$client_drupal_entity = reset($client_drupal_entities);
$secret = $client_drupal_entity
->get('secret')->value;
if ($client_drupal_entity
->get('confidential')->value) {
return $this->passwordChecker
->check($client_secret, $secret);
}
return FALSE;
}
}