You are here

public function ClientRepository::getClientEntity in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.4 src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository::getClientEntity()
  2. 8.2 src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository::getClientEntity()
  3. 5.x src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository::getClientEntity()

File

src/Repositories/ClientRepository.php, line 33

Class

ClientRepository

Namespace

Drupal\simple_oauth\Repositories

Code

public function getClientEntity($client_identifier, $grant_type = NULL, $client_secret = NULL, $must_validate_secret = TRUE) {
  $client_drupal_entities = $this->entityTypeManager
    ->getStorage('consumer')
    ->loadByProperties([
    'uuid' => $client_identifier,
  ]);

  // Check if the client is registered.
  if (empty($client_drupal_entities)) {
    return NULL;
  }

  /** @var \Drupal\consumers\Entity\Consumer $client_drupal_entity */
  $client_drupal_entity = reset($client_drupal_entities);
  $secret = $client_drupal_entity
    ->get('secret')->value;
  if ($must_validate_secret && $client_drupal_entity
    ->get('confidential')->value && $this->passwordChecker
    ->check($client_secret, $secret) === FALSE) {
    return NULL;
  }
  return new ClientEntity($client_drupal_entity);
}