You are here

public function Base::ott in DRD Agent 4.0.x

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

Validate a one-time-token.

Parameters

string $ott: Token to be validated.

string $remoteSetupToken: Base64 encoded RemoteSetupToken from DRD.

Return value

bool TRUE if token is valid and configuration succeeded, FALSE otherwise.

Overrides BaseInterface::ott

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

File

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

Class

Base
Base class for Remote DRD Action Code.

Namespace

Drupal\drd_agent\Agent\Action

Code

public function ott($token, $remoteSetupToken) : bool {
  $ott = $this->state
    ->get('drd_agent.ott', FALSE);
  if (!$ott) {
    $this
      ->watchdog('No OTT available', [], LogLevel::ERROR);
    return FALSE;
  }
  $this->state
    ->delete('drd_agent.ott');
  if (empty($ott['expires']) || $ott['expires'] < $this->time
    ->getRequestTime()) {
    $this
      ->watchdog('OTT expired', [], LogLevel::ERROR);
    return FALSE;
  }
  if (empty($ott['token']) || $ott['token'] !== $token) {
    $this
      ->watchdog('Token missmatch: :local / :remote', [
      ':local' => $ott['token'],
      ':remote' => $token,
    ], LogLevel::ERROR);
    return FALSE;
  }

  /* @var \Drupal\drd_agent\Setup $service */
  $service = $this->container
    ->get('drd_agent.setup');
  $service
    ->setRemoteSetupToken($remoteSetupToken)
    ->execute();
  $this
    ->watchdog('OTT config completed', [], LogLevel::INFO);
  return TRUE;
}