PHPackages                             mongdch/mon-auth-think - 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. mongdch/mon-auth-think

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

mongdch/mon-auth-think
======================

PHP权限控制库

1.2.5(1mo ago)01291MITPHPPHP &gt;=7.4

Since Jan 27Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/MonGDCH/mon-auth-think)[ Packagist](https://packagist.org/packages/mongdch/mon-auth-think)[ Docs](https://github.com/MonGDCH)[ RSS](/packages/mongdch-mon-auth-think/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (19)Used By (1)

mon-auth-think
==============

[](#mon-auth-think)

#### 介绍

[](#介绍)

基于think-orm的PHP权限管理类库，包含`Jwt`、`RBAC`、`AccessToken`、`Signature`等权限控制类库。

#### 安装使用

[](#安装使用)

1. composer安装本项目

```
composer require mongdch/mon-auth-think
```

2. 如需使用RBAC库，则运行导入database目录下`rbac.sql`文件到数据库中。按需修改修改增加字段即可。
3. 如需使用Mysql版本的`AccessToken`、`Signature`，则运行导入database目录下`api.sql`文件到数据库中，按需修改配置即可
4. `Gaia`框架使用则执行再运行一下脚本

```
php gaia vendor:publish mon\auth
```

#### API文档

[](#api文档)

- 暂未编写，请通过查看examples目录下的demo，阅读了解更多使用方法。

#### Demo

[](#demo)

1. JWT

```
use mon\auth\jwt\driver\Token;
use mon\auth\jwt\driver\Payload;
use mon\auth\exception\JwtException;

try{
	// 加密密钥
	$key = 'aaaaaaa';
	// 加密算法
	$alg = 'HS256';
	$build = new Payload;
	// $token = new Token;
	$token = Token::instance();

	// 构建payload
	$payload = $build->setIss('abc')->setSub('def')->setExt(['a' => '123'])->setExp(3600)->setAud('127.0.0.1');
	// 创建jwt
	$jwt = $token->create($payload, $key, $alg);
	dd($jwt);

	// 验证jwt
	$data = $token->check($jwt, $key, $alg);
	dd($data);
}
catch (JwtException $e){
	dd('Msg: '.$e->getMessage(), 'Line: '.$e->getLine(), 'Code: '.$e->getCode());
}
```

```
use mon\auth\jwt\Auth;

$token = Auth::instance()->create(1, ['pm' => 'tch']);

dd($token);

$data = Auth::instance()->check($token);
dd($data);
```

2. RBAC

```
use mon\auth\rbac\Auth;

$config = [
    // 权限开关
    'auth_on'           => true,
    // 用户组数据表名
    'auth_role'         => 'auth_role',
    // 用户-用户组关系表
    'auth_role_access'  => 'auth_access',
    // 权限规则表
    'auth_rule'         => 'auth_rule',
    // 超级管理员权限标志
    'admin_mark'        => '*',
];

Auth::instance()->init($config);
$check = Auth::instance()->check('/admin/sys/auth/group/add', 1);
debug($check);
```

3. AccessToken

```
use mon\util\Event;
use mon\auth\api\AccessTokenAuth;
use mon\auth\exception\APIException;

// 初始化
AccessTokenAuth::instance()->init();

$appid = 'abcdefg';
$secret = 'asdas234';

// 自定义验证事件
Event::instance()->listen('access_check', function ($data) {
    // token数据
    // dd($data);

    // 抛出异常 APIException 作为验证不通过的标志
    throw new APIException('自定义验证错误', 0, null, $data);
});

$token = AccessTokenAuth::instance()->create($appid, $secret);

dd($token);

try {
    $decode = AccessTokenAuth::instance()->check($token, $appid, $secret);
    dd($decode);
} catch (APIException $e) {
    dd('验证不通过！' . $e->getMessage() . ' code: ' . $e->getCode());
    // 异常绑定的数据
    dd($e->getData());
}
```

4. apiSignature

```
use mon\auth\api\SignatureAuth;

SignatureAuth::instance()->init();

$appid = 'TEST123456789';
$secret = 'asdas234';

$data = [
    'a' => 1,
    'b' => 'asd',
    'c' => true,
];

$tokenData = SignatureAuth::instance()->create($appid, $secret, $data);

dd($tokenData);

$check = SignatureAuth::instance()->check($secret, $tokenData);

dd($check);
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

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

Every ~46 days

Recently: every ~69 days

Total

18

Last Release

54d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.2

1.1.6PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![MonGDCH](https://avatars.githubusercontent.com/u/19282393?v=4)](https://github.com/MonGDCH "MonGDCH (34 commits)")

---

Tags

jwtrbacaccess tokenthink-ormapi-signature

### Embed Badge

![Health badge](/badges/mongdch-mon-auth-think/health.svg)

```
[![Health](https://phpackages.com/badges/mongdch-mon-auth-think/health.svg)](https://phpackages.com/packages/mongdch-mon-auth-think)
```

###  Alternatives

[firebase/php-jwt

A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.

9.8k445.7M2.1k](/packages/firebase-php-jwt)[lcobucci/jwt

A simple library to work with JSON Web Token and JSON Web Signature

7.5k316.6M895](/packages/lcobucci-jwt)[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)

PHPackages © 2026

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