@param Request $request
@param $token

@return \Symfony\Component\HttpFoundation\JsonResponse
430377
public function listByProfileAction(Request $request, $token)
    {
        list($transUnits, $count) = $this->get('lexik_translation.data_grid.request_handler')->getPageByToken($request, $token);

        return $this->get('lexik_translation.data_grid.formatter')->createListResponse($transUnits, $count);
    }
529688
public function panelAction(Request $request, $token)
    {
        $this->denyAccessIfProfilerDisabled();

        if (null !== $this->cspHandler) {
            $this->cspHandler->disableCsp();
        }

        $panel = $request->query->get('panel', 'request');
        $page = $request->query->get('page', 'home');

        if ('latest' === $token && $latest = current($this->profiler->find(null, null, 1, null, null, null))) {
            $token = $latest['token'];
        }

        if (!$profile = $this->profiler->loadProfile($token)) {
            return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', ['about' => 'no_token', 'token' => $token, 'request' => $request]), 200, ['Content-Type' => 'text/html']);
        }

        if (!$profile->hasCollector($panel)) {
            throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
        }

        return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), [
            'token' => $token,
            'profile' => $profile,
            'collector' => $profile->getCollector($panel),
            'panel' => $panel,
            'page' => $page,
            'request' => $request,
            'templates' => $this->getTemplateManager()->getNames($profile),
            'is_ajax' => $request->isXmlHttpRequest(),
            'profiler_markup_version' => 2, // 1 = original profiler, 2 = Symfony 2.8+ profiler
        ]), 200, ['Content-Type' => 'text/html']);
    }
573742
public function postAction(Request $request)
    {
        try {
            return $this->createJsonResponse($this->get('oauth.server')->grant(
                $this->getRequestData($request, 'snakelize')
            ));
        } catch (InvalidGrantException $e) {
            return new JsonResponse('Unavailable to create access token : bad credentials.', 401);
        } catch (\InvalidArgumentException $e) {
            return new JsonResponse('Invalid or missing fields for grant type.', 400);
        }
    }
175807
protected function getCreateChargeResponse($url, $token)
    {
        $postKey = $this->httpClientVersionCheck();

        $response = $this->getHttpClient()->post($url,
        [
            'headers'=> $this->getResponseHeaders($token),
            $postKey => $this->getOptions()
        ]);

        return json_decode($response->getBody(), true);
    }
219322
public function webViewAction(Request $request, $token)
    {
        // find email recipients, template & params
        $sentEmail = $this->getSentEmailForToken($token);

        // check if the sent email is available
        if (null !== $sentEmail) {
            // check if the current user is allowed to see the email
            if ($this->userIsAllowedToSeeThisMail($sentEmail)) {
                $template = $sentEmail->getTemplate();
                $emailVars = $sentEmail->getVariables();

                // re-attach all entities to the EntityManager.
                $this->reAttachAllEntities($emailVars);

                // remove the web-view-token from the param-array
                $templateProvider = $this->getTemplateProviderService();
                unset($emailVars[$templateProvider->getWebViewTokenId()]);

                // render & return email
                $response = $this->renderResponse("$template.html.twig", $emailVars);

                $campaignParams = $templateProvider->getCampaignParamsFor($template, $emailVars);

                if (null != $campaignParams && sizeof($campaignParams) > 0) {
                    $response->setContent($this->get('azine.email.bundle.twig.filters')->addCampaignParamsToAllUrls($response->getContent(), $campaignParams));
                }

                return $response;

                // if the user is not allowed to see this mail
            }
            $msg = $this->get('translator')->trans('web.pre.view.test.mail.access.denied');
            throw new AccessDeniedException($msg);
        }

        // the parameters-array is null => the email is not available in webView
        $days = $this->getParameter('azine_email_web_view_retention');
        $response = $this->renderResponse('AzineEmailBundle:Webview:mail.not.available.html.twig', array('days' => $days));
        $response->setStatusCode(404);

        return $response;
    }
802450
protected function getRequestToken(Request $request)
    {
        /** @var TokenExtractorInterface $tokenExtractor */
        foreach ($this->tokenExtractors as $tokenExtractor) {
            if (($token = $tokenExtractor->extract($request))) {
                return $token;
            }
        }
    }
570409
public function jsonSaveAction(Request $request)
    {
        //@FIXME: This code need to be moved to ContentController somehow.
        $this->save($request);

        $response = new Response(json_encode(['status' => 'ok']));
        $response->headers->set("Content-Type", 'application/json');

        return $response;
    }
1088768
public function resetAction(Request $request, PasswordResetToken $token): Response
    {
        $user = $this->userRepositoryCollection->findUserByToken($token);

        if ($user === null) {
            return new RedirectResponse(
                $this->router->generate('multi_user_login')
            );
        }

        $changePasswordTransferObject = ChangePasswordDataTransferObject::forUser($user);
        $form = $this->formFactory->create(ChangePasswordType::class, $changePasswordTransferObject);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->resetPasswordHandler->handle($form->getData());

            $this->flashBag->add(
                'success',
                $this->translator->trans(
                    'sumocoders.multiuserbundle.flash.password_reset_success'
                )
            );

            return new RedirectResponse(
                $this->router->generate('multi_user_login')
            );
        }

        return $this->templating->renderResponse(
            'SumoCodersFrameworkMultiUserBundle:PasswordReset:reset.html.twig',
            [
                'form' => $form->createView(),
            ]
        );
    }
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'));
    }
47554
protected function _addTokenToRequest($token, ServerRequest $request)
    {
        $params = $request->getAttribute('params');
        $params['_csrfToken'] = $token;

        return $request->withAttribute('params', $params);
    }
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);
        }
    }
1194777
private function createToken(Request $request)
    {
        $tokenString = $request->headers->get($this->header);

        if ($this->header == self::HEADER_AUTH && 0 === strpos((string)$tokenString, 'Bearer ')) {
            $tokenString = substr($tokenString, 7);
        }

        if (!$tokenString) {
            return null;
        }

        return new JwtAuthenticationToken([], $tokenString);
    }
1095575
public function indexAction(Request $request)
    {

        // For Mailchimp ping GET
        if ($request->isMethod('GET')) {
            return new JsonResponse([
                'success' => true,
                'ping' => 'pong',
            ]);
        }

        // Handle POST request of Mailchimp
        $type = $request->request->get('type');
        $data = $request->request->get('data');
        /* Response example:
            data[merges][FNAME]: Tztz
            data[merges][EMAIL]: tztz@gmail.com
            data[email_type]: html
            data[reason]: manual
            data[email]: tztz@gmail.com
            data[id]: 5c1b5a7c1e
            data[merges][LNAME]: TZST
            data[list_id]: ba039c6198
            data[web_id]: 3375995
        */
        $hooksecret = $request->query->get('hooksecret');

        if (empty($type) || empty($data) || empty($hooksecret) || !array_key_exists('list_id', $data)) {
            throw new AccessDeniedHttpException('incorrect data format!');
        }

        $listId = $data['list_id'];

        $listProviderKey = $this->getParameter('welp_mailchimp.list_provider');
        try {
            $listProvider = $this->get($listProviderKey); 
        } catch (ServiceNotFoundException $e) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should be defined as a service.', $listProviderKey), $e->getCode(), $e);
        }

        if (!$listProvider instanceof ListProviderInterface) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should implement Welp\MailchimpBundle\Provider\ListProviderInterface.', $listProviderKey));
        }

        $list = $listProvider->getList($listId);

        // Check the webhook_secret
        $authorized = false;
        if($list != null && $list->getWebhookSecret() == $hooksecret) {
            $authorized = true;                           
        }

        if (!$authorized) {
            throw new AccessDeniedHttpException('Webhook secret mismatch!');
        }

        // Trigger the right event
        switch ($type) {
            case 'subscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_SUBSCRIBE, new WebhookEvent($data));
                break;
            case 'unsubscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UNSUBSCRIBE, new WebhookEvent($data));
                break;
            case 'profile':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_PROFILE, new WebhookEvent($data));
                break;
            case 'cleaned':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CLEANED, new WebhookEvent($data));
                break;
            case 'upemail':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UPEMAIL, new WebhookEvent($data));
                break;
            case 'campaign':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CAMPAIGN, new WebhookEvent($data));
                break;
            default:
                throw new AccessDeniedHttpException('type mismatch!');
                break;
        }

        return new JsonResponse([
            'type' => $type,
            'data' => $data,
        ]);
    }
11158
protected function send(Request $request)
    {
        try {
            $response = $this->client->send($request);
        } catch (ClientException $e) {
            $response = $e->getResponse();
        } catch (ServerException $e) {
            $response = $e->getResponse();
        }

        return $response;
    }
1038048
public function jwtPayload($path = null, $request = null)
    {
        $jwt = $this->jwtToken($request);

        return $jwt->payload($path);
    }
334693
private function validateAPIToken($token, $request)
    {
        //get owner with that token
        $SQL_token = Convert::raw2sql($token);
        $tokenColumn = $this->tokenConfig['DBColumn'];

        $tokenOwner = DataObject::get_one(
            $this->tokenConfig['owner'],
            "\"" . $this->tokenConfig['DBColumn'] . "\"='" . $SQL_token . "'",
            false
        );

        if ($tokenOwner) {
            //check token expiry
            $tokenExpire = $tokenOwner->{$this->tokenConfig['expireDBColumn']};
            $now = time();
            $life = $this->tokenConfig['life'];

            if ($tokenExpire > ($now - $life)) {
                // check if token should automatically be updated
                if ($this->tokenConfig['autoRefresh']) {
                    $tokenOwner->setField($this->tokenConfig['expireDBColumn'], $now + $life);
                    $tokenOwner->write();
                }
                //all good, log Member in
                if (is_a($tokenOwner, Member::class)) {
                    # this is a login without the logging
                    Config::nest();
                    Config::modify()->set(Member::class, 'session_regenerate_id', true);
                    $identityStore = Injector::inst()->get(IdentityStore::class);
                    $identityStore->logIn($tokenOwner, false, $request);
                    Config::unnest();
                }

                return true;
            } else {
                //too old
                return new RESTfulAPIError(403,
                    'Token expired.',
                    array(
                        'message' => 'Token expired.',
                        'code' => self::AUTH_CODE_TOKEN_EXPIRED,
                    )
                );
            }
        } else {
            //token not found
            //not sure it's wise to say it doesn't exist. Let's be shady here
            return new RESTfulAPIError(403,
                'Token invalid.',
                array(
                    'message' => 'Token invalid.',
                    'code' => self::AUTH_CODE_TOKEN_INVALID,
                )
            );
        }
    }
842243
public function activate(Request $request): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            $user = $this->activationService->activateUser(
                $request->input('token')
            );

            $token = $user->createToken('Personal Access Token');

            $this->connection->commit();
        } catch (\Throwable $exception) {
            $this->connection->rollback();

            report($exception);

            return $this->response->error($exception->getMessage());
        }

        return $this->response->success('OK', (new HCAuthorizeDTO($user, $token))->toArray());
    }