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

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

alegz/yii2-oauth2-server
========================

OAuth2 Server for PHP Framework Yii2

2.2.3(9y ago)03362MITPHP

Since Apr 10Pushed 9y ago2 watchersCompare

[ Source](https://github.com/Alegzander/yii2-oauth2-server)[ Packagist](https://packagist.org/packages/alegz/yii2-oauth2-server)[ Docs](https://github.com/filsh/yii2-oauth2-server)[ RSS](/packages/alegz-yii2-oauth2-server/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (2)Versions (12)Used By (2)

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

[](#yii2-oauth2-server)

A wrapper for implementing an OAuth2 Server()

Important
---------

[](#important)

This is fork of original () repo was also submited as a separate package but code namespaces are saved.

Reason for that is no update on original repo for a long time. Me and my friends have applied some usefull patches with fixes and improvements. Fixed branches mess. Latest stable version is now in master. Please see closed pull requests for more information what changes were made to master ()

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

[](#installation)

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

Either run

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

```

or add

```
"alegz/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 as a new module:

```
'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
            ]
        ]
    ]
]
```

If you want to get Json Web Token (JWT) instead of convetional token, you will need to set `'useJwtToken' => true` in module and then define two more configurations: `'public_key' => 'app\storage\PublicKeyStorage'` which is the class that implements [PublickKeyInterface](https://github.com/bshaffer/oauth2-server-php/blob/develop/src/OAuth2/Storage/PublicKeyInterface.php) and `'access_token' => 'app\storage\JwtAccessToken'` which implements [JwtAccessTokenInterface.php](https://github.com/bshaffer/oauth2-server-php/blob/develop/src/OAuth2/Storage/JwtAccessTokenInterface.php)

`common\models\User` - user model implementing an interface `\OAuth2\Storage\UserCredentialsInterface`, so the oauth2 credentials data stored in user table For Oauth2 base library provides the default [access\_token](https://github.com/bshaffer/oauth2-server-php/blob/develop/src/OAuth2/Storage/JwtAccessToken.php) which works great except that it tries to save the token in the database. So I decided to inherit from it and override the part that tries to save (token size is too big and crashes with VARCHAR(40) in the database.

TL;DR, here are the sample classes **access\_token**

```
