PHPackages                             rxlisbest/oauth2 - 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. rxlisbest/oauth2

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

rxlisbest/oauth2
================

The Oauth2 Server extension for the Yii2 framework

1.0.1(8y ago)010MITPHP

Since Mar 17Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (3)Used By (0)

Yii2 OAuth 2.0 Server
=====================

[](#yii2-oauth-20-server)

Description
-----------

[](#description)

This extension provides simple implementation of [Oauth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) specification using Yii2 framework.

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

[](#installation)

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

To install, either run

```
$ php composer.phar require rxlisbest/oauth2 "1.0"

```

or add

```
"rxlisbest/oauth2": "1.0"

```

to the `require` section of your `composer.json` file.

To create database tables run migration command

```
$ yii migrate --migrationPath=@rxlisbest/oauth2/migrations

```

Usage
-----

[](#usage)

OAuth 2.0 Authorization usage

```
namespace app\controllers;

use app\models\LoginForm;

class AuthController extends \yii\web\Controller
{
    public function behaviors()
    {
        return [
            /**
             * Checks oauth2 credentions and try to perform OAuth2 authorization on logged user.
             * AuthorizeFilter uses session to store incoming oauth2 request, so
             * you can do additional steps, such as third party oauth authorization (Facebook, Google ...)
             */
            'oauth2Auth' => [
                'class' => \conquer\oauth2\AuthorizeFilter::className(),
                'only' => ['index'],
            ],
        ];
    }
    public function actions()
    {
        return [
            /**
             * Returns an access token.
             */
            'token' => [
                'class' => \conquer\oauth2\TokenAction::classname(),
            ],
            /**
             * OPTIONAL
             * Third party oauth providers also can be used.
             */
            'back' => [
                'class' => \yii\authclient\AuthAction::className(),
                'successCallback' => [$this, 'successCallback'],
            ],
        ];
    }
    /**
     * Display login form, signup or something else.
     * AuthClients such as Google also may be used
     */
    public function actionIndex()
    {
        $model = new LoginForm();
        if ($model->load(\Yii::$app->request->post()) && $model->login()) {
            if ($this->isOauthRequest) {
                $this->finishAuthorization();
            } else {
                return $this->goBack();
            }
        } else {
            return $this->render('index', [
                'model' => $model,
            ]);
        }
    }
    /**
     * OPTIONAL
     * Third party oauth callback sample
     * @param OAuth2 $client
     */
    public function successCallback($client)
    {
        switch ($client::className()) {
            case GoogleOAuth::className():
                // Do login with automatic signup
                break;
            ...
            default:
                break;
        }
        /**
         * If user is logged on, redirects to oauth client with success,
         * or redirects error with Access Denied
         */
        if ($this->isOauthRequest) {
            $this->finishAuthorization();
        }
    }

}
```

Api controller sample

```
class ApiController extends \yii\rest\Controller
{
    public function behaviors()
    {
        return [
            /**
             * Performs authorization by token
             */
            'tokenAuth' => [
                'class' => \conquer\oauth2\TokenAuth::className(),
            ],
        ];
    }
    /**
     * Returns username and email
     */
    public function actionIndex()
    {
        $user = \Yii::$app->user->identity;
        return [
            'username' => $user->username,
            'email' =>  $user->email,
        ];
    }
}
```

Sample client config

```
return [
...
   'components' => [
       'authClientCollection' => [
            'class' => 'yii\authclient\Collection',
            'clients' => [
                'myserver' => [
                    'class' => 'yii\authclient\OAuth2',
                    'clientId' => 'unique client_id',
                    'clientSecret' => 'client_secret',
                    'tokenUrl' => 'http://myserver.local/auth/token',
                    'authUrl' => 'http://myserver.local/auth/index',
                    'apiBaseUrl' => 'http://myserver.local/api',
                ],
            ],
        ],
];
```

License
-------

[](#license)

**conquer/oauth2** is released under the MIT License. See the bundled `LICENSE` for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

2981d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62300e760338350c94e0b2d321deabf9145ca5969662dc95dc191a4ae402bf13?d=identicon)[rxlisbest](/maintainers/rxlisbest)

---

Top Contributors

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

---

Tags

oauth2yii2oauth2 server

### Embed Badge

![Health badge](/badges/rxlisbest-oauth2/health.svg)

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

###  Alternatives

[conquer/oauth2

The Oauth2 Server extension for the Yii2 framework

76112.9k5](/packages/conquer-oauth2)

PHPackages © 2026

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