2017 © Pedro Peláez
 

yii2-extension yii2-oauth2-server

OAuth2 Server for PHP, a fork of filsh/yii2-oauth2-server

image

davidxu/yii2-oauth2-server

OAuth2 Server for PHP, a fork of filsh/yii2-oauth2-server

  • Wednesday, December 13, 2017
  • by davidxuuts
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 162 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Extension for Yii2 providing an oAuth 2 server

Forked from https://github.com/davidxu/yii2-oauth2-server Uses parts of https://github.com/samdark/yii2-league-oauth2-server, (*1)

Also inspired by https://github.com/chervand/yii2-oauth2-server, (*2)

Install

Add this to your composer.json:, (*3)


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

Usage

Step 1

You need a few things:, (*4)

  • 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:, (*5)

    • 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:, (*6)

    <?php
      /**
     * {@inheritdoc}
     */
    public static function findIdentityByAccessToken($token, $type = null) {
        return static::find()
            ->where(['user.status'=>static::STATUS_ACTIVE])
            ->leftJoin('{{%oauth_access_token}}', '`user`.`id` = `{{%oauth_access_token}}`.`user_id`')
            ->andWhere(['{{%oauth_access_token}}.identifier' => $token])
            ->one();
    }
    

    And then pass the User class as the property $userRepository in the configuration array as below., (*7)

  • An SSH key pair. See https://oauth2.thephpleague.com/installation/, (*8)

$ openssl genrsa -out private.key 2048

```bash $ openssl rsa -in private.key -pubout -out public.key, (*9)


Make sure the file rights are 600 or 660 for the generated key files. - An encryption key (just a random string) - The migrations ```bash $ php yii migrate --migrationPath=@vendor/davidxu/yii2-oauth2-server/migrations

Step 2

Add it as a yii2 module:, (*10)

<?php
$config = [
 'modules' => [
        'oauth2' => [
            'class' => davidxu\oauth2\Module::class,
            'userRepository' => \app\models\User::class,
            'privateKey' => '@common/data/keys/private.key',
            'publicKey' => '@common/data/keys/public.key',
            'encryptionKey' => 'put-a-nice-random-string-here',
        ],
    ],
];
?>

Also add the module to your application bootstrap:, (*11)

...
'bootstrap' => ['log','api.v1',...,'oauth2'],
...

Configuration

There's not a lot of configuration yet. Maybe the types of grants available will be dynamic someday., (*12)

Access control (Guarding API calls)

Check Client Credentials

Because the Client Credentials method creates access tokens that are not linked to a specific user, it uses a different filter to check the validity of the token., (*13)

Add the davidxu\oauth2\components\filters\CheckClientCredentials to your behaviors to validate Client Credential access keys., (*14)

Other auth flows

Add the davidxu\oauth2\components\authMethods\HttpBearerAuth to your behaviors, for example:, (*15)

<?php
 public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => HttpBearerAuth::class,
        ];
        $behaviors['contentNegotiator'] = [
            'class' => 'yii\filters\ContentNegotiator',
            'formats' => [
                'application/json' => Response::FORMAT_JSON,
            ]
        ];

        return $behaviors;
    }

Usage with with yiisoft/yii2-authclient (or similar Authorization Code Grant clients)

Create a custom client, with the following URLs: - authorize URL: <domain>/oauth2/authorize - token URL: <domain>/oauth2/token/create, (*16)

The Versions

13/12 2017

v2.0.1.x-dev

2.0.1.9999999-dev https://github.com/davidxuuts/yii2-oauth2-server

OAuth2 Server for PHP, a fork of filsh/yii2-oauth2-server

  Sources   Download

MIT

The Requires

 

by Igor Maliy
by David Xu

extension oauth module yii oauth2

13/12 2017

dev-master

9999999-dev https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

13/12 2017

v2.0.5

2.0.5.0 https://github.com/davidxuuts/yii2-oauth2-server

OAuth2 Server for PHP, a fork of filsh/yii2-oauth2-server

  Sources   Download

MIT

The Requires

 

by Igor Maliy
by David Xu

extension oauth module yii oauth2

24/11 2016

2.0.3

2.0.3.0 https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

24/11 2016

v2.0.3.x-dev

2.0.3.9999999-dev https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

24/11 2016

2.0.2

2.0.2.0 https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

19/06 2015

v2.0.x-dev

2.0.9999999.9999999-dev https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

19/06 2015

2.0.1

2.0.1.0 https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

17/06 2015

v2.0.0

2.0.0.0 https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

10/04 2015

v1.0

1.0.0.0 https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension yii widget