PHPackages                             oh86/laravel-gw-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. oh86/laravel-gw-auth

ActiveLibrary

oh86/laravel-gw-auth
====================

auth tools for oh86/laravel-gw

v1.1.3(4mo ago)0111MITPHP

Since Jan 6Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/OneHundred86/laravel-gw-auth)[ Packagist](https://packagist.org/packages/oh86/laravel-gw-auth)[ RSS](/packages/oh86-laravel-gw-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

oh86/laravel-gw网关鉴权组件库
======================

[](#oh86laravel-gw网关鉴权组件库)

### 一、生成配置文件

[](#一生成配置文件)

```
php artisan vendor:publish --provider='Oh86\GW\Auth\GatewayAuthServiceProvider'
```

### 二、简易教程

[](#二简易教程)

#### 1.私密请求校验中间件

[](#1私密请求校验中间件)

##### 1.1 配置 `config/gw-auth.php`

[](#11-配置-configgw-authphp)

```
return [
    'default' => env('GW_AUTH_DEFAULT_GATEWAY', 'default'),

    // 可配置后台接口网关、前台接口网关、openapi接口网关等
    'gateways' => [
        'default' => [
            'private-request' => [
                'app' => env('GW_AUTH_PRIVATE_APP'),
                'ticket' => env('GW_AUTH_PRIVATE_TICKET'),
                'ignore-check' => env('APP_DEBUG', false),  // 是否忽略校验，缺省是false
            ],
        ],

    ],
];
```

##### 1.2 使用中间件 `Oh86\GW\Auth\Middleware\CheckPrivateRequest`

[](#12-使用中间件-oh86gwauthmiddlewarecheckprivaterequest)

```
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Oh86\GW\Auth\Middleware\CheckPrivateRequest;

Route::post('api/private/test', [TestController::class, 'test'])->middleware([
    CheckPrivateRequest::class,
]);
```

#### 2.用户认证状态校验和获取

[](#2用户认证状态校验和获取)

##### 2.1 配置 `config/auth.php`

[](#21-配置-configauthphp)

```
return [
    // ...
    'guards' => [
        // ...

        'gw-auth' => [
            'driver' => 'gw',
            'header' => 'GW-Auth-Info',
            'user-class' => Oh86\GW\Auth\Guard\User::class,
        ]
    ],

    // ...
];
```

##### 2.2 校验用户登录状态和获取用户信息

[](#22-校验用户登录状态和获取用户信息)

```
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use Oh86\GW\Auth\Middleware\CheckPrivateRequest;

Route::post('api/private/auth/test', function(Request $request) {
    $user = Auth::user();

    return $user;
})->middleware([
    CheckPrivateRequest::class,
    'auth:gw-auth',
]);
```

#### 3.发送私密请求

[](#3发送私密请求)

##### 3.1 示例一

[](#31-示例一)

```
use Oh86\GW\Auth\HttpClient\PrivateRequest;

$req = new PrivateRequest([
    'baseUrl' => 'http://127.0.0.1:8000',
    'app' => 'app1',
    'ticket' => '...',
    ]);

$response = $req->get('api/private/test', ['foo' => 'bar']);

$status = $response->status();
$arr = $response->json();
```

##### 3.2 示例二，使用带有服务发现的私密请求

[](#32-示例二使用带有服务发现的私密请求)

###### 先配置 `config/gw-auth.php`

[](#先配置-configgw-authphp)

```
return [
    'default' => env('GW_AUTH_DEFAULT_GATEWAY', 'default'),

    'gateways' => [
        'default' => [
            // ...

            // 服务发现配置
            'service-discovery' => [
                'private-request' => [
                    'baseUrl' => env('GW_AUTH_SERVICE_DISCOVERY_BASE_URL'),
                    'app' => env('GW_AUTH_SERVICE_DISCOVERY_APP'),
                    'ticket' => env('GW_AUTH_SERVICE_DISCOVERY_TICKET'),
                ],
            ],
        ],

    ],
];
```

###### 请求示例：

[](#请求示例)

```
use Oh86\GW\Auth\HttpClient\PrivateRequestWithServiceDiscovery;

$req = new PrivateRequestWithServiceDiscovery('app1');

$response = $req->get('api/private/test', ['foo' => 'bar']);

$status = $response->status();
$arr = $response->json();
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance74

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Every ~86 days

Total

5

Last Release

147d ago

### Community

Maintainers

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

---

Top Contributors

[![OneHundred86](https://avatars.githubusercontent.com/u/22148561?v=4)](https://github.com/OneHundred86 "OneHundred86 (18 commits)")

### Embed Badge

![Health badge](/badges/oh86-laravel-gw-auth/health.svg)

```
[![Health](https://phpackages.com/badges/oh86-laravel-gw-auth/health.svg)](https://phpackages.com/packages/oh86-laravel-gw-auth)
```

PHPackages © 2026

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