2017 © Pedro Peláez
 

yii2-extension yii2oauth2server

OAuth2 Server for PHP

image

cncap/yii2oauth2server

OAuth2 Server for PHP

  • Wednesday, July 6, 2016
  • by cncap
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

This repository checkout from v2.0 branch of (https://github.com/Filsh/yii2-oauth2-server), (*1)


yii2-oauth2-server's readme:

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php), (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist filsh/yii2-oauth2-server "*"

or add, (*5)

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

to the require section of your composer.json., (*6)

To use this extension, simply add the following code in your application configuration:, (*7)

'oauth2' => [
    'class' => 'cncap\yii2\oauth2server\Module',
    'options' => [
        'token_param_name' => 'accessToken',
        'access_lifetime' => 3600 * 24
    ],
    'storageMap' => [
        'user_credentials' => 'common\models\User'
    ],
    '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
        ]
    ],
]

common\models\User - user model implementing an interface \OAuth2\Storage\UserCredentialsInterface, so the oauth2 credentials data stored in user table, (*8)

The next step your shold run migration, (*9)

yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations

this migration create the oauth2 database scheme and insert test user credentials testclient:testpass for http://fake/, (*10)

add url rule to urlManager, (*11)

'urlManager' => [
    'rules' => [
        'POST oauth2/<action:\w+>' => 'oauth2/default/<action>',
        ...
    ]
]

Usage

To use this extension, simply add the behaviors for your base controller:, (*12)

use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use cncap\yii2\oauth2server\filters\ErrorToExceptionFilter;
use cncap\yii2\oauth2server\filters\auth\CompositeAuth;

class Controller extends \yii\rest\Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' => CompositeAuth::className(),
                'authMethods' => [
                    ['class' => HttpBearerAuth::className()],
                    ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken'],
                ]
            ],
            'exceptionFilter' => [
                'class' => ErrorToExceptionFilter::className()
            ],
        ]);
    }
}

For more, see https://github.com/bshaffer/oauth2-server-php, (*13)

The Versions

06/07 2016

dev-master

9999999-dev https://github.com/cncap/yii2OAuthServer

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy
by Captain Vmax

extension oauth module yii oauth2