nti/impersonation-bundle
A PHP package for safely impersonating users in your application. Administrators can switch into another account to troubleshoot or verify permissions, then return to their own session. Integrates with existing authentication and supports controlled, auditable impersonation.
nti/impersonation-bundle is a Symfony2 bundle, not a Laravel package. There is no service provider, no facade, no config/impersonation.php. If you're on Laravel, you cannot composer require this and expect it to boot — treat it as a reference implementation to mine for the impersonation workflow, then implement the equivalent with Laravel's Auth::login($user) / Auth::loginUsingId() plus a session flag.Nti\ImpersonationBundle\NtiImpersonationBundle in AppKernel, and read Resources/config/ and the DependencyInjection/ extension before touching your firewall — that is where the actual wiring lives.switch_user listener on your firewall. The bundle is a thin convenience layer on top of it. Confirm your firewall has switch_user: true and that your admin role has ROLE_ALLOWED_TO_SWITCH; without that, nothing in the bundle will work.?_switch_user=_exit) on day one — it is the part people forget._switch_user=<username>. Never let the target user be chosen without an explicit permission check on the actor.IS_IMPERSONATOR (or session-flag) check in your base layout so every page renders "You are acting as X — [Return]". This is the single highest-value pattern in the whole assessment: impersonation without an always-visible exit is how people file tickets as customers by accident.kernel.event_listener / Laravel event + listener) that log actor ID, target ID, timestamp, IP, and the originating ticket/order ID. The bundle gives you the mechanism; it does not give you the audit trail.switch_user stores the original token in the session; on exit it restores it. Mirror that in Laravel by stashing Auth::id() in the session (impersonator_id) at login time and restoring it on exit — never Auth::logout() the customer and hope the admin session survived.ROLE_ADMIN/ROLE_SUPER_ADMIN. Add an explicit deny in the authorization layer; do not rely on the firewall config alone.<img> or a link prefetcher.security.yaml) without porting. If you're on Laravel, the honest recommendation is: read it, copy the concept, write ~50 lines yourself.ROLE_ALLOWED_TO_SWITCH belongs to the impersonator, not the target. This is the #1 confusion. The admin's role hierarchy must grant it; granting it to the customer does nothing._switch_user only works on the firewall that has switch_user enabled. If your app has separate admin and main firewalls, switching across them silently fails or logs you out.$this->getUser(), a cached navigation menu built for the previous user) is stale. Force a redirect after switch — don't render in the same request.switch_user: true on the right firewall, (2) does the actor have ROLE_ALLOWED_TO_SWITCH, (3) does the URL carry the correct _switch_user value and the firewall's context, (4) is the security token actually rewritten (dump it), (5) is the exit link _switch_user=_exit.How can I help you explore Laravel packages today?