PHPackages                             devzyj/yii2-oauth2-server - 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. devzyj/yii2-oauth2-server

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

devzyj/yii2-oauth2-server
=========================

OAuth server for Yii2.

1.0.1(4y ago)015BSD-3-ClausePHP

Since Feb 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/devzyj/yii2-oauth2-server)[ Packagist](https://packagist.org/packages/devzyj/yii2-oauth2-server)[ RSS](/packages/devzyj-yii2-oauth2-server/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

yii2-oauth2-server
==================

[](#yii2-oauth2-server)

在 Yii2 中实现 OAuth2 服务器模块。

Installation
============

[](#installation)

```
composer require --prefer-dist "devzyj/yii2-oauth2-server" "~1.0.0"
```

or add

```
"devzyj/yii2-oauth2-server" : "~1.0.0"
```

Usage
=====

[](#usage)

```
php yii migrate --migrationPath=@devzyj/yii2/oauth2/server/migrations
```

```
// config.php
return [
    'bootstrap' => ['oauth2'],
    'modules' => [
        'oauth2' => [
            'class' => 'devzyj\yii2\oauth2\server\Module',
            'defaultScopes' => ['basic', 'basic2', 'basic3'], // 默认权限。
            'accessTokenCryptKey' => [
                'privateKey' => '@app/path/to/private.key', // 访问令牌的私钥路径。
                'passphrase' => '', // 访问令牌的私钥密码。没有密码可以为 `null`。
                'publicKey' => '@app/path/to/public.key', // 访问令牌的公钥路径。
                //'signKey' => 'test-sign-key', // 字符串签名密钥。
            ],
            'authorizationCodeCryptKey' => [
                'ascii' => 'def0000086937b.....', // 使用 `vendor/bin/generate-defuse-key` 生成的字符串。
                //'path' => '/path/to/ascii.txt', // 保存了 `vendor/bin/generate-defuse-key` 生成的字符串的文件路径。
                //'password' => 'test-password', // 字符串密钥。
            ],
            'refreshTokenCryptKey' => [
                'ascii' => 'def000008......', // 使用 `vendor/bin/generate-defuse-key` 生成的字符串。
                //'path' => '/path/to/ascii.txt', // 保存了 `vendor/bin/generate-defuse-key` 生成的字符串的文件路径。
                //'password' => 'test-password', // 字符串密钥。
            ],
            'validateAccessTokenQueryParam' => 'access-token', // 验证访问令牌时，在查询参数中的名称。
            'userRepositoryClass' => 'app\models\UserRepository',
            'user' => [
                'class' => 'yii\web\User',
                'identityClass' => 'app\models\UserIdentity',
            ],
            'loginUrl' => ['login'],
            'authorizationUrl' => ['authorization'],
            'classMap' => [ // 依赖注入。
                'devzyj\oauth2\server\authorizes\CodeAuthorize' => [
                    'class' => 'devzyj\oauth2\server\authorizes\CodeAuthorize',
                    'enableCodeChallenge' => true, // 使用 `code_challenge`，默认为 `false`。
                ],
                'devzyj\oauth2\server\grants\AuthorizationCodeGrant' => [
                    'class' => 'devzyj\oauth2\server\grants\AuthorizationCodeGrant',
                    'enableCodeChallenge' => true, // 使用 `code_challenge`，默认为 `false`。
                ],
                ....
                ....
            ],
        ],
    ],
];

// 使用模块方法，验证访问令牌。
$module = Yii::$app->getModule('oauth2');
$tokenInfo = $module->validateAccessToken($accessToken);
```

```
// 演示版配置项。
return [
    'modules' => [
        'oauth2' => [
            'userRepositoryClass' => 'devzyj\yii2\oauth2\server\demos\models\DemoUserRepository',
            'user' => [
                'class' => 'yii\web\User',
                'identityClass' => 'devzyj\yii2\oauth2\server\demos\models\DemoUserIdentity',
            ],
            'controllerMap' => [
                'demo' => 'devzyj\yii2\oauth2\server\demos\controllers\DemoController',
            ],
            'loginUrl' => ['/oauth2/demo/login'],
            'authorizationUrl' => ['/oauth2/demo/authorization'],
        ],
    ],
]
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~863 days

Total

2

Last Release

1770d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

oauthyii2serveroauthoauth2yii2extension

### Embed Badge

![Health badge](/badges/devzyj-yii2-oauth2-server/health.svg)

```
[![Health](https://phpackages.com/badges/devzyj-yii2-oauth2-server/health.svg)](https://phpackages.com/packages/devzyj-yii2-oauth2-server)
```

PHPackages © 2026

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