jul6art / auth-bundle
Symfony auth bundle
Requires
- php: ^8.5
- doctrine/doctrine-bundle: ^2.13 || ^3.0
- doctrine/orm: ^3.3
- doctrine/persistence: ^3.4.5 || ^4.0
- jul6art/core-bundle: ^2.3 || ^3.0
- symfony/config: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/http-kernel: ^7.4 || ^8.0
- symfony/security-core: ^7.4 || ^8.0
- symfony/service-contracts: ^3.5
- symfony/yaml: ^7.4 || ^8.0
Requires (Dev)
- api-platform/core: ^5.0
- endroid/qr-code: ^6.2
- friendsofphp/php-cs-fixer: ^3.95.27
- gesdinet/jwt-refresh-token-bundle: ^2.3
- lexik/jwt-authentication-bundle: ^3.2
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.4
- phpstan/phpstan-doctrine: ^2.0.28
- phpstan/phpstan-phpunit: ^2.1.1
- phpstan/phpstan-symfony: ^2.1.1
- phpunit/phpunit: ^13.4.5
- rector/rector: ^2.8.3
- scheb/2fa-backup-code: ^8.7
- scheb/2fa-bundle: ^8.7
- scheb/2fa-totp: ^8.7
- symfony/browser-kit: ^7.4 || ^8.0
- symfony/event-dispatcher-contracts: ^2.5.4 || ^3.0
- symfony/expression-language: ^7.4 || ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
- symfony/mailer: ^7.4 || ^8.0
- symfony/phpunit-bridge: ^7.4 || ^8.0
- symfony/rate-limiter: ^7.4 || ^8.0
- symfony/security-bundle: ^7.4 || ^8.0
- symfony/serializer: ^7.4 || ^8.0
- symfony/twig-bundle: ^7.4 || ^8.0
- symfony/validator: ^7.4 || ^8.0
- symfony/var-dumper: ^7.4 || ^8.0
- symfonycasts/reset-password-bundle: ^1.26
Suggests
- api-platform/core: The API sign-in (auth.api): its routes are API Platform resources
- endroid/qr-code: The API sign-in (auth.api): the QR code of the second factor
- gesdinet/jwt-refresh-token-bundle: The API sign-in (auth.api): the refresh token, one table per realm
- lexik/jwt-authentication-bundle: The API sign-in (auth.api): the access token and its cookie
- scheb/2fa-backup-code: The API sign-in (auth.api): the backup codes
- scheb/2fa-bundle: The API sign-in (auth.api): the second factor
- scheb/2fa-totp: The API sign-in (auth.api): the authenticator app
- symfony/clock: The API sign-in (auth.api): the clock of the TOTP
- symfony/expression-language: The API sign-in (auth.api): the access decisions of its routes
- symfony/mailer: The API sign-in (auth.api): the forgotten-password e-mail
- symfony/security-bundle: The API sign-in (auth.api): the firewalls
- symfony/twig-bundle: The API sign-in (auth.api): the e-mail templates
- symfonycasts/reset-password-bundle: The API sign-in (auth.api): the forgotten password, one table per realm
Provides
None
Conflicts
None
Replaces
None
README
Symfony auth bundle
Requirements
- php ^8.5
- symfony ^7.4 || ^8.0
- jul6art/core-bundle ^2.0
Installation
composer require jul6art/auth-bundle
Map the bundle entities in your Doctrine configuration:
# config/packages/doctrine.yaml doctrine: orm: mappings: AuthBundle: type: attribute dir: '%kernel.project_dir%/vendor/jul6art/auth-bundle/Entity' prefix: 'Jul6Art\AuthBundle\Entity' is_bundle: false
Usage
The bundle registers its repository and its manager, and aliases both interfaces onto them, so they can be injected directly:
use Jul6Art\AuthBundle\Manager\Interfaces\UserManagerInterface; use Jul6Art\AuthBundle\Repository\Interfaces\UserRepositoryInterface; public function __construct( private UserManagerInterface $userManager, private UserRepositoryInterface $userRepository, ) { }
UserRepository implements PasswordUpgraderInterface, so it can be wired as the
password upgrader of your firewall.
Configuration
# config/packages/auth.yaml auth: enabled: true
The option is exposed as the auth.enabled container parameter.
API sign-in (optional)
An API Platform application can sign its accounts in through the bundle: a JSON sign-in, the second factor
(TOTP and ten backup codes, an enrolment at the first sign-in), the access token and the refresh token in
HttpOnly cookies, "stay signed in", the forgotten password, the change of password, and the second factor
switched on and off from the account's page. It is off by default, and its packages are suggested, not
required — the bundle's other users get nothing new:
composer require api-platform/core lexik/jwt-authentication-bundle gesdinet/jwt-refresh-token-bundle \
scheb/2fa-bundle scheb/2fa-totp scheb/2fa-backup-code endroid/qr-code symfonycasts/reset-password-bundle \
symfony/security-bundle symfony/mailer symfony/twig-bundle symfony/expression-language symfony/clock
One kernel may serve several applications, each on its own host and with its own base: each declares a realm — its firewalls, its classes, the name its second factor and its e-mails carry. A refresh token, a reset link of one realm never opens another.
# config/packages/auth.yaml auth: api: # Ignored in "prod", where every account always owes its second factor. two_factor_required: '%env(bool:TWO_FACTOR_REQUIRED)%' realms: shop: firewalls: [shop_login, shop_public, shop_api] user_class: App\Entity\User # implements Api\Account\ApiAccountInterface login_record_class: App\Entity\LoginRecord # implements Api\Account\LoginRecordInterface refresh_token_class: App\Entity\RefreshToken # extends gesdinet's RefreshToken reset_password_request_class: App\Entity\ResetPasswordRequest issuer: Shop mail: from: '%env(MAILER_FROM)%' reset_links: en: 'https://shop.example.org/password/{token}' fr: 'https://shop.example.org/mot-de-passe/{token}'
Api\Account\TwoFactorAccountTraitcarries the second factor's columns (the secret encrypted at rest with core-bundle'sencrypted_string).- The firewalls use the bundle's handlers:
LoginSuccessHandler,LoginFailureHandler,TwoFactorSuccessHandler,TwoFactorFailureHandler,TwoFactorRequiredHandler,RefreshFailureHandler,UserChecker,ApiEntryPoint(namespaceJul6Art\AuthBundle\Api\Security). The bundle sets scheb'stwo_factor_conditionand symfonycasts'request_password_repositoryitself. - Import the enrolment's routes:
resource: '@AuthBundle/Resources/config/routes/api.php'. - The reset link is always the realm's, never built from the request's host — which a visitor chooses.
- An application that serves several realms binds each access token to its realm (an audience), as it binds each host to its firewall: the bundle cannot know which host is whose.
Quality assurance
composer qa # coding standards, Rector, static analysis and tests composer test # PHPUnit composer phpstan # PHPStan, level max composer cs # PHP-CS-Fixer, writes the fixes composer rector # Rector, writes the fixes
License
The Auth Bundle is open-sourced software licensed under the MIT license.
© 2026 jul6art
