bigz/switch-user-stateless-bundle
UserProvider, Firewall, TokenStorage). Assumes Symfony’s dependency injection and event system.X-Impersonate-User) or token claims. Critical for cloud-native/horizontal scaling.impersonate_user_id).Security component, so impersonation triggers events like SECURITY_IMPERSONATE and SECURITY_IMPERSONATED.security.token_storage in Symfony 5.4+).Security component since 2020?IsGranted extension).impersonate_user_id).composer.json and register in Kernel.security.yaml:
security:
firewalls:
main:
stateless: true
switch_user: true # Enable impersonation
SwitchUserListener to add custom logic (e.g., logging).// Custom JWT encoder
$payload['impersonate_user_id'] = $impersonatedUserId;
X-Impersonate-User header or token claim to API requests.curl -H "Authorization: Bearer $TOKEN" -H "X-Impersonate-User: 123" $API_URL
security.token_storage, which was deprecated in Symfony 5.4 in favor of security.user_value_resolver. May need a custom resolver or patch.SECURITY_IMPERSONATE). Ensure your app listens to these if using event-driven workflows./admin/impersonate).UserProvider) may add latency if the provider is slow.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Token issuer doesn’t support claims | Impersonation fails silently. | Use a custom middleware to parse headers. |
| Invalid impersonation user ID | Security risk |
How can I help you explore Laravel packages today?