| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?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 = parent::behaviors();
- $behaviors['authenticator'] = [
- 'class' => CompositeAuth::class,
- 'authMethods' => [
- HttpBasicAuth::class,
- 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
- }
- }
|