symfony/security-bundle
Symfony SecurityBundle integrates the Security component into the Symfony full-stack framework, providing authentication, authorization, and related security features with seamless configuration and framework tooling.
symfony/security-bundle is a core component of the Symfony framework, designed for seamless integration with Symfony’s full-stack architecture (e.g., dependency injection, routing, Twig, and event dispatching). For a Laravel-based application, this introduces a paradigm shift from Laravel’s native authentication (e.g., laravel/ui, laravel/sanctum, or spatie/laravel-permission) to Symfony’s component-based approach.UserProviderInterface with Laravel’s User model.Security component uses a token-based system (e.g., UsernamePasswordToken), which may not align with Laravel’s session/cookie-based auth.access_control to Laravel’s Route::middleware() requires custom logic.symfony/security-core, symfony/http-foundation), which may conflict with Laravel’s dependencies (e.g., symfony/http-client vs. Laravel’s Guzzle).replace or provide to avoid conflicts or isolate Symfony components in a micro-service or API layer.Security component relies on firewalls, entry points, and authenticators, which differ from Laravel’s Auth::attempt() or Sanctum token-based auth. Replicating Laravel’s auth flow (e.g., "remember me," CSRF protection) may require custom authenticators.Session component, which may not integrate cleanly with Laravel’s session driver (e.g., Redis, database).spatie/laravel-permission, league/oauth2-server) may suffice.Mercure or Umbrel) while Laravel handles the frontend?/login or /oauth/token endpoints.Security component.use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\HttpFoundation\Request;
class SymfonyAuthMiddleware
{
public function handle(Request $request, Closure $next)
{
$tokenStorage = new TokenStorage();
// Inject Symfony's auth logic here...
return $next($request);
}
}
HttpKernel as a Laravel service provider.KERNEL_REQUEST).Voter, OIDC → OidcUserProvider).security:check:firewall command for debugging.UserProviderInterface.TokenStorage and AuthenticationManager.| Laravel Feature | Symfony Security Bundle Equivalent | Compatibility Risk |
|---|---|---|
| Laravel Sanctum | OAuth2/OIDC Providers | High (different token formats) |
| Laravel Breeze/Jetstream | Form Login Authenticator + User Provider | Medium (UI templating differs) |
| Eloquent Users | Doctrine ORM or Custom UserProvider | High (Symfony defaults to Doctrine) |
| Laravel Middleware | Symfony Firewalls + Event Listeners | Medium (different invocation order) |
| Laravel Sessions | Symfony Session Component | Medium (config differences) |
| CSRF Protection | Symfony’s CSRF Token Manager | Low (can be bridged) |
composer require symfony/security-bundle symfony/security-core
config/packages/security.yaml (Symfony’s config format).security:
firewalls:
main:
lazy: true
provider: app_user_provider
form_login:
login_path: login
check_path: login
logout: true
providers:
app_user_provider:
entity: { class: App\Entity\User, property: email }
UserInterface:
class EloquentUserProvider implements UserProviderInterface
{
public function loadUserByUsername(string $username): UserInterface
{
return User::where('email', $username)->firstOrFail();
}
// ... other methods
}
Auth::attempt() with Symfony’s AuthenticationManager:
use Symfony\Component\Security\Core\Authentication
How can I help you explore Laravel packages today?