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

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

niolab/yii2-oauth2-server
=========================

Oauth2 server

v1.3.0(2y ago)1288↓100%1MITPHPPHP &gt;=8.0|&gt;=8.2

Since Aug 20Pushed 1y ago1 watchersCompare

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

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

Extension for Yii2 providing an oAuth 2 server
==============================================

[](#extension-for-yii2-providing-an-oauth-2-server)

Uses parts of

Also inspired by

Install
-------

[](#install)

Add this to your `composer.json`:

```
"niolab/yii2-oauth2-server": "~1.0"
```

Usage
-----

[](#usage)

### Step 1

[](#step-1)

You need a few things:

- A UserRepository for this module to get its users from. The easiest is to take your existing `User` class, and make sure it also implements the following interfaces:

    - `yii\web\IdentityInterface`
    - `League\OAuth2\Server\Entities\UserEntityInterface`
    - `League\OAuth2\Server\Repositories\UserRepositoryInterface`
        - Make sure to *validate* the user in `UserRepositoryInterface::getUserEntityByUserCredentials()`

    Also make sure to implement `findIdentityByAccessToken()`, it's used by `NIOLAB\oauth2\components\authMethods\HttpBearerAuth` to authenticate the user by access token. Example:

    ```
