eesnaola/sid-authentication-bundle
Installation Add the bundle via Composer:
composer require eesnaola/sid-authentication-bundle
Enable it in config/bundles.php:
return [
// ...
Eesnaola\SidAuthenticationBundle\SidAuthenticationBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console sid-authentication:install
Update config/packages/sid_authentication.yaml (e.g., adjust session_id_name or cookie_lifetime).
First Use Case Authenticate via a session ID (SID) in a controller:
use Symfony\Component\HttpFoundation\Request;
use Eesnaola\SidAuthenticationBundle\Security\SidAuthenticator;
public function login(Request $request, SidAuthenticator $authenticator)
{
$sid = $request->cookies->get('SID');
$user = $authenticator->authenticateBySid($sid);
// Handle user or redirect
}
Session-Based Auth
SidAuthenticator to validate SIDs in security.yaml:
firewalls:
main:
sid_authentication:
sid_parameter: SID
SidUserProvider to fetch users from your DB:
class CustomSidUserProvider extends SidUserProvider
{
public function loadUserBySid($sid): ?User
{
return $this->userRepository->findBy(['sid' => $sid]);
}
}
Cookie Management
SidGenerator:
$sid = $this->sidGenerator->generate();
$response->headers->setCookie(new Cookie('SID', $sid, time() + 3600));
$response->headers->clearCookie('SID');
Integration with Symfony Security
sid_authentication firewall in security.yaml to auto-validate SIDs.sid_authentication entry point:
sid_authentication:
sid_parameter: CUSTOM_SID_COOKIE
user_provider: App\Security\CustomSidUserProvider
SameSite/Secure cookie flags.Alpha Software
SidAuthenticator) to stabilize behavior.Session ID Collisions
sid_generator (default: random_bytes) produces unique IDs.Cookie Security
secure: true and httponly: true in sid_authentication.yaml:
sid_authentication:
cookie_options:
secure: true
httponly: true
samesite: 'Strict'
User Provider Quirks
loadUserBySid() to return null for invalid SIDs (avoid exceptions).loadUserBySid() is DB-bound.monolog for SidAuthenticator logs.SID cookie presence/values.sid_authentication.success/sid_authentication.failure events:
services:
App\EventListener\SidAuthListener:
tags:
- { name: kernel.event_listener, event: sid_authentication.success, method: onAuthSuccess }
Custom SID Storage
Replace SidStorageInterface to store SIDs in Redis/DB:
class RedisSidStorage implements SidStorageInterface
{
public function save($sid, User $user): void
{
Redis::set("sid:$sid", $user->getId());
}
}
Multi-Factor SID Auth
Combine with SecurityBundle to require SID + password:
firewalls:
main:
custom_form:
login_path: /login
check_path: /login_check
sid_authentication: ~
Rate Limiting
Use Symfony\Security\Http\Firewall\RateLimiter to block SID brute-force:
sid_authentication:
rate_limiter: 'authentication_rate_limiter'
How can I help you explore Laravel packages today?