Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Security Bundle

Security Bundle Laravel Package

symfony/security-bundle

Symfony SecurityBundle tightly integrates the Symfony Security component into the full-stack framework, providing authentication, authorization, firewalls, user providers, and access control with seamless configuration and framework-level tooling.

View on GitHub
Deep Wiki
Context7

Provides a tight integration of the Security component into the Symfony full-stack framework

Frequently asked questions about Security Bundle
Can I use Symfony SecurityBundle directly in a Laravel project without migrating to Symfony?
No, the bundle is designed for Symfony’s full-stack framework and relies on Symfony’s DependencyInjection, routing, and event systems. However, you can integrate individual Symfony Security *components* (e.g., `symfony/security-core`) into Laravel via Composer, adapting configurations manually. For a full bundle experience, consider a hybrid architecture or a Laravel wrapper package.
How does Symfony SecurityBundle’s role-based access control compare to Laravel’s Gates/Policies?
Symfony’s SecurityBundle uses a declarative `security.yaml` configuration with voters for fine-grained access control, similar to Laravel’s Policies but more flexible for complex rules. Laravel’s Gates are simpler for basic checks, while Symfony’s system scales better for multi-role hierarchies or dynamic permissions. You’d need to map Symfony’s `VoterInterface` to Laravel’s `Policy` or create a custom adapter layer.
What Laravel versions are compatible with Symfony SecurityBundle?
The bundle itself doesn’t support Laravel natively, but its underlying *components* (e.g., `symfony/security-core`) are compatible with Laravel 8+ if you install them directly. Version conflicts may arise with Laravel’s bundled Symfony components (e.g., `illuminate/http` vs. `symfony/http-foundation`). Test thoroughly, as Laravel’s service container and middleware pipeline differ from Symfony’s.
How do I configure OAuth2/OIDC authentication with Symfony SecurityBundle in Laravel?
Symfony SecurityBundle provides built-in support for OAuth2/OIDC via the `security.yaml` configuration, but integrating it into Laravel requires bypassing Laravel’s default auth system. You’d need to create a custom Laravel service provider to bridge Symfony’s `OAuth2Authenticator` with Laravel’s `Auth::login()`. Alternatively, use Laravel’s `socialiteproviders` packages for OAuth2 and adapt Symfony’s token handling.
Will using Symfony SecurityBundle slow down my Laravel application?
Minimal overhead is expected if you use only the core components, but the full bundle includes profiling tools and event listeners that may add latency. Symfony’s bundle is optimized for Symfony’s architecture, so performance depends on how well you abstract its dependencies. Benchmark with your specific use case, especially if mixing Laravel and Symfony middleware or services.
Can I replace Laravel’s built-in authentication (Auth, Sessions) entirely with Symfony SecurityBundle?
Technically possible but complex due to architectural differences. Laravel’s `Auth` facade and session handling are tightly coupled with Illuminate’s container, while Symfony’s bundle relies on its own DI and session system. A partial replacement (e.g., using Symfony for OAuth2 only) is more practical. Expect to rewrite or adapt Laravel’s auth middleware, guards, and session drivers.
Are there Laravel-specific wrappers or adapters for Symfony SecurityBundle?
No official wrappers exist, but you can build one by extending Symfony’s components with Laravel’s contracts (e.g., `Authenticatable`, `Authorizable`). Community packages like `spatie/laravel-symfony-components` provide partial integrations for other Symfony components. For authentication, consider `laravel/passport` or `spatie/laravel-permission` as alternatives if you don’t need Symfony’s advanced features.
How do I handle CSRF protection in Laravel if I’m using Symfony SecurityBundle?
Symfony SecurityBundle includes CSRF protection via its `CsrfTokenManager`, but Laravel’s `VerifyCsrfToken` middleware uses a different token format. You’ll need to either disable Laravel’s CSRF middleware and use Symfony’s, or create a custom middleware to bridge both systems. Ensure your forms and APIs generate tokens compatible with your chosen system.
What’s the best way to test authentication flows when using Symfony SecurityBundle in Laravel?
Test authentication flows by mocking Symfony’s `TokenStorage`, `AuthenticationManager`, and `UserProvider` interfaces in PHPUnit. For Laravel-specific tests, extend Laravel’s `AuthenticationTestingTrait` and override methods to use Symfony’s token system. Use Laravel’s `HttpTests` for middleware testing, but account for Symfony’s event-driven firewall logic by testing event listeners separately.
How do I deploy a Laravel app with Symfony SecurityBundle to production without dependency conflicts?
Resolve conflicts by pinning Symfony component versions in `composer.json` to match Laravel’s bundled versions (e.g., `symfony/http-foundation:^6.0` if Laravel 9+). Use `composer why-not` to diagnose conflicts, and consider a monorepo or vendor-specific Composer setups if conflicts persist. Test your production environment with a staging server to catch hidden issues, especially with session storage or cache drivers.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai