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

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

bgi-online/yii2-oauth2-server
=============================

OAuth2 Server for PHP

2.0.1(10y ago)023MITPHP

Since Apr 10Pushed 9y agoCompare

[ Source](https://github.com/BGIOnline/yii2-oauth2-server)[ Packagist](https://packagist.org/packages/bgi-online/yii2-oauth2-server)[ Docs](https://github.com/filsh/yii2-oauth2-server)[ RSS](/packages/bgi-online-yii2-oauth2-server/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (5)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 as a new module:

```
'modules'=>[
        //other modules .....
        'oauth2' => [
            'class' => 'filsh\yii2\oauth2server\Module',
            'tokenParamName' => 'accessToken',
            'tokenAccessLifetime' => 3600 * 24,
            'storageMap' => [
                'user_credentials' => 'app\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)

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**

```
