vivanwebsolution/sylius-2fa-plugin
最新稳定版本:v1.1.0
Composer 安装命令:
composer require vivanwebsolution/sylius-2fa-plugin
包简介
VivanWebSolution Sylius 2FA Plugin
关键字:
README 文档
README
This plugin enables Google Two-Factor Authentication (2FA) for Sylius 2.0 Admin Users using:
It allows admins to secure their accounts with Google Authenticator time-based one-time passwords (TOTP).
Features
- Seamless integration of Google Authenticator for 2FA on Sylius Admin Users
- Admin UI toggle to enable/disable 2FA per user
- AJAX-enabled toggle with CSRF protection
- Extends the Sylius
AdminUserentity to supportTwoFactorInterface - QR code generation for quick mobile setup using
endroid/qr-code
Requirements
- Sylius 2.0
- PHP 8.x
- Composer
Installation
1. Install via Composer
composer require vivanwebsolution/sylius-2fa-plugin
2. Enable the Bundle
In config/bundles.php, register the bundle:
return [ // ... Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true], ];
3. Configure the Bundle
Create the config file at config/packages/scheb_2fa.yaml:
scheb_two_factor:
security_tokens:
- Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
- Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken
google:
enabled: true
server_name: 'Sylius Admin'
To clear the Symfony cache, run:
php bin/console cache:clear
4. Extend the AdminUser Entity
Modify your AdminUser entity to implement the 2FA interface:
<?php declare(strict_types=1); namespace App\Entity\User; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\AdminUser as BaseAdminUser; use VivanWebSolution\Sylius2FAPlugin\Trait\GoogleTwoFactorTrait; use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface; #[ORM\Entity] #[ORM\Table(name: 'sylius_admin_user')] class AdminUser extends BaseAdminUser implements TwoFactorInterface { use GoogleTwoFactorTrait; }
5. Run Database Migrations
Ensure your database is configured, then run:
php bin/console doctrine:schema:update --force
6. Override the Admin User Form Template
Create or override the following template:
templates/bundles/SyliusAdminBundle/admin_user/form/sections.html.twig
Include the 2FA section:
{% include '@VivanWebSolutionSylius2FAPlugin/admin/sections.html.twig' %}
7. Configure Routes
Add the plugin routes to config/routes.yaml:
vivan_sylius_2fa_plugin_admin:
resource: '@VivanWebSolutionSylius2FAPlugin/config/admin_routing.yaml'
prefix: /admin
Usage
-
Log in to the Sylius Admin panel.
-
Navigate to the Admin User detail page.
-
Use the checkbox in the "Two-Factor Authentication" section to enable or disable Google 2FA for that admin user.
-
When 2FA is enabled, the user will be prompted to enter a Google Authenticator code after logging in with their credentials.
References
- Scheb Two Factor Bundle – Provides two-factor authentication support for Symfony.
- Scheb Google Authenticator – Adds Google Authenticator support to the Scheb bundle.
- Endroid QR Code – Used for generating QR codes for Google Authenticator setup.
Functionality Screenshot
© Vivan Web Solution — Open-source Sylius plugin for 2FA with Google Authenticator
统计信息
- 总下载量: 677
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2025-06-05




