Версия Symfony: 5.4
Версия PHP: 8
Здравствуйте!
Я хочу добавить двухфакторную аутентификацию в свой проект и наткнулся на ваше решение, которое мне кажется отличным. Поначалу установка казалась простой, но я, должно быть, что-то упускаю, потому что моя аутентификация по-прежнему работает с использованием электронной почты и пароля, как обычно.
Я следую руководству по установке, и это часть моей безопасности. ямл:
Код: Выделить всё
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
Код: Выделить всё
#[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
]);
}
С уважением
Подробнее здесь: https://stackoverflow.com/questions/782 ... my-project