How to use this in your own project:
- scheb/2fa-backup-code
- scheb/2fa-bundle
- scheb/2fa-totp
- scheb/2fa-trusted-device
- endroid/qr-code
You can install them via composer:
symfony composer require 2fa scheb/2fa-backup-code scheb/2fa-totp scheb/2fa-trusted-device endroid/qr-code
This will normally enable the bundle automatically. If not, please enable it in config/bundles.php:
Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true],- Copy the
config/packages/scheb_2fa.yamlinto your own project. - Copy the
config/routes/scheb_2fa.yamlinto your own project.
Add the following to your firewall in config/packages/security.yaml:
two_factor:
auth_form_path: 2fa_login
check_path: 2fa_login_check
trusted_parameter_name: _trustedAdd the routes to the access control:
- { route: '2fa_login', roles: IS_AUTHENTICATED_2FA_IN_PROGRESS }
- { route: '2fa_login_check', roles: IS_AUTHENTICATED_2FA_IN_PROGRESS }
- { route: 'user_2fa', roles: ROLE_USER }
- { route: 'user_2fa_qrcode', roles: ROLE_USER }
- { route: 'user_password', roles: ROLE_USER }
- { route: 'user_profile', roles: ROLE_USER }See SchebTwoFactorBundle → Installation → Step 4: Configure the firewall for more information.
- Copy
src/*/User/*into your own project. - Copy
src/Securityinto your own project. - Copy
templates/userinto your own project. - Copy
tests/*/User/*into your own project.
Copy the EventListener folder from src/ into your own project. Or adjust your own user menu accordingly.
- Copy the migrations from
src/Migrations/into your own project. - Run the migrations:
symfony console doctrine:migrations:migrate
If your project does not need a profile page, you can remove:
src/Controller/User/ProfileController.phptemplates/user/profile.html.twig
And remove the entry in templates/user/_profile_navigation.html.twig.
If your project does not need registration, you can remove:
src/Controller/User/RegisterController.phpsrc/Message/User/RegisterUser.phpsrc/MessageHandler/User/RegisterUserHandler.phptemplates/user/register.html.twig