2017 © Pedro Peláez
 

yii2-extension yii2-oauth2-server

OAuth2 Server for PHP

image

gowravshekar/yii2-oauth2-server

OAuth2 Server for PHP

  • Friday, December 18, 2015
  • by gowravshekar
  • Repository
  • 1 Watchers
  • 1 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 163 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

yii2-oauth2-server

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

Installation

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

Either run, (*3)

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

or add, (*4)

"filsh/yii2-oauth2-server": "~2.0"

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

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

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

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

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/, (*9)

add url rule to urlManager, (*10)

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

Usage

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

use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;
use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use filsh\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()
            ],
        ]);
    }
}

To get access token (js example):, (*12)

var url = window.location.host + "/oauth2/token";
var data = {
    'grant_type':'password',
    'username':'<some login from your user table>',
    'password':'<real pass>',
    'client_id':'testclient',
    'client_secret':'testpass'
};
//ajax POST `data` to `url` here
//

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

The Versions

18/12 2015

2.0.1.x-dev

2.0.1.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

18/12 2015

dev-use-jwt-access-token-patch

dev-use-jwt-access-token-patch https://github.com/filsh/yii2-oauth2-server

OAuth2 Server for PHP

  Sources   Download

MIT

The Requires

 

by Igor Maliy

extension oauth module yii oauth2

16/12 2015

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

19/06 2015

2.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