| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace app\modules\api;
- use app\models\user\User;
- use yii\filters\auth\CompositeAuth;
- use yii\filters\auth\HttpBasicAuth;
- use yii\filters\auth\HttpBearerAuth;
- use yii\filters\auth\QueryParamAuth;
- /**
- * api module definition class
- */
- class Module extends \yii\base\Module
- {
- /**
- * {@inheritdoc}
- */
- public $controllerNamespace = 'app\modules\api\controllers';
- public function behaviors()
- {
- $behaviors = parent::behaviors();
- /*$behaviors['authenticator'] = [
- 'class' => CompositeAuth::class,
- 'authMethods' => [
- [
- 'class' =>HttpBasicAuth::class,
- 'auth' => function ($username, $password) {
- $user = User::find()->where(['username' => $username])->one();
- if ($user->verifyPassword($password)) {
- return $user;
- }
- return null;
- },
- ],
- HttpBearerAuth::class,
- QueryParamAuth::class,
- ],
- ];*/
- $behaviors['authenticator'] = [
- 'class' => HttpBearerAuth::class,
- ];
- return $behaviors;
- }
- /**
- * {@inheritdoc}
- */
- public function init()
- {
- parent::init();
- \Yii::$app->user->enableSession = false;
- // custom initialization code goes here
- }
- }
|