abdullyahuza/filament-impersonate
最新稳定版本:v1.0.0
Composer 安装命令:
composer require abdullyahuza/filament-impersonate
包简介
Filament Impersonate allows administrators to securely impersonate other users within the Filament admin panel. With a simple "Impersonate" action, admins can log in as another user to troubleshoot issues, test permissions, or preview user-specific content. A visible banner indicates impersonation m
README 文档
README
🎭 Filament Impersonate
A plugin for Filament Admin Panel that allows authorized users to impersonate other users.
📦 Installation
composer require abdullyahuza/filament-impersonate
Optionally publish the config file:
php artisan vendor:publish --tag="filament-impersonate-config"
⚙️ Configuration
Inside config/filament-impersonate.php:
return [ 'redirect_after_impersonation' => 'filament.app.pages.dashboard', 'guard' => 'web', 'user_model' => \App\Models\User::class, 'session_key' => 'filament_impersonator_id', 'excluded_user_ids' => [/* user IDs that should never be impersonated */], 'allowed_environments' => ['local', 'staging', 'production'], 'display_name_resolver' => fn ($user) => $user->name ?? 'Unknown User', 'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate users'), ];
Setup Filament-Impersonate
Install for Panel
->plugins([
...
FilamentImpersonate::make(),
])
->middleware([
...
// AuthenticateSession::class,
])
✅ Usage
Impersonate a user
- From the Filament UI, click the impersonation button shown next to user profile (if allowed).
- You will be logged in as that user.
- A banner or button will appear indicating impersonation — click it to stop impersonating.
Stop impersonating
Click the "Stop Impersonating" button to return to your original user session.
🔐 Permissions
To restrict who can impersonate users, configure the can_impersonate_resolver in your config file.
Example:
'can_impersonate_resolver' => fn ($user) => $user?->hasRole('admin') || $user?->can('impersonate_users'),
💾 Session Management
During impersonation, the following is stored in the session:
- Impersonator ID
- Original user roles & permissions (if applicable)
These are restored when impersonation is stopped.
🛡️ Notes
- Only users not in
excluded_user_idscan be impersonated. - Impersonation only works in environments defined in
allowed_environments. - You can customize how user names are displayed using
display_name_resolver.
🧪 Testing
Ensure your environment is included in allowed_environments for local testing.
'allowed_environments' => ['local'],
📄 License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-21
