You are here

class OauthCredentials in Apigee Edge 8

The API credentials for OAuth.

@todo: move to \Drupal\apigee_edge\Connector namespace.

Hierarchy

Expanded class hierarchy of OauthCredentials

File

src/OauthCredentials.php, line 32

Namespace

Drupal\apigee_edge
View source
class OauthCredentials extends Credentials {

  /**
   * OauthCredentials constructor.
   *
   * @param \Drupal\key\KeyInterface $key
   *   The key entity which stores the API credentials.
   *
   * @throws \InvalidArgumentException
   *   An InvalidArgumentException is thrown if the key type
   *   does not implement EdgeKeyTypeInterface.
   */
  public function __construct(KeyInterface $key) {
    if ($key
      ->getKeyType() instanceof EdgeKeyTypeInterface && ($auth_type = $key
      ->getKeyType()
      ->getAuthenticationType($key)) && $auth_type === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH) {
      parent::__construct($key);
    }
    else {
      throw new InvalidArgumentException("The `{$key->id()}` key is not configured for OAuth.");
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getAuthentication() : Authentication {
    return $this->keyType
      ->getAuthenticationMethod($this->key);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Credentials::$key protected property The key entity which stores the API credentials.
Credentials::$keyType protected property The key type of the key entity.
Credentials::getKey public function Gets the key entity which stores the API credentials. Overrides CredentialsInterface::getKey
Credentials::getKeyType public function Gets the key type of the key entity. Overrides CredentialsInterface::getKeyType
OauthCredentials::getAuthentication public function Gets the authentication object which instantiated by the key type. Overrides Credentials::getAuthentication
OauthCredentials::__construct public function OauthCredentials constructor. Overrides Credentials::__construct