You are here

public function GenericValidation::processRequest in Two-factor Authentication (TFA) 8

Processes the request and returns an array of data as appropriate.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object.

\Symfony\Component\Serializer\SerializerInterface $serializer: The serializer. Some methods might require the plugin to leverage the serializer after extracting the request contents.

Return value

array The response.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

Overrides ServiceDefinitionInterface::processRequest

File

services_tfa/src/Plugin/ServiceDefinition/GenericValidation.php, line 100

Class

GenericValidation
TFA web service.

Namespace

Drupal\services_tfa\Plugin\ServiceDefinition

Code

public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer) {
  $uid = $request
    ->get('id');
  $code = $request
    ->get('code');
  $plugin_id = $request
    ->get('plugin_id');
  if ($uid && $code && $plugin_id) {
    $this->validationPlugin = $this->tfaValidationManager
      ->createInstance($plugin_id, [
      'uid' => $uid,
    ]);

    // @todo validateRequest is not part of TfaValidationInterface.
    $valid = $this->validationPlugin
      ->validateRequest($code);
    if ($this->validationPlugin
      ->isAlreadyAccepted()) {
      throw new AccessDeniedHttpException('Invalid code, it was recently used for a login. Please try a new code.');
    }
    elseif (!$valid) {
      throw new AccessDeniedHttpException('Invalid application code. Please try again.');
    }
    else {
      return 1;
    }
  }
  else {
    throw new AccessDeniedHttpException('Required parameters missing.');
  }
}