filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

I get the access_token,but,how to use it? #117

Closed yuxiuhong closed 7 years ago

yuxiuhong commented 7 years ago

How to write the protected function?and,How the proctected function extend the oauth2-server?

mtangoo commented 7 years ago

Seems you didn't read the Readme file. Do that and its right there

Taken from the same file

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()
            ],
        ]);
    }
}
yuxiuhong commented 7 years ago

Thanks for your advice. If I want to write my api and I hope others use it,what should I do?

mtangoo commented 7 years ago

Please take time to read the Guide on that topic. It explains everything you have asked and more http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html

yuxiuhong commented 7 years ago

OK, Thank you!

mtangoo commented 7 years ago

you can close the ticket!