You are here

private function Base::authenticate in DRD Agent 8.3

Same name and namespace in other branches
  1. 4.0.x src/Agent/Action/Base.php \Drupal\drd_agent\Agent\Action\Base::authenticate()

Authenticate the request or throw an exception.

Parameters

string $uuid: The uuid of the calling DRD instance.

array $args: Array of arguments.

Return value

$this

Throws

\RuntimeException

1 call to Base::authenticate()
Base::run in src/Agent/Action/Base.php
Main callback to execute an action.

File

src/Agent/Action/Base.php, line 304

Class

Base
Base class for Remote DRD Action Code.

Namespace

Drupal\drd_agent\Agent\Action

Code

private function authenticate($uuid, array $args) : self {
  $auth_methods = AuthBase::getMethods($this->container);
  if (!isset($auth_methods[$args['auth']]) || !$auth_methods[$args['auth']] instanceof AuthBaseInterface) {
    throw new RuntimeException('Unrecognized authentication method');
  }

  /** @var \Drupal\drd_agent\Agent\Auth\BaseInterface $auth */
  $auth = $auth_methods[$args['auth']];
  if (!$auth
    ->validateUuid($uuid)) {
    throw new RuntimeException('DRD instance not registered');
  }
  if (!$auth
    ->validate($args['authsetting'])) {
    throw new RuntimeException('Not authenticated');
  }
  return $this;
}