PHPackages                             waywake/auth-client - 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. waywake/auth-client

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

waywake/auth-client
===================

Auth client for WayWake services

v4.2.0(1mo ago)0204MITPHPPHP ^8.4

Since May 4Pushed 1mo agoCompare

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

READMEChangelogDependencies (9)Versions (39)Used By (0)

Waywake Auth Client
===================

[](#waywake-auth-client)

`waywake/auth-client` 是公司内部 Auth 系统的 PHP 客户端包，面向 Laravel/Lumen 12 和 13 应用。它通过 `waywake/json-rpc` 调用 Auth 服务，提供：

- OAuth code 换 access token
- 根据 token 获取当前用户信息
- 登录中间件和权限中间件
- Web 登录跳转 URL 生成
- Laravel/Lumen 服务提供者和内置 token/logout 路由

环境要求
----

[](#环境要求)

- PHP `^8.4`
- Laravel/Lumen 12 或 13 相关组件
- `waywake/json-rpc ^2.2`

开发测试使用 PHPUnit 11，覆盖率使用 PCOV。

安装
--

[](#安装)

```
composer require waywake/auth-client
```

如果项目没有自动加载服务提供者，需要手动注册：

```
PdAuth\PdAuthServiceProvider::class
```

Laravel 项目可发布配置：

```
php artisan vendor:publish --tag=pdauth
```

Lumen 项目在应用启动时注册服务提供者即可，包会调用 `configure('pdauth')`。

配置
--

[](#配置)

配置文件来源是 `config/auth.php`，合并到应用配置键 `pdauth`。

默认支持的应用：

- `op`
- `erp`
- `crm`
- `ds`
- `payment`
- `xiaoke`
- `finance`

常用环境变量：

```
APP_ENV=local
APP_NAME=erp
RPC_AUTH_URI=http://auth.dev.haowumc.com

AUTH_OP_SECRET=123456
AUTH_ERP_SECRET=123456
AUTH_CRM_SECRET=123456
AUTH_DS_SECRET=123456
AUTH_PAYMENT_SECRET=123456
AUTH_XIAOKE_SECRET=123456
AUTH_FINANCE_SECRET=123456
```

`APP_ENV` 会影响 Auth Web 地址：

- `local` / `develop`: `http://auth.dev.haowumc.com`
- `production`: `https://auth.int.haowumc.com`

`RPC_AUTH_URI` 用于 JSON-RPC 客户端访问 Auth 服务。若应用容器里已经绑定 `rpc.auth`，本包会优先复用该客户端；否则会创建 `JsonRpc\Client` 并选择 `auth` endpoint。

控制器用法
-----

[](#控制器用法)

控制器中引入 `PdAuth\Controller` trait，并在构造函数中选择 guard：

```
use PdAuth\Controller;

class UserController
{
    use Controller;

    public function __construct()
    {
        $this->auth('erp');
    }

    public function me()
    {
        return $this->user;
    }
}
```

`auth($guard)` 会完成：

- `app('auth')->shouldUse($guard)`
- `app('pd.auth')->choose($guard)`
- 注册 `PdAuth\Middleware\Authenticate`
- 注册 `PdAuth\Middleware\CheckRole`
- 将当前用户写入 `$this->user`

权限配置
----

[](#权限配置)

`CheckRole` 会读取当前路由 action 对应控制器上的 `Privileges`。支持常量或静态属性：

```
class OrderController
{
    public const Privileges = [
        'index' => ['admin', 'sales'],
        'show' => '*',
    ];
}
```

规则：

- action 配置为 `'*'` 时直接放行
- 用户没有 `roles` 时返回 403
- 用户角色和 action 角色无交集时返回 403
- 控制器或 action 未定义权限时返回 403

前端登录流程
------

[](#前端登录流程)

未登录访问受保护接口时：

- JSON 请求返回 HTTP `401`
- 响应体包含 `data.url`，前端应跳转到该地址登录

示例响应：

```
{
  "code": 400401,
  "msg": "Unauthorized",
  "data": {
    "url": "http://auth.dev.haowumc.com/connect?appid=100009&redirect=..."
  }
}
```

扫码登录后 Auth 会返回 `pd_code` 和 `app_id`，前端调用：

```
GET /api/auth/token.json?pd_code=...&app_id=...

```

成功后返回 token 数据，并写入 `token` cookie。

退出登录：

```
GET /api/auth/logout

```

响应中的 `data.url` 是 Auth 系统退出地址，客户端可继续跳转。

Auth API
--------

[](#auth-api)

```
$auth = app('pd.auth')->choose('erp');

$loginUrl = $auth->connect('https://app.example.com/callback');
$token = $auth->getAccessToken($code);
$user = $auth->getUserInfo($token['access_token']);
$auth->logout($token['access_token']);
```

也可以按 `app_id` 选择应用：

```
$auth = app('pd.auth')->choose(null, '100009');
```

路由
--

[](#路由)

服务提供者会注册：

```
GET api/auth/token.json
GET api/auth/token.html
GET api/auth/logout

```

`token.json` 返回 JSON，`token.html` 写 cookie 后重定向到 `/`。

测试
--

[](#测试)

安装依赖：

```
composer install
```

运行测试：

```
composer test
```

使用 PCOV 生成覆盖率：

```
composer test:coverage
```

当前测试覆盖核心类：

- `PdAuth\Auth`
- `PdAuth\Controller`
- `PdAuth\PdAuthServiceProvider`
- `PdAuth\Middleware\Authenticate`
- `PdAuth\Middleware\CheckRole`

`tests/1.php` 是历史手动调试脚本，不属于 PHPUnit 测试套件。

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance90

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.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

Every ~79 days

Recently: every ~32 days

Total

38

Last Release

50d ago

Major Versions

v1.0.8 → v2.0.12019-01-24

v2.1.13 → v3.0.12019-07-22

v3.0.2 → v4.0.02026-01-03

PHP version history (2 changes)v4.0.0PHP ^8.3

v4.1.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3872854a6aea1f16610c9b1125ee7058281d69223cdf9b5ed3396ff06a9fbee0?d=identicon)[xAmast](/maintainers/xAmast)

---

Top Contributors

[![i5shuyi](https://avatars.githubusercontent.com/u/58246546?v=4)](https://github.com/i5shuyi "i5shuyi (13 commits)")[![izpdavi](https://avatars.githubusercontent.com/u/7802716?v=4)](https://github.com/izpdavi "izpdavi (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waywake-auth-client/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

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