You are here

public function OauthCredentials::__construct in Apigee Edge 8

OauthCredentials constructor.

Parameters

\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.

Overrides Credentials::__construct

File

src/OauthCredentials.php, line 44

Class

OauthCredentials
The API credentials for OAuth.

Namespace

Drupal\apigee_edge

Code

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.");
  }
}