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

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

zacksleo/yii2-oauth2
====================

yii2 oauth2 module

1.0.8(7y ago)47.4kMITPHP

Since Jan 21Pushed 7y ago1 watchersCompare

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

READMEChangelog (8)Dependencies (7)Versions (10)Used By (0)

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

[](#yii2-oauth2)

yii2 oauth2 module based on [yii2-oauth2-server](https://github.com/Filsh/yii2-oauth2-server)

[![Latest Stable Version](https://camo.githubusercontent.com/1f5981f8eecd1e8f3313c2da282cce52536a6e30d3aa7999bd403de26b5eed3c/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d6f61757468322f76657273696f6e)](https://packagist.org/packages/zacksleo/yii2-oauth2)[![Total Downloads](https://camo.githubusercontent.com/eecc2a28e38b1764a40a2d6091be1cca30375af628f936d2bce3501dddf5d4a7/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d6f61757468322f646f776e6c6f616473)](https://packagist.org/packages/zacksleo/yii2-oauth2)[![License](https://camo.githubusercontent.com/2dadf3b717424bd5a1966c94cf219634d2ba28bcd7dd6e27d8e07f6723e70fc1/68747470733a2f2f706f7365722e707567782e6f72672f7a61636b736c656f2f796969322d6f61757468322f6c6963656e7365)](https://packagist.org/packages/zacksleo/yii2-oauth2)[![StyleCI](https://camo.githubusercontent.com/7af7304eddcffb81a4f388f7cfdc882696793af3003b25343434e82e73bf4ae3/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131373935333235332f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/117953253)![Code Climate](https://camo.githubusercontent.com/053c2be6a6e622438556365d37f4522156d2b66070ece10693e25fd1d6e9ae5e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f7a61636b736c656f2f796969322d6f61757468322e737667)[![Build Status](https://camo.githubusercontent.com/6eef4b9cc8544022832534b3f3acb3bdccdb94393c70e00d5b782da38bd59642/68747470733a2f2f7472617669732d63692e6f72672f7a61636b736c656f2f796969322d6f61757468322e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zacksleo/yii2-oauth2)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b41fababfa70dfa60cb98e2725537758ebd16f3672bbce79cf36b7cf350eca43/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a61636b736c656f2f796969322d6f61757468322f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/zacksleo/yii2-oauth2/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/744bdaf22249477a738cc7af8ee05e96d7af6e98964208b06d97619f90bdbe80/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a61636b736c656f2f796969322d6f61757468322f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/?branch=master)[![Build Status](https://camo.githubusercontent.com/a444da0de4319856c15b72cb357df981bc19325aa32e7147af5ffa454a14e251/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a61636b736c656f2f796969322d6f61757468322f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zacksleo/yii2-oauth2/build-status/master)

Install
-------

[](#install)

```
composer install zacksleo/yii2-oauth2

```

Migration Database
------------------

[](#migration-database)

```
./yii migrate --migrationPath=@vendor/zacksleo/yii2-oauth2/migrations

```

Config module
-------------

[](#config-module)

### for API or frontend

[](#for-api-or-frontend)

```
 'modules' => [
     'oauth2' => [
         'class' => 'filsh\yii2\oauth2server\Module',
         /* Fix Yii2 2.0.13+ Incompatible Issue
          * @see https://github.com/Filsh/yii2-oauth2-server/issues/132
          */
         'components' => [
            'request' => function () {
                return \filsh\yii2\oauth2server\Request::createFromGlobals();
            },
            'response' => [
                'class' => \filsh\yii2\oauth2server\Response::class,
            ],
         ],
         'tokenParamName' => 'access_token',
         'tokenAccessLifetime' => 3600 * 24 * 7,
         'storageMap' => [
             'user_credentials' => 'common\models\User',
             'access_token' => 'zacksleo\yii2\oauth2\common\models\storage\AccessToken',
         ],
         '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,
             ],
             'authorization_code' => [
                 'class' => 'OAuth2\GrantType\AuthorizationCode',
                 'require_exact_redirect_uri' => false,
             ]
         ]
     ]
 ]
```

### for backend

[](#for-backend)

```
  'modules' => [
      'oauth2' => [
          'class' => 'zacksleo\yii2\oauth2\backend\Module',
      ]
  ]
```

Token Controller
----------------

[](#token-controller)

```
