@param ServerRequestInterface $request
@param ClientEntityInterface  $client

@throws OAuthServerException

@return UserEntityInterface
438938
protected function validateUser(ServerRequestInterface $request, ClientEntityInterface $client)
    {
        $username = $this->getRequestParameter('username', $request);
        if (is_null($username)) {
            throw OAuthServerException::invalidRequest('username');
        }

        $password = $this->getRequestParameter('password', $request);
        if (is_null($password)) {
            throw OAuthServerException::invalidRequest('password');
        }

        $user = $this->userRepository->getUserEntityByUserCredentials(
            $username,
            $password,
            $this->getIdentifier(),
            $client
        );
        if ($user instanceof UserEntityInterface === false) {
            $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request));

            throw OAuthServerException::invalidCredentials();
        }

        return $user;
    }
1322203
public function webhook(?ServerRequestInterface $request = null): Webhook
    {
        return new Webhook($this->appSecret, $this->verifyToken, $this->pageToken, $this->client, $request);
    }
274570
public function oauthCallbackAction(Request $request, Session $session, Client $client): RedirectResponse
    {
        // Give up if the required GET params or stored request token don't exist.
        if (!$request->get('oauth_verifier')) {
            throw $this->createNotFoundException('No OAuth verifier given.');
        }
        if (!$session->has('oauth.request_token')) {
            throw $this->createNotFoundException('No request token found. Please try logging in again.');
        }

        // Complete authentication.
        $token = $session->get('oauth.request_token');
        $verifier = $request->get('oauth_verifier');
        $accessToken = $client->complete($token, $verifier);

        // Store access token, and remove request token.
        $session->set('oauth.access_token', $accessToken);
        $session->remove('oauth.request_token');

        // Regenerate session ID.
        $session->migrate();

        // Store user identity.
        $ident = $client->identify($accessToken);
        $session->set('logged_in_user', $ident);

        // Send to homepage.
        return $this->redirectToRoute('home');
    }
1146799
public function getUserEntityByUserCredentials(
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    ): ?UserEntityInterface {
        $builder = $this->connection->createQueryBuilder();
        $user = $builder->select(['user.id', 'user.password'])
            ->from('user')
            ->where('username = :username')
            ->setParameter('username', $username)
            ->execute()
            ->fetch();

        if (!$user) {
            return null;
        }

        if (!password_verify($password, $user['password'])) {
            return null;
        }

        return new User(Uuid::fromBytesToHex($user['id']));
    }
843686
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
    {
        $token = new AccessToken();

        $token->setUserIdentifier($userIdentifier);

        return $token;
    }
487323
public function execute(Client $client)
    {
        if (!$this->request instanceof Request) {
            throw new \InvalidArgumentException('request is not an instanceof \GuzzleHttp\Message\Request');
        }

        $this->copyClientDefaults($client);

        return $client->send($this->request);
    }
294673
public static function sendRequest(RequestEntity $requestEntity) {
	    /** @var Request $request */
	    $request = self::buildRequestClass($requestEntity);
	    $begin = microtime(true);
        try {
	        $response = $request->send();
        } catch(yii\httpclient\Exception $e) {
            throw new ServerErrorHttpException('Url "' . $request->url . '" is not available', null, $e);
        }
	    $end = microtime(true);
	    $duration = $end - $begin;
        return self::buildResponseEntity($response, $duration);
    }
48810
protected function createClient( ServerRequestInterface $request, $resource )
	{
		$args = $request->getAttributes();
		$params = $request->getQueryParams();
		$related = ( isset( $args['related'] ) ? $args['related'] : ( isset( $params['related'] ) ? $params['related'] : null ) );

		$tmplPaths = $this->container->get( 'aimeos' )->get()->getCustomPaths( 'client/jsonapi/templates' );
		$context = $this->container->get( 'aimeos.context' )->get();
		$langid = $context->getLocale()->getLanguageId();

		$view = $this->container->get( 'aimeos.view' )->create( $context, $tmplPaths, $langid );
		$context->setView( $view );

		return \Aimeos\Client\JsonApi::create( $context, $resource . '/' . $related );
	}
788273
private function assertClient(ClientInterface $client)
    {
        if ($client->getConnection() instanceof AggregateConnectionInterface) {
            throw new NotSupportedException(
                'Cannot initialize a MULTI/EXEC transaction over aggregate connections.'
            );
        }

        if (!$client->getProfile()->supportsCommands(array('MULTI', 'EXEC', 'DISCARD'))) {
            throw new NotSupportedException(
                'The current profile does not support MULTI, EXEC and DISCARD.'
            );
        }
    }
166854
public function setRemoteUser(ClientInterface $client, IdentityInterface $user)
    {
        $model = $this->getRemoteUser($client);
        $model->client_id = $user->getId();
        $model->save();

        return $user;
    }
443468
private function addClient(ClientInterface $client): self
    {
        $configurations = $this->configResolver->getParameter('configurations', 'ez_platform_automated_translation');
        $reflection     = new \ReflectionClass($client);
        $key            = strtolower($reflection->getShortName());
        if (isset($configurations[$key])) {
            $client->setConfiguration($configurations[$key]);
            $this->clients[$key] = $client;
        }

        return $this;
    }
290602
protected function passIssueToken(array $parameters, ClientInterface $determinedClient = null): ResponseInterface
    {
        // if client is not given we interpret it as a 'default' client should be used
        if ($determinedClient === null) {
            $determinedClient = $this->passGetIntegration()->passReadDefaultClient();
            if ($determinedClient->hasCredentials() === true) {
                throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_UNAUTHORIZED_CLIENT);
            }
        }

        if ($determinedClient !== null && $determinedClient->isPasswordGrantEnabled() === false) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_UNAUTHORIZED_CLIENT);
        }

        $scope = $this->passGetScope($parameters);
        list ($isScopeValid, $scopeList, $isScopeModified) =
            $this->passGetIntegration()->passValidateScope($determinedClient, $scope);
        if ($isScopeValid === false) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_SCOPE);
        }

        if (($userName = $this->passGetUserName($parameters)) === null ||
            ($password = $this->passGetPassword($parameters)) === null
        ) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_REQUEST);
        }

        $response = $this->passGetIntegration()->passValidateCredentialsAndCreateAccessTokenResponse(
            $userName,
            $password,
            $determinedClient,
            $isScopeModified,
            $scopeList,
            $parameters
        );

        return $response;
    }
214057
protected function getClient(Request $request)
    {
        $client = $this->apiClientRepository->findOneByKeyAndSecret($request->getUser(), $request->getPassword());
        if (!$client instanceof ApiClientInterface) {
            throw new BadClientCredentialsHttpException();
        } elseif ($client->isBlocked()) {
            throw new ClientBlockedHttpException();
        } elseif (!$client->isTrusted()) {
            throw new ClientNonTrustedHttpException();
        }

        return $client;
    }
1301523
public function setHttpClient(Client $client = null)
    {
        if ($client === null) {
            $client = new Client(
                HttpClientDiscovery::find(),
                MessageFactoryDiscovery::find()
            );
        }
        $this->client = $client;
        return $this;
    }
62606
public function send(RequestEntity $requestEntity) {
		$request = $this->createHttpRequest($requestEntity);
		try {
			$response = $request->send();
		
		} catch(\yii\httpclient\Exception $e) {
			throw new ServerErrorHttpException('Url "' . $request->url . '" is not available');
		}
		
		if($response->statusCode >= 400) {
			$this->showUserException($response);
		}
		if($response->statusCode >= 500) {
			$this->showServerException($response);
		}
		if($response->statusCode == 201 || $response->statusCode == 204) {
			$response->content = null;
		}
		return $response;
	}
1080996
public function findIdentityByAuthClient(ClientInterface $client)
    {
        $remote = $this->getRemoteUser($client);
        if (!$remote->provider) {
            return null;
        }
        if ($remote->client_id) {
            return $this->findIdentity($remote->client_id);
        }
        $email = $client->getUserAttributes()['email'];
        $user = $this->findIdentityByEmail($email);
        if (!$user) {
            return null;
        }
        if ($remote->isTrustedEmail($email)) {
            return $this->setRemoteUser($client, $user);
        }

        return null;
    }
735437
protected function createPersonalClient(ClientRepository $clients)
    {
        $name = $this->option('name') ?: $this->ask(
            'What should we name the personal access client?',
            config('app.name').' Personal Access Client'
        );

        $client = $clients->createPersonalAccessClient(
            null, $name, 'http://localhost'
        );

        $this->info('Personal access client created successfully.');

        $this->outputClientDetails($client);
    }