bitexpert/sylius-2fa-plugin

Sylius 2FA Plugin

Installs: 48

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

Type:sylius-plugin

pkg:composer/bitexpert/sylius-2fa-plugin

This package is auto-updated.

Last update: 2026-02-01 08:44:27 UTC


README

Build Status installs on Packagist Mastodon Follow

Requirements:

  • PHP 8.2 or higher
  • Sylius 2.0 or higher

Installation

  1. Install the plugin via Composer
composer require bitexpert/sylius-2fa-plugin
  1. Enable the plugin
<?php
# config/bundles.php
return [
    // ...

    Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true],
    Endroid\QrCodeBundle\EndroidQrCodeBundle::class => ['all' => true],
    BitExpert\SyliusTwoFactorAuthPlugin\BitExpertSyliusTwoFactorAuthPlugin::class => ['all' => true],
];
  1. Import config
# config/packages/_sylius.yaml
imports:
    # ...

    - { resource: "@BitExpertSyliusTwoFactorAuthPlugin/config/config.yaml" }
    
    # ...
  1. Import routing
# config/routes/bitexpert_sylius_2fa.yaml
bitexpert_sylius_2fa_admin:
  resource: "@BitExpertSyliusTwoFactorAuthPlugin/config/routes/admin.yaml"
  prefix: /%sylius_admin.path_name%

bitexpert_sylius_2fa_shop:
  resource: "@BitExpertSyliusTwoFactorAuthPlugin/config/routes/shop.yaml"
  prefix: /{_locale}
  1. Update firewall configuration

Add the two_factor configuration to your admin firewall configuration.

# config/packages/security.yaml
security:
  firewalls:
    admin:
      two_factor:
        auth_form_path: bitexpert_sylius_2fa_admin_login
        check_path: bitexpert_sylius_2fa_admin_login_check
        multi_factor: false

Add the two_factor configuration to your shop firewall configuration.

# config/packages/security.yaml
security:
  firewalls:
    shop:
      two_factor:
        auth_form_path: bitexpert_sylius_2fa_shop_login
        check_path: bitexpert_sylius_2fa_shop_login_check
        multi_factor: false
  1. Configure AdminUser entity in file src/Entity/User/AdminUser.php

Add the BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthInterface interface and the BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthTrait trait to the entity.

<?php

declare(strict_types=1);

namespace App\Entity\User;

use BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthInterface;
use BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\AdminUser as BaseAdminUser;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_admin_user')]
class AdminUser extends BaseAdminUser implements TwoFactorAuthInterface
{
    use TwoFactorAuthTrait;
}
  1. Configure ShopUser entity in file src/Entity/User/ShopUser.php

Add the BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthInterface interface and the BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthTrait trait to the entity.

<?php

declare(strict_types=1);

namespace App\Entity\User;

use BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthInterface;
use BitExpert\SyliusTwoFactorAuthPlugin\Entity\TwoFactorAuthTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\ShopUser as BaseShopUser;

#[ORM\Entity]
#[ORM\Table(name: 'sylius_shop_user')]
class ShopUser extends BaseShopUser implements TwoFactorAuthInterface
{
    use TwoFactorAuthTrait;
}
  1. Update your database schema
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate

Tests

You can run the unit tests with the following command (requires dependency installation):

./vendor/bin/phpunit

Contribution

Feel free to contribute to this module by reporting issues or create some pull requests for improvements.

To run the Test Application included in the repo, refer to the Sylius Test Application docs. If you are using DDEV you can run the following command to bootstrap the Test Application in Docker:

ddev start

License

The Sylius 2FA Plugin for Sylius is released under the MIT license.