Authenticates a user by a token in a cookie

@param Request $request
@return Session|null
496768
private function authCookie(Request $request) {
		if ($request->cookies->has(self::COOKIE_TOKEN_NAME)) {
			$token = $request->cookies->get(self::COOKIE_TOKEN_NAME);
			return $this->authToken($token);
		}
		return null;
	}
512223
private function authHeader(Request $request) {
		if ($request->headers->has('authorization')) {
			$auth = $request->headers->get('authorization');
			if (!empty($auth)) {
				list(, $token) = explode(' ', $auth);
				if (empty($token)) {
					return null;
				}
				return $this->authToken($token);
			}
		}
		return null;
	}
1344887
public function postLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required',
            'password'             => 'required',
        ]);

        // 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.
        $throttles = $this->isUsingThrottlesLoginsTrait();

        if ($throttles && $this->hasTooManyLoginAttempts($request)) {
            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->getCredentials($request);

        if (\Taki::attempt($credentials, $request->has('remember'))) {
            return $this->handleUserWasAuthenticated($request, $throttles);
        }

        // 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.
        if ($throttles) {
            $this->incrementLoginAttempts($request);
        }

        return redirect($this->loginPath())
                ->withInput($request->only($this->loginUsername(), 'remember'))
                ->withErrors([
                    $this->loginUsername() => $this->getFailedLoginMessage(),
        ]);
    }
966462
public function prepareRequest(Request $request)
	{
		if ( ! is_null($this['config']['session.driver']) && ! $request->hasSession())
		{
			$request->setSession($this['session']->driver());
		}

		return $request;
	}
1142185
protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();

        $this->clearLoginAttempts($request);

        return $this->authenticated($request, $this->guard()->user())
                ?: redirect()->intended($this->redirectPath());
    }
11580
public function loginAction(Request $request)
        {

            if ($this->container->getParameter('database_password') === null) {
                return $this->redirect($this->generateUrl('install_license'));
            } else {
                $request = $this->getRequest();
                $session = $request->getSession();

                // get the login error if there is one
                if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
                    $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
                } else {
                    $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
                }


                return $this->render('SlashworksBackendBundle:Security:login.html.twig', array(
                    'last_username' => $session->get(SecurityContext::LAST_USERNAME),
                    'error'         => $error,
                ));
            }
        }
636309
protected function authenticateViaCookie($request)
    {
        if (! $token = $this->getTokenViaCookie($request)) {
            return;
        }

        // If this user exists, we will return this user and attach a "transient" token to
        // the user model. The transient token assumes it has all scopes since the user
        // is physically logged into the application via the application's interface.
        if ($user = $this->provider->retrieveById($token['sub'])) {
            return $user->withAccessToken(new TransientToken);
        }
    }
1260026
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.
		$throttles = $this->isUsingThrottlesLoginsTrait();

		if ( $throttles && $lockedOut = $this->hasTooManyLoginAttempts( $request ) )
		{
			$this->fireLockoutEvent( $request );

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

		$credentials = $this->getCredentials( $request );
		if ( Acct::guard( $this->getGuard() )->attempt( $credentials, $request->has( 'remember' ) ) )
			return $this->handleUserWasAuthenticated( $request, $throttles );

		// 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.
		if ( $throttles && !$lockedOut )
			$this->incrementLoginAttempts( $request );

		return $this->sendFailedLoginResponse( $request );
	}
1090264
public function loginAction(Request $request)
    {
        /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
        $session = $request->getSession();

        $authErrorKey = Security::AUTHENTICATION_ERROR;
        $lastUsernameKey = Security::LAST_USERNAME;

        // get the error if any (works with forward and redirect -- see below)
        if ($request->attributes->has($authErrorKey)) {
            $error = $request->attributes->get($authErrorKey);
        } elseif (null !== $session && $session->has($authErrorKey)) {
            $error = $session->get($authErrorKey);
            $session->remove($authErrorKey);
        } else {
            $error = null;
        }

        if (!$error instanceof AuthenticationException) {
            $error = null; // The value does not come from the security component.
        }

        // last username entered by the user
        $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);
        $csrfToken = $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue();

        return $this->render('EkynaAdminBundle:Security:login.html.twig', [
            'last_username' => $lastUsername,
            'error'         => $error,
            'token'         => $csrfToken,
        ]);
    }
1097450
public function getCredentials(Request $request)
    {
        $token = !empty($request->headers->get(self::AUTHORIZATION_HEADER)) ?
            $request->headers->get(self::AUTHORIZATION_HEADER) :
            $request->cookies->get(AuthResponseService::AUTH_COOKIE);

        return new CredentialTokenModel(str_replace(self::BEARER, '', $token));
    }
149107
public function authenticate(Request $request, Route $route)
    {
        $this->validateAuthorizationHeader($request);

        if ($user = $this->auth->getUser()) {
            return $user;
        }

        throw new UnauthorizedHttpException(null, 'Please log in before perform this query.');
    }
929670
public function getOAuthCallbackAction(Request $request)
	{
		$this->initSessionBag();

		$apiKeys = $this->getAppParams();
		$oauth = new \OAuth($apiKeys["api-key"], $apiKeys["api-secret"]);
		$oauth->setToken($this->sessionBag->get("oauth_token"), $this->sessionBag->get("oauth_token_secret"));

		$oauthResponse = $oauth->getAccessToken($this->getAccessTokenUrl(), null, $request->query->get("oauth_verifier"));

		$this->storeOAuthData($oauthResponse);
		return $this->returnResult($oauthResponse);
	}
1142361
private function login(Request $request)
    {
        $user = $this->loginProvider->authenticate($request);
        if (null !== $user) {
            try {
                $token = $user->createToken($this->tokenSalt);
                $this->tokenStore->store($request, $token, $user);
                return $user;
            } catch (\Exception $e) {
                throw new InternalAuthProviderException(
                        'Error while trying to store new token for user: ' . $e->getMessage(),
                        $e
                );
            }
        }

        return null;
    }
235199
public function token(Request $request)
    {
        $user = $this->getUser($request);
        
        $client = $user->clients->first();
        if (null !== $client && $client instanceof Client) {

            $serverRequest = $this->createRequest(
                $client,
                $user->id,
                $request, $scope = []
            );
            $reponse = parent::issueToken($serverRequest);
            $responseArray = json_decode($reponse->content(), true);
            unset($responseArray['refresh_token']);
            return response()->json($responseArray)
                ->setStatusCode($reponse->getStatusCode());
        }
        return response(['error' => 'Please create a client first'], 401);
    }
1132904
public function authenticateAction(Request $request) {
        $data = $request->request->all();
        try {
            $data = $this->getAuthCredentials($request);
            $this->info('> Authenticate request', ['method' => $request->getMethod(), 'query' => $data]);
            // exports $client_id, $redirect_uri, $username and $password
            extract($data);

            $accessCredentials = $this->accessProvider->generate($request, $client_id, $redirect_uri, $username, $password);
            $response = new RedirectResponse($redirect_uri . '?code=' . $accessCredentials->getAuthCode());
        }catch (BadDataException $e) {
            $data['errors'] = $e->getErrors();
            $this->error('Bad Data Exception: ' . $e->getMessage(), ['errors' => $data['errors'], 'exception' => $e]);
            $response = $this->getBadFormRequestResponse($data);
        } catch (SoauthException $e) {
            $this->error('Soauth Exception: ' . $e->getMessage(), ['exception' => $e]);
            $response = $this->getBadFormRequestResponse($data);
        }

        $this->info('< Response', ['status_code' => $response->getStatusCode(), 'target' => $response instanceOf RedirectResponse ? $response->getTargetUrl() : null]);
        return $response;
    }
219089
private function authBasic(Request $request) {
		$user = $this->findUser($request->getUser());
		if ($user !== null && $this->verifyUser($user, $request->getPassword())) {
			$session = $this->findSession($user);
			if ($session === null) {
				$session = $this->createSession($user);
			}
			$this->authenticated = true;

			return $session;
		}
		return null;
	}
991924
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 ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

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

        $credentials = $this->credentials($request);

        if ($this->guard()->attempt($credentials, $request->has('remember'))) {
            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.
        if (! $lockedOut) {
            $this->incrementLoginAttempts($request);
        }

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