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

ActiveYii2-extension

sxlxnyw/yii2-oauth2-server
==========================

OAuth2 Server for PHP

05PHP

Since Nov 8Pushed 9y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#yii2-oauth2-server)

A wrapper for implementing an OAuth2 Server()

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist sxlxnyw/yii2-oauth2-server "*"

```

or add

```
"sxlxnyw/yii2-oauth2-server": "*"
```

to the require section of your composer.json.

To use this extension, simply add the following code in your application configuration:

```
'oauth2' => [
    'class' => 'sxlxnyw\yii2\oauth2server\Module',
    'options' => [
        'token_param_name' => 'accessToken',
        'access_lifetime' => 3600 * 24
    ],
    'storageMap' => [
        'user_credentials' => 'common\models\User'
    ],
    'grantTypes' => [
        'client_credentials' => [
            'class' => 'OAuth2\GrantType\ClientCredentials',
            'allow_public_clients' => false
        ],
        'user_credentials' => [
            'class' => 'OAuth2\GrantType\UserCredentials'
        ],
        'refresh_token' => [
            'class' => 'OAuth2\GrantType\RefreshToken',
            'always_issue_new_refresh_token' => true
        ]
    ],
]
```

`common\models\User` - user model implementing an interface `\OAuth2\Storage\UserCredentialsInterface`, so the oauth2 credentials data stored in user table

The next step your shold run migration

```
yii migrate --migrationPath=@vendor/sxlxnyw/yii2-oauth2-server/migrations
```

this migration create the oauth2 database scheme and insert test user credentials `testclient:testpass` for `http://fake/`

add url rule to urlManager

```
'urlManager' => [
    'rules' => [
        'POST oauth2/' => 'oauth2/default/',
        ...
    ]
]
```

Usage
-----

[](#usage)

To use this extension, simply add the behaviors for your base controller:

```
use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use sxlxnyw\yii2\oauth2server\filters\ErrorToExceptionFilter;
use sxlxnyw\yii2\oauth2server\filters\auth\CompositeAuth;

class Controller extends \yii\rest\Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => CompositeAuth::className(),
                'authMethods' => [
                    ['class' => HttpBearerAuth::className()],
                    ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken'],
                ]
            ],
            'exceptionFilter' => [
                'class' => ErrorToExceptionFilter::className()
            ],
        ]);
    }
}
```

For more, see

###  Health Score

20

—

LowBetter than 17% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![sxlxnyw](https://avatars.githubusercontent.com/u/13213919?v=4)](https://github.com/sxlxnyw "sxlxnyw (5 commits)")

### Embed Badge

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

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

PHPackages © 2026

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