Checks that a provided grant is valid, or attempts to produce one if the
provided grant is a string.

@param  AbstractGrant|string $grant
@return AbstractGrant
426307
protected function verifyGrant($grant)
    {
        if (is_string($grant)) {
            return $this->grantFactory->getGrant($grant);
        }

        $this->grantFactory->checkGrant($grant);
        return $grant;
    }
306203
public function setHelp($help)
    {
        if (null !== $help) {
            Assert::string($help, 'The help text must be a string. Got: %s');
            Assert::notEmpty($help, 'The help text must not be empty.');
        }

        $this->help = $help;

        return $this;
    }
274509
public function grant(IRequest $request)
    {
        if (!$refreshTokenIdentifier = $request->request('refresh_token')) {
            throw new MissingParameterException("Parameter 'refresh_token' is missing.");
        }

        if (!$refreshToken = $this->refreshTokenStorage->get($refreshTokenIdentifier)) {
            throw new InvalidGrantException('Invalid refresh token.');
        }

        $client = $this->clientAuthenticator->authenticate($request);

        // are clients same?
        if ($client->getId() !== $refreshToken->getClient()->getId()) {
            throw new InvalidGrantException('Invalid refresh token.');
        }

        // is client allowed to use this grant type?
        if (!$client->isAllowedToUse($this)) {
            throw new UnauthorizedClientException('Client can not use this grant type.');
        }

        $expiresAt = $refreshToken->getExpiresAt();

        if ($expiresAt instanceof \DateTime) {
            $expiresAt = $expiresAt->getTimestamp();
        }

        // is refresh token expired?
        if ($expiresAt < time()) {
            throw new InvalidGrantException('Refresh token has expired.');
        }

        // intersection of refresh token and requested scopes
        $scopes = $this->scopeResolver->intersect($request->request('scope'), $refreshToken->getScopes());

        return $this->accessTokenStorage->generate(
            $refreshToken->getUser(),
            $refreshToken->getClient(),
            $scopes
        );
    }
1275205
public function send(AbstractRequest $request)
    {
        $handle = HandleFactory::build($request);
        $this->dispatch(MessageEvent::REQUEST, new MessageEvent($request));

        try {
            $result = $handle->execute();
        } catch (\Exception $error) {
            if ($error instanceof CurlException) {
                $response = ResponseFactory::build('', $handle->infos(), $request);
                $error->setResponse($response);
            }
            $this->dispatch(ErrorEvent::ERROR, new ErrorEvent($error));
            throw $error;
        }

        $response = ResponseFactory::build($result, $handle->infos(), $request);
        $this->dispatch(MessageEvent::RESPONSE, new MessageEvent($response));

        return $response;
    }
1207422
protected function registerDefaultGrant($name)
    {
        // PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
        $class = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $name)));
        $class = 'League\\OAuth2\\Client\\Grant\\' . $class;

        $this->checkGrant($class);

        return $this->setGrant($name, new $class);
    }
1058193
public function validate($data) {
        $result = parent::validate($data);
        if ($result !== true) {
            return $result;
        }
        $runningmethod = get_config('antivirus_clamav', 'runningmethod');
        if ($runningmethod === 'unixsocket') {
            $socket = stream_socket_client('unix://' . $data, $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
            if (!$socket) {
                return get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
            } else {
                // Send PING query to ClamAV socket to check its running state.
                fwrite($socket, "nPING\n");
                $response = stream_get_line($socket, 4);
                fclose($socket);
                if ($response !== 'PONG') {
                    return get_string('errorclamavnoresponse', 'antivirus_clamav');
                }
            }
        }
        return true;
    }
1317111
private function assertValidResource($resource)
    {
        $resource = (string) $resource;
        // All resources are basic ASCII, so we can ignore the fact that `strtolower` doesn't handle UTF-8 well.
        $resource = strtolower($resource);

        if (!in_array($resource, static::VALID_RESOURCES)) {
            throw new InvalidResourceException($resource);
        }

        return $resource;
    }
465010
private function verifyExtension($extension)
    {
        $allowed = $this->config['allowed_extensions'];
        if (! empty($allowed) && ! in_array(strtolower($extension), $allowed)) {
            throw FileNotSupportedException::extensionRestricted(strtolower($extension), $allowed);
        }

        return $extension;
    }
100160
public function validateParameters(&$parameters)
    {
        if (!isset($parameters['username']))
        {
            throw new InvalidArgumentException(
                'The \'username\' parameter must be defined for the Password grant type',
                InvalidArgumentException::MISSING_PARAMETER
            );
        }
        elseif (!isset($parameters['password']))
        {
            throw new InvalidArgumentException(
                'The \'password\' parameter must be defined for the Password grant type',
                InvalidArgumentException::MISSING_PARAMETER
            );
        }
    }
1051813
private function _validateHolder(): Certificate
    {
        $path = $this->_config->holderPath();
        $config = PathValidationConfig::defaultConfig()->withMaxLength(
            count($path))->withDateTime($this->_config->evaluationTime());
        try {
            $holder = $path->validate($config, $this->_crypto)->certificate();
        } catch (PathValidationException $e) {
            throw new ACValidationException(
                "Failed to validate holder PKC's certification path.", 0, $e);
        }
        if (!$this->_ac->isHeldBy($holder)) {
            throw new ACValidationException("Name mismatch of AC's holder PKC.");
        }
        return $holder;
    }
274803
protected function makePasswordGrant()
    {
        $grant = new PasswordGrant(
            $this->app->make(Bridge\UserRepository::class),
            $this->app->make(Bridge\RefreshTokenRepository::class)
        );

        $grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());

        return $grant;
    }
1232549
function attainAuthorizationUrl(iGrantAuthorizeRequest $grant)
    {
        # Build Authorize Url

        $grantParams = $grant->assertAuthorizeParams();
        $response    = $this->call( new GetAuthorizeUrl($grantParams) );

        if ( $ex = $response->hasException() )
            throw $ex;

        return $response->expected();
    }
734796
public function has($key)
    {
        if (!is_string($key)) {
            throw new \InvalidArgumentException(htmlspecialchars(
                "Get function only accepts strings. Input was: $key."
            ));
        }

        return isset($this->services[ $key ]) || isset($this->instances[ $key ]);
    }
55214
public function invoke(AbstractRequest $request)
    {
        $this->invoker->invoke($request);
        $current = clone $request->resourceObject;
        foreach ($request->links as $link) {
            /* @noinspection ExceptionsAnnotatingAndHandlingInspection */
            $nextResource = $this->annotationLink($link, $current, $request);
            $current = $this->nextLink($link, $current, $nextResource);
        }

        return $current;
    }
374277
protected static function validatePassword($password) {
		if (empty($password)) {
			throw new InvalidPasswordException();
		}

		$password = \trim($password);

		if (\strlen($password) < 1) {
			throw new InvalidPasswordException();
		}

		return $password;
	}
650294
public function setExtension($extension)
    {
        if (is_string($extension) && preg_match(Number::GUID_REGEX, $extension)) {
            return $this->extension_guid = $extension;
        }
        if ($extension instanceof Extension) {
            return $this->extension_guid = $extension->guid;
        }
        return false;
    }
190295
public function get($uri, AbstractRequest $request = null)
    {
        $http = $this->getHttpClone();

        if ($request) {
            $requestUri = $this->buildQuery($uri, $request->getQuery());
        } else {
            $requestUri = $uri;
        }

        $http->setOption(CURLOPT_URL, $requestUri);

        return $http->execute();
    }