PHPackages                             death\_satan/hyperf-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. death\_satan/hyperf-auth

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

death\_satan/hyperf-auth
========================

The Hyperf Auth package.

v3.1.0(2y ago)018MITPHPPHP &gt;=8.1

Since Jan 7Pushed 2y agoCompare

[ Source](https://github.com/zds-s/hyperf-auth)[ Packagist](https://packagist.org/packages/death_satan/hyperf-auth)[ RSS](/packages/death-satan-hyperf-auth/feed)WikiDiscussions master Synced 1mo ago

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

Hyperf 认证组件 \[此组件 fork hyperf-ext/auth,适配hyperf最新版\]
====================================================

[](#hyperf-认证组件-此组件-fork-hyperf-extauth适配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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

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

853d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfd742c3c43b35e19b7f48d680be2aeb42db75213e105285586b6b3f27a8b18f?d=identicon)[zds](/maintainers/zds)

---

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)")[![zds-s](https://avatars.githubusercontent.com/u/49744633?v=4)](https://github.com/zds-s "zds-s (1 commits)")

---

Tags

phpauthhyperf

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[hyperf-ext/auth

The Hyperf Auth package.

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

The Hyperf JWT package.

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

PHPackages © 2026

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