The validateTokens event is triggered before every request.

It's a moment where this plugin can check all the supplied lock tokens
in the If: header, and check if they are valid.

@param RequestInterface $request
@param array            $conditions
13959
public function validateTokens(RequestInterface $request, &$conditions)
    {
        foreach ($conditions as $kk => $condition) {
            foreach ($condition['tokens'] as $ii => $token) {
                // Sync-tokens must always start with our designated prefix.
                if (self::SYNCTOKEN_PREFIX !== substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX))) {
                    continue;
                }

                // Checking if the token is a match.
                $node = $this->server->tree->getNodeForPath($condition['uri']);

                if (
                    $node instanceof ISyncCollection &&
                    $node->getSyncToken() == substr($token['token'], strlen(self::SYNCTOKEN_PREFIX))
                ) {
                    $conditions[$kk]['tokens'][$ii]['validToken'] = true;
                }
            }
        }
    }
924720
public function init(RequestInterface $request)
    {
        $translator = $this->translator();

        $notice = $request->getParam('notice');
        switch ($notice) {
            case 'resetpass':
                $message = $translator->translate('Check your email for instructions to reset your password.');
                $this->addFeedback([
                    'level'       => 'notice',
                    'message'     => $message,
                    'dismissible' => false
                ]);
                break;

            case 'newpass':
                $message = $translator->translate('Log in with your new password.');
                $this->addFeedback([
                    'level'       => 'notice',
                    'message'     => $message,
                    'dismissible' => false
                ]);
                break;
        }

        return true;
    }
1120690
private function isValidCsrfToken(Request $request): bool
    {
        $csrfTokenValue = $request->headers->get(self::CSRF_TOKEN_HEADER);

        return $this->csrfTokenManager->isTokenValid(
            new CsrfToken('authenticate', $csrfTokenValue)
        );
    }
102832
public function checkForToken(Request $request)
    {
        if (! $this->auth->parser()->setRequest($request)->hasToken()) {
            throw new UnauthorizedHttpException('jwTauth', 'Token not provided');
        }
    }
437884
public function process(RequestInterface $request): bool
    {
        if (!$request->getMethod()->isPost()) {
            return false;
        }

        if ($this->checkOriginEnabled && !self::isValidOrigin($request)) {
            return false;
        }

        return $this->doProcess($request->getFormParameters(), $request->getUploadedFiles());
    }
1105646
public function validateRequest(RequestInterface $request, ResponseInterface $response)
	{
		// ensure we have needed params
		if (!$request->request("password") || !$request->request("username"))
		{
			$response->setError(400, 'invalid_request', 'Missing parameters: "username" and "password" required');
			return null;
		}

		// check username/password
		if (!$this->storage->checkUserCredentials($request->request("username"), $request->request("password")))
		{
			$response->setError(401, 'invalid_grant', 'Invalid username and password combination');
			return null;
		}

		// get user details by username
		$userInfo = $this->storage->getUserDetails($request->request("username"));

		// make sure we got an array of user details
		if (empty($userInfo))
		{
			$response->setError(400, 'invalid_grant', 'Unable to retrieve user information');
			return null;
		}

		// if not set, something went wrong
		if (!isset($userInfo['user_id']))
		{
			throw new \LogicException("you must set the user_id on the array returned by getUserDetails");
		}

		// set our userinfo for later use
		$this->userInfo = $userInfo;

		// return sucess
		return true;
	}
371685
public function onRequest( RequestInterface $request ) {
        $schema = $this->getEndpoint()->getSchema();

        return $request->withHeader( 'X-Schema-Version', $schema );
    }
964327
public function init(RequestInterface $request)
    {
        // Undocumented Slim 3 feature: The route attributes are stored in routeInfo[2].
        $routeInfo = $request->getAttribute('routeInfo');

        if (isset($routeInfo[2]['token'])) {
            $this->lostPasswordToken = $routeInfo[2]['token'];
        } else {
            $this->lostPasswordToken = $request->getParam('token');
        }

        if ($this->lostPasswordToken && $this->validateToken($this->lostPasswordToken)) {
            return true;
        }

        header('HTTP/1.0 400 Bad Request');
        header('Location: '.$this->adminUrl('account/lost-password?notice=invalidtoken'));
        exit;
    }
1285873
private function parseToken(Request $request) : ?Token
    {
        $cookies    = $request->getCookieParams();
        $cookieName = $this->defaultCookie->getName();

        if (! isset($cookies[$cookieName])) {
            return null;
        }

        try {
            $token = $this->tokenParser->parse($cookies[$cookieName]);
        } catch (\InvalidArgumentException $invalidToken) {
            return null;
        }

        if (! $token->validate(new ValidationData())) {
            return null;
        }

        return $token;
    }
219965
public function match(RequestInterface $request, array &$attrs = null): bool
    {
        foreach ($this->headers as $checkFunc) {
            if (!$checkFunc($request)) return false;
        }
        return true;
    }
175100
protected function authentication(RequestInterface $request)
	{
		if ($this->tokenRequired)
		{
			return $request->withHeader('Authorization', sprintf('OAuth %s', $this->getAccessToken()));
		}

		return $request;
	}
1315146
protected function sendErrorEvent(RequestInterface $request, $reason)
    {
        $key = $this->getEventKey($request);
        $event = $this->events[$key];

        unset($this->events[$key]);

        $event->setExecutionStop();
        $event->setReason($reason);
        $this->eventDispatcher->dispatch(GuzzleHttpEvent::EVENT_ERROR_NAME, $event);
    }
813246
protected function validate(Request $request)
    {
        $validator = $this->resolveValidator($request);

        if ($validator) {
            $validator->validate($request);
        }
    }
1219484
protected function validateConditions(array $conditions)
    {
        foreach ($conditions as $key => $val) {
            if ($this->referenceResolver->isReference($key)) {
                return true;
            }
        }

        return parent::validateConditions($conditions);
    }
855225
public function validateWith($validator, Request $request = null)
    {
        $request = $request ?: app('request');

        if (is_array($validator)) {
            $validator = $this->getValidationFactory()->make($request->all(), $validator);
        }

        if ($validator->fails()) {
            $this->throwValidationException($request, $validator);
        }
    }
491819
public function validate(Request $request)
    {
        $options = $request->getParameters();

        $this->ensureAllInRules($options)
             ->ensureValid($options);
    }
1340690
public function process(Request $request, FormInterface $form)
    {
        if ($request->isMethod('POST')) {
            $form->submit($request);
            if ($form->isValid()) {
                return true;
            }
        }

        return false;
    }