onix-systems-php/hyperf-impersonate
最新稳定版本:v1.0.0
Composer 安装命令:
composer require onix-systems-php/hyperf-impersonate
包简介
Hyperf Impersonate is a plugin that allows to you to authenticate as your users
README 文档
README
Includes the following classes:
- Contract:
- Impersonatable;
- Controller:
- ImpersonateController;
- DTO:
- ImpersonateInfoDTO;
- ImpersonateLeaveDTO;
- ImpersonateTakeDTO;
- Event:
- LeaveImpersonation
- TakeImpersonation
- Exception:
- AlreadyImpersonatingException;
- CantBeImpersonatedException;
- CantImpersonateException;
- CantImpersonateSelfException;
- NotImpersonatingException;
- ProtectedAgainstImpersonationException;
- Middleware:
- ProtectFromImpersonation;
- Resource:
- ResourceInfoImpersonate;
- ResourceLeaveImpersonate;
- ResourceTakeImpersonate;
- Service:
- ImpersonateService;
- Trait
- Impersonatable
Install:
composer require onix-systems-php/hyperf-impersonate
Publish config:
php bin/hyperf.php vendor:publish onix-systems-php/hyperf-impersonate -i config
Publish translations:
php bin/hyperf.php vendor:publish onix-systems-php/hyperf-impersonate -i en_us_translation php bin/hyperf.php vendor:publish onix-systems-php/hyperf-impersonate -i ua_uk_translation
Import impersonate routes:
require_once './vendor/onix-systems-php/hyperf-auth/publish/routes.php';
Add line to config/autoload/swagger.php for swagger:
'vendor/onix-systems-php/hyperf-impersonate/src/',
Basic Usage
use OnixSystemsPHP\HyperfImpersonate\Contract\Impersonatable as ImpersonatableInterface; use OnixSystemsPHP\HyperfImpersonate\Trait\Impersonatable; class User extends ... implements ImpersonatableInterface { use Impersonatable; }
Advanced Usage
Defining impersonation authorization
By default all users can impersonate an user.
You need to add the method canImpersonate() to your user model:
public function canImpersonate(): bool { return in_array($this->getRole(), UserRoles::GROUP_ADMINS); }
By default all users can be impersonated.
You need to add the method canBeImpersonated() to your user model to extend this behavior:
public function canBeImpersonated(): bool { return in_array($this->getRole(), UserRoles::GROUP_USERS); }
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-16