Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayman-benmada/sylius-multi-factor-authentication-plugin
Multi factor authentication plugin for ShopUser and AdminUser
https://github.com/ayman-benmada/sylius-multi-factor-authentication-plugin
2fa 2fa-security multifactor-authentication sylius sylius-plugin symfony
Last synced: 25 days ago
JSON representation
Multi factor authentication plugin for ShopUser and AdminUser
- Host: GitHub
- URL: https://github.com/ayman-benmada/sylius-multi-factor-authentication-plugin
- Owner: ayman-benmada
- License: mit
- Created: 2024-05-05T11:08:43.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-12T19:28:30.000Z (8 months ago)
- Last Synced: 2024-11-24T16:24:07.348Z (about 1 month ago)
- Topics: 2fa, 2fa-security, multifactor-authentication, sylius, sylius-plugin, symfony
- Language: PHP
- Homepage:
- Size: 517 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Sylius Multi factor authentication Plugin
Multi factor authentication plugin for ShopUser and AdminUser## Details
### MFA activation on the eshop
![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-1.png?raw=true)### MFA verification after login on the eshop
![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-2.png?raw=true)### MFA activation on the backoffice
![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-3.png?raw=true)### MFA verification after login on the backoffice
![presentation photo](https://github.com/ayman-benmada/Sylius-Multi-Factor-Authentication-Plugin/blob/main/src/Resources/public/image/presentation-4.png?raw=true)## Installation
Require plugin with composer :
```bash
composer require abenmada/sylius-multi-factor-authentication-plugin
```⚠️ Please delete the automatically generated files **config/packages/scheb_2fa.yaml** and **config/routes/scheb_2fa.yaml**.
Change your `config/bundles.php` file to add the line for the plugin :
```php
['all' => true],
Scheb\TwoFactorBundle\SchebTwoFactorBundle::class => ['all' => true],
];
```Then create the config file in `config/packages/abenmada_multi_factor_authentication_plugin.yaml` :
```yaml
imports:
- { resource: "@MultiFactorAuthenticationPlugin/Resources/config/services.yaml" }
```Then import the routes in `config/routes/abenmada_multi_factor_authentication_plugin.yaml` :
```yaml
abenmada_multi_factor_authentication_plugin_shop_routing:
resource: "@MultiFactorAuthenticationPlugin/Resources/config/routes/sylius_shop.yaml"
prefix: /{_locale}abenmada_multi_factor_authentication_plugin_admin_routing:
resource: "@MultiFactorAuthenticationPlugin/Resources/config/routes/sylius_admin.yaml"
prefix: /%sylius_admin.path_name%
```Change your `config/services.yaml` file :
```yaml
parameters:
abenmada_multi_factor_authentication_plugin_issuer: "Fashion Web Store" # Issuer name used in QR code
```Change your `config/packages/security.yaml` file :
```yaml
security:
firewalls:
admin:
two_factor:
auth_form_path: abenmada_multi_factor_authentication_plugin_admin_user_login
check_path: abenmada_multi_factor_authentication_plugin_admin_user_login_checkshop:
two_factor:
auth_form_path: abenmada_multi_factor_authentication_plugin_shop_user_login
check_path: abenmada_multi_factor_authentication_plugin_shop_user_login_checkaccess_control:
# This makes the logout route accessible during two-factor authentication. Allows the user to cancel two-factor authentication, if they need to.
- { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY }# This ensures that the form can only be accessed when two-factor authentication is in progress.
- { path: ^/2fa, role: IS_AUTHENTICATED_2FA_IN_PROGRESS }
```Add a new tab in `templates/bundles/SyliusAdminBundle/Layout/_security.html.twig` file **(if it doesn't exist, customize it)** :
```html
{{ 'abenmada_multi_factor_authentication_plugin.ui.multi_factor_authentication'|trans }}
```Customize the account menu :
```php
getMenu();$menu
->addChild('multiFactorAuthentication', ['route' => 'sylius_shop_account_abenmada_multi_factor_authentication_plugin_shop_user_enable'])
->setLabel('abenmada_multi_factor_authentication_plugin.ui.multi_factor_authentication')
->setLabelAttribute('icon', 'shield');
}
}
``````yaml
services:
app.listener.account_menu:
class: App\Menu\Listener\AccountMenuListener
tags:
- { name: kernel.event_listener, event: sylius.menu.shop.account, method: invoke }
```Update the entity `src/Entity/User/AdminUser.php` :
```php
getEmail() ?: '';
}
}
```Update the entity `src/Entity/User/ShopUser.php` :
```php
getEmail() ?: '';
}
}
```Run the migration :
```bash
bin/console doctrine:migrations:migrate
```Install the assets :
```bash
bin/console assets:install --ansi
```