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

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

bnviking/yii2-oauth2
====================

OAuth2.0 Yii2 extension

v1.1.1(4y ago)3158MITPHPPHP &gt;=7.4

Since Apr 3Pushed 4y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

 [ ![](https://avatars.githubusercontent.com/u/12669446?s=400&u=d883b62c0adcae00380135155c820b5d928224dc&v=4) ](https://bnv.one)

OAuth2.0
--------

[](#oauth20)

#### Extension for Yii2 framework

[](#extension-for-yii2-framework)

 [![Widget OAuth2.0](./widget.png)](./widget.png)

---

The following clients are currently supported for authorization:

- vk.com \[[register your application](https://vk.com/apps?act=manage)\]
- mail.ru \[[register your application](https://o2.mail.ru/app/)\]
- yandex.ru \[[register your application](https://oauth.yandex.ru/)\]
- discord.com \[[register your application](https://discord.com/developers/applications)\]
- trovo.live \[[register your application](https://developer.trovo.live/)\]
- twitch.tv \[[register your application](https://dev.twitch.tv/console)\]

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

[](#installation)

The preferred way to install this extension is through \[composer\] ().

Either run

```
php composer.phar require --prefer-dist bnviking/yii2-oauth2 "~v1.1.1"

```

or add

```
"bnviking/yii2-oauth2": "~v1.1.1"

```

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

Config
------

[](#config)

```
'components' => [
    ...
    'bnvOAuth2'=> [
        'class' => \bnviking\oauth2\OAuth2Config::class,
        'clientUrlName' => 'client',
        'authUrl' => 'auth2/authorize',
        'clients' => [
            'discord'=>[
                'class'=> \bnviking\oauth2\clients\Discord::class,
                'clientID' => 'discord_client_id',
                'clientSecret' => 'discord_client_secret',
            ],
            'vkontakte'=>[
                'class'=> \bnviking\oauth2\clients\VKontakte::class,
                'clientID' => 'vkontakte_client_id',
                'clientSecret' => 'vkontakte_client_secret',
            ],
            'yandex'=>[
                'class'=> \bnviking\oauth2\clients\Yandex::class,
                'clientID' => 'yandex_client_id',
                'clientSecret' => 'yandex_client_secret',
            ],
            'mailru'=>[
                'class'=> \bnviking\oauth2\clients\MailRu::class,
                'clientID' => 'mailru_client_id',
                'clientSecret' => 'mailru_client_secret',
            ],
            'trovo'=>[
                'class'=> \bnviking\oauth2\clients\Trovo::class,
                'clientID' => 'trovo_client_id',
                'clientSecret' => 'trovo_client_secret',
            ],
            'twitch'=>[
                'class'=> \bnviking\oauth2\clients\Twitch::class,
                'clientID' => 'twitch_client_id',
                'clientSecret' => 'twitch_client_secret',
            ],
        ]
    ]
    ...
]
```

Create link to OAuth2
---------------------

[](#create-link-to-oauth2)

> - clientUrlName - name param Client ID for create URL
> - authUrl - ``/``

Redirect URL for your APP: **

Use in action
-------------

[](#use-in-action)

```

```

 [![Widget OAuth2.0 example](./widget.png)](./widget.png)

###### Additional html options for widget

[](#additional-html-options-for-widget)

```
'components' => [
    ...
     'bnvOAuth2'=> [
        'clients' => [
            ...
            'htmlOptions' => ['class'=>'my-css-class']
        ]
     ]
]
```

Custom widget example
---------------------

[](#custom-widget-example)

> All clients can be retrieved using the ClientManager

`widget.php`

```
