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

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

davidxu/yii2-oauth2-server
==========================

Oauth2 server

1.0.2(1y ago)05MITPHPPHP &gt;=8.0|&gt;=8.2

Since Aug 14Pushed 1y agoCompare

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

READMEChangelogDependencies (3)Versions (4)Used By (0)

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

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

Forked from Uses parts of

Also inspired by

Install
-------

[](#install)

Add this to your `composer.json`:

```
"davidxu/yii2-oauth2-server": "*"
```

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 `davidxu\oauth2\components\authMethods\HttpBearerAuth` to authenticate the user by access token. Example:

    ```
