PHPackages                             onix-systems-php/hyperf-impersonate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. onix-systems-php/hyperf-impersonate

ActiveExtension[Authentication &amp; Authorization](/categories/authentication)

onix-systems-php/hyperf-impersonate
===================================

Hyperf Impersonate is a plugin that allows to you to authenticate as your users

v1.0.0(2y ago)12MITPHPPHP &gt;=8.1

Since Feb 16Pushed 2y ago2 watchersCompare

[ Source](https://github.com/onix-systems-php/hyperf-impersonate)[ Packagist](https://packagist.org/packages/onix-systems-php/hyperf-impersonate)[ RSS](/packages/onix-systems-php-hyperf-impersonate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Hyperf-impersonate component
============================

[](#hyperf-impersonate-component)

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
-----------

[](#basic-usage)

```
use OnixSystemsPHP\HyperfImpersonate\Contract\Impersonatable as ImpersonatableInterface;
use OnixSystemsPHP\HyperfImpersonate\Trait\Impersonatable;

class User extends ... implements ImpersonatableInterface
{
    use Impersonatable;
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Defining impersonation authorization

[](#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);
}
```

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

813d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e1c2e991197c9603eb160eb27e1be423eb683ee2eed293288993936444c20bb?d=identicon)[onix-systems-php](/maintainers/onix-systems-php)

---

Top Contributors

[![alexsyvolap](https://avatars.githubusercontent.com/u/80973788?v=4)](https://github.com/alexsyvolap "alexsyvolap (5 commits)")

---

Tags

phphyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/onix-systems-php-hyperf-impersonate/health.svg)

```
[![Health](https://phpackages.com/badges/onix-systems-php-hyperf-impersonate/health.svg)](https://phpackages.com/packages/onix-systems-php-hyperf-impersonate)
```

###  Alternatives

[hyperf-ext/jwt

The Hyperf JWT package.

53134.9k2](/packages/hyperf-ext-jwt)[hyperf-ext/auth

The Hyperf Auth package.

2376.2k3](/packages/hyperf-ext-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
