{"id":22278862,"url":"https://github.com/ayman-benmada/sylius-multi-factor-authentication-plugin","last_synced_at":"2025-07-28T18:30:54.451Z","repository":{"id":238326339,"uuid":"796238144","full_name":"ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin","owner":"ayman-benmada","description":"Multi factor authentication plugin for ShopUser and AdminUser","archived":false,"fork":false,"pushed_at":"2024-05-12T19:28:30.000Z","size":529,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-24T16:24:07.348Z","etag":null,"topics":["2fa","2fa-security","multifactor-authentication","sylius","sylius-plugin","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayman-benmada.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T11:08:43.000Z","updated_at":"2024-11-04T09:55:53.000Z","dependencies_parsed_at":"2024-05-05T17:25:17.792Z","dependency_job_id":"9a0f92fa-60fa-466f-9279-6b1ffe4cf628","html_url":"https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin","commit_stats":null,"previous_names":["ayman-benmada/sylius-multi-factor-authentication-plugin"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayman-benmada%2FSylius-Multi-Factor-Authentication-Plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayman-benmada%2FSylius-Multi-Factor-Authentication-Plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayman-benmada%2FSylius-Multi-Factor-Authentication-Plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayman-benmada%2FSylius-Multi-Factor-Authentication-Plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayman-benmada","download_url":"https://codeload.github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227941968,"owners_count":17844682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2fa","2fa-security","multifactor-authentication","sylius","sylius-plugin","symfony"],"created_at":"2024-12-03T15:16:53.924Z","updated_at":"2024-12-03T15:16:54.729Z","avatar_url":"https://github.com/ayman-benmada.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eSylius Multi factor authentication Plugin\u003c/h1\u003e\n\n\u003cp\u003e\n    Multi factor authentication plugin for ShopUser and AdminUser\n\u003c/p\u003e\n\n## Details\n\n### MFA activation on the eshop\n![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-1.png?raw=true)\n\n### MFA verification after login on the eshop\n![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-2.png?raw=true)\n\n### MFA activation on the backoffice\n![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-3.png?raw=true)\n\n### MFA verification after login on the backoffice\n![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-4.png?raw=true)\n\n## Installation\n\nRequire plugin with composer :\n\n```bash\ncomposer require abenmada/sylius-multi-factor-authentication-plugin\n```\n\n⚠️  Please delete the automatically generated files **config/packages/scheb_2fa.yaml** and **config/routes/scheb_2fa.yaml**.\n\nChange your `config/bundles.php` file to add the line for the plugin :\n\n```php\n\u003c?php\n\nreturn [\n    //..\n    Abenmada\\MultiFactorAuthenticationPlugin\\MultiFactorAuthenticationPlugin::class =\u003e ['all' =\u003e true],\n    Scheb\\TwoFactorBundle\\SchebTwoFactorBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nThen create the config file in `config/packages/abenmada_multi_factor_authentication_plugin.yaml` :\n\n```yaml\nimports:\n    - { resource: \"@MultiFactorAuthenticationPlugin/Resources/config/services.yaml\" }\n```\n\nThen import the routes in `config/routes/abenmada_multi_factor_authentication_plugin.yaml` :\n\n```yaml\nabenmada_multi_factor_authentication_plugin_shop_routing:\n    resource: \"@MultiFactorAuthenticationPlugin/Resources/config/routes/sylius_shop.yaml\"\n    prefix: /{_locale}\n\nabenmada_multi_factor_authentication_plugin_admin_routing:\n    resource: \"@MultiFactorAuthenticationPlugin/Resources/config/routes/sylius_admin.yaml\"\n    prefix: /%sylius_admin.path_name%\n```\n\nChange your `config/services.yaml` file :\n\n```yaml\nparameters:\n    abenmada_multi_factor_authentication_plugin_issuer: \"Fashion Web Store\" # Issuer name used in QR code\n```\n\nChange your `config/packages/security.yaml` file :\n\n```yaml\nsecurity:\n    firewalls:\n        admin:\n            two_factor:\n                auth_form_path: abenmada_multi_factor_authentication_plugin_admin_user_login\n                check_path: abenmada_multi_factor_authentication_plugin_admin_user_login_check\n\n        shop:\n            two_factor:\n                auth_form_path: abenmada_multi_factor_authentication_plugin_shop_user_login\n                check_path: abenmada_multi_factor_authentication_plugin_shop_user_login_check\n\n    access_control:\n        # This makes the logout route accessible during two-factor authentication. Allows the user to cancel two-factor authentication, if they need to.\n        - { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY }\n\n        # This ensures that the form can only be accessed when two-factor authentication is in progress.\n        - { path: ^/2fa, role: IS_AUTHENTICATED_2FA_IN_PROGRESS }\n```\n\nAdd a new tab in `templates/bundles/SyliusAdminBundle/Layout/_security.html.twig` file **(if it doesn't exist, customize it)** :\n\n```html\n\u003ca href=\"{{ path('abenmada_multi_factor_authentication_plugin_admin_user_enable', {'id': app.user.id}) }}\" class=\"item\"\u003e\n    \u003ci class=\"shield icon\"\u003e\u003c/i\u003e\n    {{ 'abenmada_multi_factor_authentication_plugin.ui.multi_factor_authentication'|trans }}\n\u003c/a\u003e\n```\n\nCustomize the account menu : \n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Menu\\Listener;\n\nuse Sylius\\Bundle\\UiBundle\\Menu\\Event\\MenuBuilderEvent;\n\nfinal class AccountMenuListener\n{\n    public function invoke(MenuBuilderEvent $event): void\n    {\n        $menu = $event-\u003egetMenu();\n\n        $menu\n            -\u003eaddChild('multiFactorAuthentication', ['route' =\u003e 'sylius_shop_account_abenmada_multi_factor_authentication_plugin_shop_user_enable'])\n            -\u003esetLabel('abenmada_multi_factor_authentication_plugin.ui.multi_factor_authentication')\n            -\u003esetLabelAttribute('icon', 'shield');\n    }\n}\n```\n\n```yaml\nservices:\n    app.listener.account_menu:\n        class: App\\Menu\\Listener\\AccountMenuListener\n        tags:\n            - { name: kernel.event_listener, event: sylius.menu.shop.account, method: invoke }\n```\n\nUpdate the entity `src/Entity/User/AdminUser.php` :\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Entity\\User;\n\nuse Abenmada\\MultiFactorAuthenticationPlugin\\Model\\MultiFactorAuthenticationTrait;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Scheb\\TwoFactorBundle\\Model\\Google\\TwoFactorInterface;\nuse Sylius\\Component\\Core\\Model\\AdminUser as BaseAdminUser;\n\n/**\n * @ORM\\Entity\n * @ORM\\Table(name=\"sylius_admin_user\")\n */\n#[ORM\\Entity]\n#[ORM\\Table(name: 'sylius_admin_user')]\nclass AdminUser extends BaseAdminUser implements TwoFactorInterface\n{\n    use MultiFactorAuthenticationTrait;\n\n    public function getGoogleAuthenticatorUsername(): string\n    {\n        return $this-\u003egetEmail() ?: '';\n    }\n}\n```\n\nUpdate the entity `src/Entity/User/ShopUser.php` :\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Entity\\User;\n\nuse Abenmada\\MultiFactorAuthenticationPlugin\\Model\\MultiFactorAuthenticationTrait;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Scheb\\TwoFactorBundle\\Model\\Google\\TwoFactorInterface;\nuse Sylius\\Component\\Core\\Model\\ShopUser as BaseShopUser;\n\n/**\n * @ORM\\Entity\n * @ORM\\Table(name=\"sylius_shop_user\")\n */\n#[ORM\\Entity]\n#[ORM\\Table(name: 'sylius_shop_user')]\nclass ShopUser extends BaseShopUser implements TwoFactorInterface\n{\n    use MultiFactorAuthenticationTrait;\n\n    public function getGoogleAuthenticatorUsername(): string\n    {\n        return $this-\u003egetEmail() ?: '';\n    }\n}\n```\n\nRun the migration :\n\n ```bash\nbin/console doctrine:migrations:migrate\n```\n\nInstall the assets :\n\n```bash\nbin/console assets:install --ansi\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayman-benmada%2Fsylius-multi-factor-authentication-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayman-benmada%2Fsylius-multi-factor-authentication-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayman-benmada%2Fsylius-multi-factor-authentication-plugin/lists"}