getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception); $firewallConfig = $this->firewallContext->getFirewallConfig('main'); if ($exception instanceof InvalidTwoFactorCodeException) { addUserMessage(translate('invalidCode', 'two_factor'), 'error'); } return $this->httpUtils->createRedirectResponse($request, $firewallConfig->getAuthFormPath()); } }