<?php
namespace app\controllers;
use \JsonRpc2\Controller;
use app\components\JwtAccessControl;
class ApiController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => JwtAccessControl::className(),
'except' => ['login'],
],
];
}
public function actionLogin() {
return 'login';
}
public function actionUpdate() {
return 'update';
}
}
<?php
namespace app\components;
use Yii;
use yii\base\ActionFilter;
class JwtAccessControl extends ActionFilter
{
public function beforeAction($action)
{
if (true)
throw new \JsonRpc2\extensions\AuthException('Missing auth', \JsonRpc2\extensions\AuthException::MISSING_AUTH);
return parent::beforeAction($action);
}
public function afterAction($action, $result)
{
return parent::afterAction($action, $result);
}
}
Now it works just like this