filsh/yii2-oauth2-server

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

yuxiuhong opened this issue · 5 comments

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

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()
            ],
        ]);
    }
}

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

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

OK, Thank you!

you can close the ticket!