You are here

class ClientRepository in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.2 src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository
  2. 8.3 src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository
  3. 5.x src/Repositories/ClientRepository.php \Drupal\simple_oauth\Repositories\ClientRepository

Hierarchy

  • class \Drupal\simple_oauth\Repositories\ClientRepository implements \League\OAuth2\Server\Repositories\ClientRepositoryInterface

Expanded class hierarchy of ClientRepository

1 string reference to 'ClientRepository'
simple_oauth.services.yml in ./simple_oauth.services.yml
simple_oauth.services.yml
1 service uses ClientRepository
simple_oauth.repositories.client in ./simple_oauth.services.yml
Drupal\simple_oauth\Repositories\ClientRepository

File

src/Repositories/ClientRepository.php, line 10

Namespace

Drupal\simple_oauth\Repositories
View source
class ClientRepository implements ClientRepositoryInterface {

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * @var \Drupal\Core\Password\PasswordInterface
   */
  protected $passwordChecker;

  /**
   * Constructs a ClientRepository object.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, PasswordInterface $password_checker) {
    $this->entityTypeManager = $entity_type_manager;
    $this->passwordChecker = $password_checker;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientRepository::$entityTypeManager protected property
ClientRepository::$passwordChecker protected property
ClientRepository::getClientEntity public function
ClientRepository::__construct public function Constructs a ClientRepository object.