Check the request token of a request.

@param \Psr\Http\Message\ServerRequestInterface $request Request.
@return boolean True if valid, false otherwise.
558015
public function check(\Psr\Http\Message\ServerRequestInterface $request)
    {
        $data = $request->getParsedBody();
        if (! is_array($data)) {
            return false;
        }
        if (! isset($data[$this->name])) {
            return false;
        }
        return $this->token === $data[$this->name];
    }
818094
public function hasValidData(\Psr\Http\Message\ServerRequestInterface $request, $key = null)
    {
        if (! in_array($request->getMethod(), ['POST', 'PATCH', 'PUT', 'DELETE'])) {
            return false;
        }
        if (! $this->check($request)) {
            return false;
        }
        $data = $request->getParsedBody();
        return ! isset($key) or isset($data[$key]);
    }
1329225
public function supports(Request $request): bool
    {
        return $request->query->has('jwt') ||
            $request->headers->has('authorization') ||
            ($this->devTenant && ($this->kernel->getEnvironment() === 'dev'));
    }
356443
protected function getToken(Request $request)
    {
        try {
            $this->validateAuthorizationHeader($request);

            $token = $this->parseAuthorizationHeader($request);
        } catch (Exception $exception) {
            if (! $token = $request->query('token', false)) {
                throw $exception;
            }
        }

        return $token;
    }
170866
protected function _getDigest(ServerRequest $request)
    {
        $digest = $request->getEnv('PHP_AUTH_DIGEST');
        if (empty($digest) && function_exists('apache_request_headers')) {
            $headers = apache_request_headers();
            if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Digest ') {
                $digest = substr($headers['Authorization'], 7);
            }
        }
        if (empty($digest)) {
            return false;
        }

        return $this->parseAuthData($digest);
    }
1118156
private function validate(ServerRequestInterface $request, string $tokenValue): bool
    {
        // Validate POST, PUT, DELETE, PATCH requests
        $method = $request->getMethod();
        if (!in_array($method, ['POST', 'PUT', 'DELETE', 'PATCH'])) {
            return true;
        }

        $postData = $request->getParsedBody();

        $requestCsrfToken = null;
        if (isset($postData[$this->name])) {
            $requestCsrfToken = $postData[$this->name];
        }
        if (!$requestCsrfToken) {
            // Reads the value and adds it to the request as the X-XSRF-TOKEN header.
            $headers = $request->getHeader('X-CSRF-Token');
            $requestCsrfToken = reset($headers);
        }

        if ($requestCsrfToken !== $tokenValue) {
            throw new RuntimeException('CSRF middleware failed. Invalid CSRF token. This looks like a cross-site request forgery.');
        }

        return true;
    }
587816
public function validateAuthorization(ServerRequestInterface $request)
    {
        $user = $this->app->make(User::class);

        // Allow logged in users to bypass API authentication entirely if the route allows it
        // This functionality is NOT READY. We will not allow this yet.
        /*
        $route = $request->getAttribute('_route');

        if ($user->checkLogin()) {
            // Return the request with additional attributes
            return $request
                ->withAttribute('oauth_access_token_id', null)
                ->withAttribute('oauth_client_id', null)
                ->withAttribute('oauth_user_id', null)
                ->withAttribute('oauth_scopes', 'session');

            return $request;
        }
        */

        // Delegate the rest to the passed in validator
        return $this->validator->validateAuthorization($request);
    }
125472
protected static function checkHttpXForwardedSsl(Request $request): bool
    {
        return $request->server->has('HTTP_X_FORWARDED_SSL') && 'on' === $request->server->get('HTTP_X_FORWARDED_SSL');
    }
570706
private static function detectDebugMode(ServerRequestInterface $request): bool
    {
        $cookie = $request->getCookieParams();

        $addr = $request->getServerParams()['REMOTE_ADDR'] ?? \php_uname('n');
        $secret = isset($cookie[self::COOKIE_SECRET]) && \is_string($cookie[self::COOKIE_SECRET])
            ? $cookie[self::COOKIE_SECRET]
            : null;

        $list = \is_string(self::$mode)
            ? \array_map('\trim', \explode(',', self::$mode))
            : (array) self::$mode;


        if (
            !$request->hasHeader('X-Forwarded-For') &&
            !$request->hasHeader('Forwarded')
        ) {
            $list[] = '127.0.0.1';
            $list[] = '::1';
        }

        return \in_array($addr, $list, true) || \in_array("$secret@$addr", $list, true);
    }
619393
public function issueToken(ServerRequestInterface $request)
    {
        $response = $this->withErrorHandling(function () use ($request) {
            $input = (array) $request->getParsedBody();
            $clientId = isset($input['client_id']) ? $input['client_id'] : null;

            // Overwrite password grant at the last minute to add support for customized TTLs
            $this->server->enableGrantType(
                $this->makePasswordGrant(), LumenPassport::tokensExpireIn(null, $clientId)
            );

            return $this->server->respondToAccessTokenRequest($request, new Psr7Response);
        });

        if ($response->getStatusCode() < 200 || $response->getStatusCode() > 299) {
            return $response;
        }

        $payload = json_decode($response->getBody()->__toString(), true);

        if (isset($payload['access_token'])) {
            $tokenId = $this->jwt->parse($payload['access_token'])->getClaim('jti');
            $token = $this->tokens->find($tokenId);

            if ($token->client->firstParty() && LumenPassport::$allowMultipleTokens) {
                // We keep previous tokens for password clients
            } else {
                $this->revokeOrDeleteAccessTokens($token, $tokenId);
            }
        }

        return $response;
    }
1252957
protected function isPossibleToGetFromRequest(ServerRequestInterface $request)
    {
        if ($this->allowOverride instanceof OverridePolicyInterface) {
            $allowOverride = $this->allowOverride->isAllowToOverride($request);
        } else {
            $allowOverride = $this->allowOverride;
        }

        return $allowOverride === true && $request->hasHeader($this->requestHeader);
    }
187723
protected function tokenMatches($request) : bool
  {
    if (!isset( $_SESSION['_saini']) || !$_SESSION['_saini']) return false;

    $csrfToken = $request->has('csrf_token') ? $request->input('csrf_token') : ($request->headers->has('X-CSRF-TOKEN') ? $request->header('X-CSRF-TOKEN') : null);
    $sessionToken =  $_SESSION['_saini'];

    if (!hash_equals($sessionToken, $csrfToken)) {
      return false;
    }

    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)
        );
    }
112694
public function requestHasToken(RequestInterface $request)
    {
        $headers = $request->headers('AUTHORIZATION');

        // check the header, then the querystring, then the request body
        return !empty($headers) || (bool) ($request->request($this->config['token_param_name'])) || (bool) ($request->query($this->config['token_param_name']));
    }
1168447
private function checkCsrfToken(Request $request)
    {
        if ($this->csrfTokenManager === null) {
            return;
        }

        $exception = new UnauthorizedException(
            'Missing or invalid CSRF token',
            $request->getMethod() . ' ' . $request->getPathInfo()
        );

        if (!$request->headers->has('X-CSRF-Token')) {
            throw $exception;
        }

        $csrfToken = new CsrfToken(
            $this->csrfTokenIntention,
            $request->headers->get('X-CSRF-Token')
        );

        if (!$this->csrfTokenManager->isTokenValid($csrfToken)) {
            throw $exception;
        }
    }
1251301
function match(RequestInterface $request)
    {
        if (strtoupper($request->getMethod()) !== $this->getMethod())
            return false;

        return parent::match($request);
    }
1202366
public function match(ServerRequestInterface $request)
    {
        $method = strtoupper($request->getMethod());
        if (! empty($this->methods) && ! in_array($method, $this->methods)) {
            return false;
        }
        $uri    = $request->getUri();
        $scheme = $uri->getScheme();
        if (! empty($this->schemes) && ! in_array($scheme, $this->schemes)) {
            return false;
        }
        $path = rtrim($uri->getPath(), '/');

        $regex  = $this->compiled;
        $result = preg_match($regex, $path, $matches);

        if (! $result) {
            return false;
        }

        $params = $this->defaults;
        foreach ($matches as $key => &$value) {
            if (is_int($key)) {
                continue;
            }
            if ($value === '') {
                continue;
            }
            $params[$key] = $value;
        }
        $params['request_method'] = $method;
        $params['request_scheme'] = $scheme;

        return new RouteMatch($params);
    }