PHPackages                             cncap/yii2oauth2server - 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. cncap/yii2oauth2server

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

cncap/yii2oauth2server
======================

OAuth2 Server for PHP

09PHP

Since Jul 6Pushed 10y ago1 watchersCompare

[ Source](https://github.com/cncap/yii2OAuthServer)[ Packagist](https://packagist.org/packages/cncap/yii2oauth2server)[ RSS](/packages/cncap-yii2oauth2server/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

This repository checkout from v2.0 branch of ()

---

yii2-oauth2-server's readme:
============================

[](#yii2-oauth2-servers-readme)

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 filsh/yii2-oauth2-server "*"

```

or add

```
"filsh/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' => 'cncap\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/filsh/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 cncap\yii2\oauth2server\filters\ErrorToExceptionFilter;
use cncap\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 12% 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/64367df1f0bba13ed8b7f5b7183d94b2a0c90f421374a7063e2087a8d960380d?d=identicon)[cncap](/maintainers/cncap)

---

Top Contributors

[![vemaxlee](https://avatars.githubusercontent.com/u/13921287?v=4)](https://github.com/vemaxlee "vemaxlee (7 commits)")

### Embed Badge

![Health badge](/badges/cncap-yii2oauth2server/health.svg)

```
[![Health](https://phpackages.com/badges/cncap-yii2oauth2server/health.svg)](https://phpackages.com/packages/cncap-yii2oauth2server)
```

###  Alternatives

[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

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