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

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

femike/yii2-oauth2-server
=========================

OAuth2 Server for PHP fork Filsh/yii2-oauth2-server

2.0.3(10y ago)21831MITPHP

Since Sep 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/femike/yii2-oauth2-server)[ Packagist](https://packagist.org/packages/femike/yii2-oauth2-server)[ Docs](https://github.com/femike/yii2-oauth2-server)[ RSS](/packages/femike-yii2-oauth2-server/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)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 filsh/yii2-oauth2-server "*"

```

or add

```
"filsh/yii2-oauth2-server": "~2.0"
```

to the require section of your composer.json.

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

```
'bootstrap' => ['oauth2'],
'modules' => [
    'oauth2' => [
        'class' => 'filsh\yii2\oauth2server\Module',
        'tokenParamName' => 'accessToken',
        'tokenAccessLifetime' => 3600 * 24,
        'storageMap' => [
            'user_credentials' => 'common\models\User',
        ],
        'grantTypes' => [
            '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/rest/',
        ...
    ]
]
```

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 filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use filsh\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()
            ],
        ]);
    }
}
```

Create action authorize in site controller for Authorization Code

`https://api.mysite.com/authorize?response_type=code&client_id=TestClient&redirect_uri=https://fake/`

[see more](http://bshaffer.github.io/oauth2-server-php-docs/grant-types/authorization-code/)

```
/**
 * SiteController
 */
class SiteController extends Controller
{
    /**
     * @return mixed
     */
    public function actionAuthorize()
    {
        if (Yii::$app->getUser()->getIsGuest())
            return $this->redirect('login');

        /** @var $module \filsh\yii2\oauth2server\Module */
        $module = Yii::$app->getModule('oauth2');
        $response = $module->handleAuthorizeRequest(!Yii::$app->getUser()->getIsGuest(), Yii::$app->getUser()->getId());

        /** @var object $response \OAuth2\Response */
        Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;

        return $response->getParameters();
    }
}
```

For more, see

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 76.8% 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 ~18 days

Total

3

Last Release

3851d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fd6426297d2eb1b8653a95ee8192e7f2ba2a9187a9c9f2562e7397698ebc9ff?d=identicon)[femike](/maintainers/femike)

---

Top Contributors

[![filsh](https://avatars.githubusercontent.com/u/6173680?v=4)](https://github.com/filsh "filsh (43 commits)")[![freezy-sk](https://avatars.githubusercontent.com/u/661637?v=4)](https://github.com/freezy-sk "freezy-sk (6 commits)")[![pelegrin](https://avatars.githubusercontent.com/u/1381989?v=4)](https://github.com/pelegrin "pelegrin (2 commits)")[![rzani](https://avatars.githubusercontent.com/u/684192?v=4)](https://github.com/rzani "rzani (1 commits)")[![Dareen](https://avatars.githubusercontent.com/u/5462442?v=4)](https://github.com/Dareen "Dareen (1 commits)")[![shcherbanich](https://avatars.githubusercontent.com/u/3122336?v=4)](https://github.com/shcherbanich "shcherbanich (1 commits)")[![hiqsol](https://avatars.githubusercontent.com/u/11820365?v=4)](https://github.com/hiqsol "hiqsol (1 commits)")[![RoyXiang](https://avatars.githubusercontent.com/u/1772811?v=4)](https://github.com/RoyXiang "RoyXiang (1 commits)")

---

Tags

oauthoauth2extensionmoduleyii

### Embed Badge

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

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

###  Alternatives

[filsh/yii2-oauth2-server

OAuth2 Server for PHP

331523.9k12](/packages/filsh-yii2-oauth2-server)[budyaga/yii2-users

Module for manage users and their rights with the support of registration through social services and assigned to each user more than one social service.

409.1k](/packages/budyaga-yii2-users)

PHPackages © 2026

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