Версия пакета: 6.1 Версия Symfony: 5.4 Версия PHP: 8
Я хочу добавить двухфакторную аутентификацию в свой проект и наткнулся на ваше решение, которое мне кажется отличным. Поначалу установка казалась простой, но я, должно быть, что-то упускаю, потому что моя аутентификация по-прежнему работает с электронной почтой и паролем, как обычно.
Я следую руководству по установке, и это часть моего файла security.yaml:
main:
lazy: true
provider: app_user_provider
remember_me:
secret: '%kernel.secret%'
token_provider: 'Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider'
lifetime: 68400
form_login:
# "login" is the name of the login route
login_path: login
check_path: login
enable_csrf: true
logout:
path: logout
# where to redirect after logout
target: login
two_factor:
auth_form_path: 2fa_login # The route name you have used in the routes.yaml
check_path: 2fa_login_check # The route name you have used in the routes.yaml
Мой SecurityController выглядит так:
#[Route('/login', name: 'login')]
public function index(AuthenticationUtils $authenticationUtils): Response
{
if ($this->isGranted('ROLE1') || $this->isGranted('ROLE2') ){
return $this->redirectToRoute('home_master_user');
}
elseif ($this->isGranted('ROLE3') && $this->isGranted('ROLE')) {
return $this->redirectToRoute('home');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('login/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error
]);
}
Честно говоря, я не понимаю, почему это не работает, даже после прочтения различных руководств, которые я прочитал.






После долгих поисков проблема оказалась просто в файле security.yaml:
main:
two_factor:
auth_form_path: 2fa_login # The route name you have used in the routes.yaml
check_path: 2fa_login_check # The route name you have used in the routes.yaml
provider: app_user_provider
enable_csrf: true
Я поставил провайдера на двухфакторку и теперь все работает