christhompsontldr/impersonate
Laravel package to let authorized users impersonate other accounts for support and troubleshooting. Provides start/stop impersonation helpers, middleware/guards integration, and easy checks to ensure only permitted roles can switch users safely.
Authenticatable, Guard) and middleware, ensuring seamless integration with existing auth systems (e.g., Laravel Breeze, Sanctum, Passport).Illuminate\Auth\Authenticatable).id, email fields).Impersonate middleware, which can be added to routes or groups (e.g., /admin/*). Example:
Route::middleware(['auth', 'can:impersonate-others', 'impersonate'])->group(...);
remember_token).retrieved, saved) during impersonation.can_impersonate flag)?Illuminate\Auth).composer require christhompsontldr/impersonate
app/Http/Kernel.php:
'impersonate' => \ChrisThompsonTLDR\Impersonate\Middleware\Impersonate::class,
Impersonate middleware to add:
Log facade).Gate::allows('impersonate', $user)).Illuminate\Contracts\Auth\Authenticatable).Illuminate\Session\Middleware\StartSession).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package incompatibility with Laravel 10+ | Impersonation breaks silently. | Fork and update dependencies. |
| No session cleanup | Zombie impersonation sessions. | Add middleware to auto-revoke sessions. |
| Missing permission checks | Unauthorized impersonation. | Integrate with Laravel’s Gate policy. |
| No audit logging | Compliance/audit gaps. | Log impersonation events to a table. |
| Session fixation attack | Session hijacking. | Regenerate session ID on impersonation. |
How can I help you explore Laravel packages today?