This will be fired when the user clicks cancel on slack or third party site.  This page will redirect the user
back to the login path.

@param Request $request
@param AuthenticationException|null $authException
@return Response
967904
public function start(Request $request, AuthenticationException $authException = null)
    {
        return new Response(
            $this->twig->render('@StarterKitStart/oauth-start.html.twig', ['login_path' => $this->loginPath])
        );
    }
376877
public function start(Request $request, AuthenticationException $authException = null)
    {
        $exception = new MissingTokenException('JWT Token not found', 0, $authException);
        $event     = new JWTNotFoundEvent($exception, new JWTAuthenticationFailureResponse($exception->getMessageKey()));

        if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
            $this->dispatcher->dispatch($event, Events::JWT_NOT_FOUND);
        } else {
            $this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $event);
        }

        return $event->getResponse();
    }
304161
public function postLogin(LoginRequest $request)
    {
        $inputs = $request->except('_token','rememberme');

        $rememberme = $request->get('rememberme');

        $attemp = Auth::attempt($inputs, !!$rememberme);

        if (!$attemp) {
            $request->session()->flash('error', trans('auth.failed'));
            return Redirect::back();
        }

        return Redirect::intended('/');

    }
85067
protected function logout(Request $request)
    {
        impersonate()->logout();

        // if redirect url in request
        if ($request->has('redirect_to')) {
            return redirect($request->get('redirect_to'));
        }

        return back();
    }
80836
public function loginAction(Request $request)
    {

        if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            return $this->redirectToRoute('campaignchain_core_homepage');
        }

        return parent::loginAction($request);
    }
317298
public function activate(Request $request)
    {
        if (!$email = $request->get('email')) {
            $email = null;
        }

        if (!$code = $request->get('code')) {
            $code = null;
        }

        if (!config('laraflock.dashboard.activations')) {
            Flash::error(trans('dashboard::dashboard.flash.activation.not_active'));

            return redirect()->route('auth.login');
        }

        return $this->view('auth.activate')->with(['email' => $email, 'code' => $code]);
    }
1097732
public function authenticate(Request $request)
    {
        $this->checkForToken($request);

        try {
            if (! $this->auth->parseToken()->authenticate()) {
                throw new UnauthorizedHttpException('jwTauth', 'User not found');
            }
        } catch (JwTException $e) {
            throw new UnauthorizedHttpException('jwTauth', $e->getMessage(), $e, $e->getCode());
        }
    }
1338414
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
    {
        // if the user hit a secure page and start() was called, this was
        // the URL they were on, and probably where you want to redirect to
        $targetPath = $request->getSession()->get('_security.'.$providerKey.'.target_path');

        if (!$targetPath) {
            $targetPath = $this->getDefaultSuccessRedirectUrl();
        }

        return new RedirectResponse($targetPath);
    }
886758
public function onAuthenticationFailure( Request $request, AuthenticationException $exception )
	{
		// if AJAX login
		if ( ! $request->isXmlHttpRequest() ) {
			throw new NotFoundHttpException('Must use AJAX Login');
		}

		return new JsonResponse(array(
				"success" => false
		));
	}
461208
public function callback(Request $request)
    {
        // Check to see if this provider exists and has a callback implemented
        $provider = strtolower($request->attributes->get('provider'));

        if (! $this->providerExists($provider)) {
            return $this->createNotFoundResponse();
        }

        if (! method_exists($this, $provider)) {
            throw new LogicException(sprintf(
                'Callback for provider \'%s\' not implemented',
                $provider
            ));
        }

        // Use provider service and access token from provider to create a LoginRequest for our app
        $code            = $request->query->get('code');
        $providerService = $this->getServiceByProvider($provider);
        $providerToken   = $providerService->requestAccessToken($code);

        $socialLoginRequest = $this->$provider($providerService, $providerToken);

        // Handle login or link-account request and redirect to the redirect-url
        $state = (int) $request->query->get('state');
        try {
            if ($state === self::ACTION_LOGIN_WITH_ACCOUNT) {
                $token = $this->service->handleLoginRequest($socialLoginRequest);
            } elseif ($state === self::ACTION_LINK_ACCOUNT) {
                $token = $this->service->handleLinkRequest(
                    $socialLoginRequest,
                    $this->session->get('user')
                );
            } else {
                return new Response(
                    'State parameter not set',
                    422
                );
            }

            $redirect = $this->config['redirect-url'];
            $redirect .= '?'.http_build_query($token);
        } catch (NoLinkedAccountException $e) {
            $redirect = $this->config['redirect-url'];
            $redirect .= '?login_failure=1&error=no_linked_account';
        } catch (LinkedAccountExistsException $e) {
            $redirect = $this->config['redirect-url'];
            $redirect .= '?login_failure=1&error=account_already_linked';
        } catch (OutOfBoundsException $e) {
            $redirect = $this->config['redirect-url'];
            $redirect .= '?login_failure=1';

            if ($e->getCode() === SocialLoginService::EXCEPTION_ACCOUNT_NOT_FOUND) {
                $redirect .= '&error=account_not_found';
            }
        }

        $response = new Response();
        $response->setStatusCode(301);
        $response->headers->set('Location', $redirect);

        return $response;
    }
408440
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        if ($request->isXmlHttpRequest()) {
            /** @var User $user */
            $user = $token->getUser();
            $roles = $token->getRoles();
            $outputRoles = array();

            foreach ($roles as $role) {
                $outputRoles[] = $this->translator->trans('roles.' . $role->getRole(), array(), 'CodeLoversAngularBundle');
            }

            $output = $this->generator->getUserData($request, $token);

            // notify listeners to allow output modification
            $event = new LoginEvent($user);
            $event->setOutput($output);

            $this->dispatcher->dispatch(AuthEvents::LOGIN_SUCCESS, $event);

            return new JsonResponse($event->getOutput());
        } else {
            if ($targetPath = $request->getSession()->get('_security.target_path')) {
                $url = $targetPath;
            } else {
                $url = $this->getDefaultUrl();
            }

            return new RedirectResponse($url);
        }
    }
1309533
protected function authenticate($request, array $guards)
    {
        if (empty($guards)) {
            $guards = [null];
        }

        foreach ($guards as $guard) {
            if ($this->auth->guard($guard)->check()) {
                return $this->auth->shouldUse($guard);
            }
        }

        throw new AuthenticationException(
            'Unauthenticated.', $guards, $this->redirectTo($request)
        );
    }
330778
protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        abort(401);

        return redirect()->guest(route(\Platform::port()->slug().'::login'));
    }
118487
public function start(Request $request, AuthenticationException $exception = null)
    {
        if ($exception) {
            $message = $exception->getMessage();
            if (empty($message) && is_callable([$exception, 'getMessageKey'])) {
                $message = $e->getMessageKey();
            }
        } else {
            $message = 'Full authentication is required to access this resource.';
        }

        $content = [
            'errors' => [
                'code' => 401,
                'message' => $this->translator->trans($message, [], 'errors')
            ]
        ];

        return new JsonResponse($content, JsonResponse::HTTP_UNAUTHORIZED);
    }
307724
public function login(LoginRequest $request, JWTAuth $JWTAuth)
    {
        $credentials = $request->only(['email', 'password']);

        try {
            $token = \JWTAuth::attempt($credentials);

            event(new Login(\JWTAuth::user(), false));

            if (!$token) {
                throw new AccessDeniedHttpException(__('auth.failed'));
            }

        } catch (JWTException $e) {
            throw new HttpException(500);
        }

        return response()
            ->json([
                'status'     => 'ok',
                'token'      => $token,
                'expires_in' => Auth::guard()->factory()->getTTL() * 60
            ]);
    }
1362238
protected function attemptAuthentication(Request $request)
    {
        $myRequest = $this->duplicateRequest($request);

        if (!$this->getRelyingParty()->supports($myRequest)) {
            return null;
        }

        try {
            $tokenOrResponse = $this->getRelyingParty()->manage($myRequest);
        } catch (AuthenticationException $ex) {
            throw $ex;
        } catch (\Exception $ex) {
            $msg = "Appsco OAuth failed";
            if ($ex instanceof AppscoOAuthException) {
                $msg .= ': '.$ex->getMessage();
            }
            throw new AuthenticationException($msg, 0, $ex);
        }

        if ($tokenOrResponse instanceof Response) {

            return $tokenOrResponse;
        }

        if ($tokenOrResponse instanceof AppscoToken) {
            try {

                $result = $this->authenticationManager->authenticate($tokenOrResponse);

                $this->setLocale($tokenOrResponse, $request);

                return $result;

            } catch (AuthenticationException $e) {
                $e->setToken($tokenOrResponse);
                throw $e;
            }
        }

        return null;
    }
341817
public function tokenAction(Request $request)
    {
        /** @var PropertyAccess $config */
        $config = $this->app['conf'];

        if ( ! $request->isSecure() && $config->get(['main', 'api_require_ssl'], true) == true) {
            throw new HttpException(400, 'This route requires the use of the https scheme: ' . $config->get(['main', 'api_require_ssl']), null, ['content-type' => 'application/json']);
        }

        $this->oAuth2Adapter->grantAccessToken();
        ob_flush();
        flush();

        // As OAuth2 library already outputs response content, we need to send an empty
        // response to avoid breaking silex controller
        return '';
    }