PHPackages                             hyperf-ext/auth - 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. hyperf-ext/auth

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

hyperf-ext/auth
===============

The Hyperf Auth package.

v2.2.0(4y ago)2380.1k↓17.8%16[6 issues](https://github.com/hyperf-ext/auth/issues)[2 PRs](https://github.com/hyperf-ext/auth/pulls)3MITPHPPHP &gt;=7.3

Since Sep 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hyperf-ext/auth)[ Packagist](https://packagist.org/packages/hyperf-ext/auth)[ RSS](/packages/hyperf-ext-auth/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (12)Versions (7)Used By (3)

Hyperf 认证组件
===========

[](#hyperf-认证组件)

该组件移植了 Laravel Auth 组件（[illuminate/auth](https://github.com/illuminate/auth)）相对完整的功能特性，除了中间件传参和邮件通知。

- Hyperf 的中间件遵循 PSR-15 的规范，无法使用 Laravel 的方式通过路由向中间件传递值，故在实现上与 Laravel 不同，仅实现了一个基础的身份认证中间件抽象类 `HyperfExt\Auth\Middlewares\AbstractAuthenticateMiddleware`。
- 邮件（[illuminate/mail](https://github.com/illuminate/mail)）和通知（[illuminate/notifications](https://github.com/illuminate/notifications)）尚未移植完成。

该组件实现了两个自定义注解。

- Hyperf\\Di\\Annotations\\AbstractAnnotation\\Auth
    可用于类和方法，语法 `Auth({"GUARD_CONF_NAME"[, ...]}[, passable=bool])`：

    - 第一个参数为 Guard 名列表
    - 第二个 `passable` 可选参数默认值为 `false`，设置为 `true` 时未认证的用户也可以通过 Guard，不会抛出为认证的异常，在某些特殊情况下将会比较有用。例如，同一个 API 需要对认证用户和非认证用户展示不同的数据。
- Hyperf\\Di\\Annotations\\AbstractAnnotation\\Policy
    可用于类，语法 `Policy({"MODEL_FQCN"\[, ...\]})`：

    - 参数为模型 FQCN 列表

另外，Gate 和策略的注册方法与 Laravel 不同。

Gate 可以通过注入 `HyperfExt\Auth\Contracts\Access\GateManagerInterface` 来调用实例的 `define` 方法注册。或者监听 `HyperfExt\Auth\Events\GateManagerResolved` 事件来在监听器中访问事件的 `gate` 属性（GateManagerInterface）来注册。

策略可以通过 `gen:policy` 命令来创建，例如 `gen:policy PostPolicy --model=App\\Model\\Post`。也可以在配置文件的 `policies` 中定义模型类和策略类的映射。

如需使用 JWT，请额外安装 [`hyperf-ext/jwt`](https://github.com/hyperf-ext/jwt) 组件。

安装
--

[](#安装)

```
composer require hyperf-ext/auth
```

发布配置
----

[](#发布配置)

```
php bin/hyperf.php vendor:publish hyperf-ext/auth
```

> 文件位于 `config/autoload/auth.php`。

配置
--

[](#配置)

> 详细说明见配置文件。

使用
--

[](#使用)

### 身份认证

[](#身份认证)

文档待完成。

### 授权

[](#授权)

文档待完成。

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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

Every ~65 days

Recently: every ~80 days

Total

6

Last Release

1798d ago

PHP version history (2 changes)v2.0.0PHP &gt;=7.2

v2.1.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fc06d3a44afebb588f3eba3f7f2515527e1796fa061cda5aa95ece1e072510c?d=identicon)[EricYZhu](/maintainers/EricYZhu)

---

Top Contributors

[![ericyzhu](https://avatars.githubusercontent.com/u/1786762?v=4)](https://github.com/ericyzhu "ericyzhu (6 commits)")[![FCMHUB](https://avatars.githubusercontent.com/u/33237325?v=4)](https://github.com/FCMHUB "FCMHUB (2 commits)")

---

Tags

authhyperfphpphpauthhyperf

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hyperf-ext-auth/health.svg)

```
[![Health](https://phpackages.com/badges/hyperf-ext-auth/health.svg)](https://phpackages.com/packages/hyperf-ext-auth)
```

###  Alternatives

[hyperf-ext/jwt

The Hyperf JWT package.

53140.6k2](/packages/hyperf-ext-jwt)

PHPackages © 2026

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