AuthController.php 605 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace common\rest;
  3. use yii\filters\auth\HttpBearerAuth;
  4. use yii\filters\auth\QueryParamAuth;
  5. /**
  6. * @var $usuario \common\models\Usuario
  7. */
  8. class AuthController extends JsonController {
  9. public $usuario;
  10. public function behaviors() {
  11. $behavior = parent::behaviors();
  12. $behavior["authenticator"]["authMethods"] = [
  13. QueryParamAuth::className(),
  14. HttpBearerAuth::className()
  15. ];
  16. return $behavior;
  17. }
  18. public function beforeAction($action) {
  19. parent::beforeAction($action);
  20. $this->usuario = \Yii::$app->getUser()->getIdentity();
  21. return true;
  22. }
  23. }