You are here

public function ApigeeAuthKeyType::getAuthenticationMethod in Apigee Edge 8

Gets the authentication method object.

Parameters

\Drupal\key\KeyInterface $key: The key entity.

Return value

\Http\Message\Authentication The authentication object.

Overrides KeyTypeAuthenticationMethodInterface::getAuthenticationMethod

File

src/Plugin/KeyType/ApigeeAuthKeyType.php, line 136

Class

ApigeeAuthKeyType
Key type for Apigee Edge authentication credentials.

Namespace

Drupal\apigee_edge\Plugin\KeyType

Code

public function getAuthenticationMethod(KeyInterface $key) : Authentication {
  $values = $key
    ->getKeyValues();
  if ($this
    ->getInstanceType($key) === EdgeKeyTypeInterface::INSTANCE_TYPE_HYBRID) {
    if ($this
      ->useGcpDefaultServiceAccount($key)) {
      return new GceServiceAccountAuthentication(\Drupal::service('apigee_edge.authentication.oauth_token_storage'));
    }
    else {
      $account_key = $this
        ->getAccountKey($key);
      return new HybridAuthentication($account_key['client_email'], $account_key['private_key'], \Drupal::service('apigee_edge.authentication.oauth_token_storage'));
    }
  }
  elseif ($values['auth_type'] === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_OAUTH) {

    // Use Oauth authentication.
    return new OauthAuthentication($this
      ->getUsername($key), $this
      ->getPassword($key), \Drupal::service('apigee_edge.authentication.oauth_token_storage'), NULL, $this
      ->getClientId($key), $this
      ->getClientSecret($key), NULL, $this
      ->getAuthorizationServer($key));
  }
  else {

    // Use basic authentication.
    return new BasicAuth($this
      ->getUsername($key), $this
      ->getPassword($key));
  }
}