Do a remote call.
@param $request The Request instance
@param $isLogin Boolean whether this request is a login request or not
@return The Response instance
9899
protected function doRemoteCall(Request $request, $isLogin) {
    // initially login, if no sessionId is set
    $sessionId = $this->getSessionId();
    if (!$isLogin && $sessionId == null) {
      $response = $this->doLogin();
      if ($response) {
  	    $sessionId = $this->getSessionId();
      }
    }

    $jsonResponse = null;
    $returnValue = -1;

    $request->setResponseFormat('json');
    $serializedRequest = base64_encode(serialize($request));

    $arguments = [
      $serializedRequest,
      $sessionId
    ];
    $currentDir = getcwd();
    chdir(dirname($this->serverCli));
    if (self::$logger->isDebugEnabled()) {
      self::$logger->debug("Do remote call to: ".$this->serverCli);
      self::$logger->debug("Request:\n".$request->toString());
    }
    // store and reopen the session (see http://bugs.php.net/bug.php?id=44942)
    session_write_close();
    exec($this->php.' '.$this->serverCli.' '.join(' ', $arguments), $jsonResponse, $returnValue);
    session_start();
    if (self::$logger->isDebugEnabled()) {
      self::$logger->debug("Response [JSON]:\n".$jsonResponse[0]);
    }
    chdir($currentDir);

    $responseData = json_decode($jsonResponse[0], true);
    $response = ObjectFactory::getNewInstance('response');
    $response->setValues($responseData);
    $response->setFormat('json');
    $formatter = ObjectFactory::getInstance('formatter');
    $formatter->deserialize($response);
    if (self::$logger->isDebugEnabled()) {
      self::$logger->debug("Response:\n".$response->toString());
    }

    if (!$response->getValue('success')) {
      // if the session expired, try to relogin
      if (strpos('Authorization failed', $response->getValue('errorMsg')) === 0 && !$isLogin) {
        $this->doLogin();
      }
      else {
        $this->handleError($response);
      }
    }
    return $response;
  }
617239
private function login(ServerRequestInterface $request)
    {
        //Check header
        $authorization = $this->parseHeader($request->getHeaderLine('Authorization'));

        if (!$authorization) {
            return false;
        }

        //Check the user
        if (!isset($this->users[$authorization['username']])) {
            return false;
        }

        if ($this->users[$authorization['username']] !== $authorization['password']) {
            return false;
        }

        return $authorization['username'];
    }
663536
public function execute(RequestInterface $request): RequestInterface
    {
        if (is_null($this->sessionToken)) {
            return $request;
        } else {
            return $request->withHeader(
                self::HEADER_CLIENT_AUTHENTICATION,
                [$this->sessionToken->getToken()]
            );
        }
    }
1043785
protected function sendFailedLoginResponse( Request $request )
	{
		return Redirect::back()->withInput( $request->only( $this->loginUsername(), 'remember' ) )->withErrors( [
				$this->loginUsername() => $this->getFailedLoginMessage(),
			] );
	}
1069460
public function loginAction(Request $request)
    {
        if ($this->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)) {
            return $this->redirectToRoute($this->getParameter('darvin_user.already_logged_in_redirect_route'));
        }

        return new Response($this->getSecurityFormRenderer()->renderLoginForm($request->isXmlHttpRequest()));
    }
349289
public function createSessionFromRequest($request, $resolver)
    {
        if (!$this->isRestController($resolver)) {
            return false;
        }
        /** @var SessionBuilder $builder */
        foreach ($this->getSessionBuilders() as $builder) {
            if ($builder->isApplicable($request)) {
                return $this->startSession($builder->getSession($request));
            }
        }
        throw new LoginFailedException(array('Request cannot be authenticated.'));
    }
46859
protected function _handleLoginAction(ServerRequest $request, Response $response)
    {
        $request->allowMethod($this->getConfig('requestMethod'));

        $providerName = $request->getParam('provider');
        $provider = $this->_getService($request)->getProvider($providerName);
        $authUrl = $provider->makeAuthUrl();

        $this->_setRedirectUrl($request);

        return $response->withLocation($authUrl);
    }
359711
private function login(ServerRequestInterface $request, &$username)
    {
        //Check header
        $authorization = self::parseAuthorizationHeader($request->getHeaderLine('Authorization'));

        if (!$authorization) {
            return false;
        }

        //Check whether user exists
        if (!isset($this->users[$authorization['username']])) {
            return false;
        }

        $username = $authorization['username'];

        //Check authentication
        return $this->checkAuthentication($authorization, $request->getMethod(), $this->users[$username]);
    }
61496
public static function checkAuthentication($redirect = true)
    {
        if(static::isAuthenticated()) {
            return;
        }

        if ($redirect) {
            Http\Server::getInstance()->redirect(RouteCollection::getInstance()->get('login')->getUri());
        } else {
            throw new LoginException();
        }
    }
150976
public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');

        try {
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->json(['error' => 'invalid_credentials'], 401);
            }
        } catch (JWTException $e) {
            return response()->json(['error' => 'could_not_create_token'], 500);
        }

        return response()->json(compact('token'));
    }
1171862
public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }
566154
public function __doRequest($request, $location, $action, $version, $oneway=0){
      if (self::$logger->isDebugEnabled()) {
        self::$logger->debug("Request:");
        self::$logger->debug($request);
      }
      $response = trim(parent::__doRequest($request, $location, $action, $version, $oneway));
      if (self::$logger->isDebugEnabled()) {
        self::$logger->debug("Response:");
        self::$logger->debug($response);
        self::$logger->debug($this->getDebugInfos());
      }
      $parsedResponse = preg_replace('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $response);
      // fix missing last e> caused by php's built-in webserver
      if (preg_match('/^<\?xml/', $parsedResponse) && !preg_match('/e>$/', $parsedResponse)) {
        $parsedResponse .= 'e>';
      }
      return $parsedResponse;
  }
520712
public function send(RequestInterface $request, array $options = [])
    {
        $response = parent::send($request, $options);

        // re-authenticate if 403 and token is expired
        if (
            $this->token &&
            $response->getStatusCode() === 403 &&
            $this->isTokenExpired($this->token) &&
            !$this->authenticate()
        ) {
            throw new ClientException('Cannot re-authenticate.');
        }

        $this->checkResponse($response);

        return $response;
    }
1301182
public function request($method, $endpoint, array $params = array(), $isVault = false)
    {
        return $this->doRequest($method, $endpoint, $params, $isVault);
    }
1086742
public function login(Request $request)
    {
        $form = $this->form(new LoginForm());
        $form->handleRequest($request);

        if ($form->isValid()) {
            if ($this->attemptLogin($request, $form)) {
                return $this->sendLoginResponse($request);
            }
        }

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        $this->sendFailedLoginResponse($request);
    }
242497
protected function sendLockoutResponse( Request $request )
	{
		$seconds = $this->secondsRemainingOnLockout( $request );

		return redirect()->back()->withInput( $request->only( $this->loginUsername(), 'remember' ) )->withErrors( [
				$this->loginUsername() => $this->getLockoutErrorMessage( $seconds ),
			] );
	}
763838
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        // get url to redirect (or return in the JSON-response)
        if ($this->session->get('_security.admin.target_path')
            && false !== strpos($this->session->get('_security.admin.target_path'), '#')
        ) {
            $url = $this->session->get('_security.admin.target_path');
        } else {
            $url = $this->router->generate('sulu_admin');
        }

        if ($request->isXmlHttpRequest()) {
            // if AJAX login
            $array = ['url' => $url];
            $response = new JsonResponse($array, 200);
        } else {
            // if form login
            $response = new RedirectResponse($url);
        }

        return $response;
    }