AuthController.php 614 B

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