You are here

abstract class Oauth2ClientServiceBase in OAuth2 Client 8.3

Same name and namespace in other branches
  1. 8.2 src/Service/Oauth2ClientServiceBase.php \Drupal\oauth2_client\Service\Oauth2ClientServiceBase

Base class for OAuth2 Client services.

Hierarchy

Expanded class hierarchy of Oauth2ClientServiceBase

1 file declares its use of Oauth2ClientServiceBase
Oauth2ClientGrantServiceBase.php in src/Service/Grant/Oauth2ClientGrantServiceBase.php

File

src/Service/Oauth2ClientServiceBase.php, line 11

Namespace

Drupal\oauth2_client\Service
View source
abstract class Oauth2ClientServiceBase implements Oauth2ClientServiceInterface {

  /**
   * The OAuth2 Client plugin manager.
   *
   * @var \Drupal\oauth2_client\PluginManager\Oauth2ClientPluginManagerInterface
   */
  protected $oauth2ClientPluginManager;

  /**
   * {@inheritdoc}
   */
  public function getClient($pluginId) {
    $clients =& drupal_static(__CLASS__ . '::' . __FUNCTION__, []);
    if (!isset($clients[$pluginId])) {
      $definition = $this->oauth2ClientPluginManager
        ->getDefinition($pluginId);
      if (!$definition || !isset($definition['id'])) {
        throw new InvalidOauth2ClientException($pluginId);
      }
      $clients[$pluginId] = $this->oauth2ClientPluginManager
        ->createInstance($definition['id']);
    }
    return $clients[$pluginId];
  }

  /**
   * {@inheritdoc}
   */
  public function retrieveAccessToken($pluginId) {
    $client = $this
      ->getClient($pluginId);
    $token = $client
      ->retrieveAccessToken();
    if ($token instanceof AccessTokenInterface) {
      return $token;
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function clearAccessToken($pluginId) {
    $client = $this
      ->getClient($pluginId);
    $client
      ->clearAccessToken();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Oauth2ClientServiceBase::$oauth2ClientPluginManager protected property The OAuth2 Client plugin manager. 1
Oauth2ClientServiceBase::clearAccessToken public function Clears the access token for the given client. Overrides Oauth2ClientServiceInterface::clearAccessToken
Oauth2ClientServiceBase::getClient public function Retrieve an OAuth2 Client Plugin. Overrides Oauth2ClientServiceInterface::getClient
Oauth2ClientServiceBase::retrieveAccessToken public function Retrieve an access token from storage. Overrides Oauth2ClientServiceInterface::retrieveAccessToken