You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi, I just created REST API and want to use yii2-admin as control for API access, is it possible to do it with this module??
I tried to add AccessControl component to API controller, it recognize the user is logged in, but not recognize the user assignment and keep showing me 403 response, even the user has right assignment for the URL..
but if I remove the access part from controller behavior, it works but no restriction to user assignment..
<?php
namespace api\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use yii\filters\Cors;
use yii\filters\VerbFilter;
use yii\filters\auth\HttpBearerAuth;
use mdm\admin\components\AccessControl;
/**
* DataSatuan Controller API
*/
class DataSatuanController extends ActiveController
{
public $modelClass = 'common\models\DataSatuan';
public function behaviors()
{
$behaviors = parent::behaviors();
$auth = $behaviors['authenticator'];
$auth['authMethods'] = [
HttpBearerAuth::class
];
unset($behaviors['authenticator']);
$behaviors['cors'] = [
'class' => Cors::class
];
$behaviors['authenticator'] = $auth;
$behaviors['access'] = [
'class' => AccessControl::className(),
];
return $behaviors;
}
public function actions()
{
$actions = parent::actions();
unset($actions['index']);
return $actions;
}
public function actionIndex(){
$activeData = new \yii\data\ActiveDataProvider([
'query' => \common\models\DataSatuan::find(),
// 'pagination' => false
// 'pagination' => ['pageSize' => 0]
// 'pagination' => ['defaultPageSize' => 40]
]);
return $activeData;
}
}
and this is the response from cURL :
{
"name": "Forbidden",
"message": "You are not allowed to perform this action.",
"code": 0,
"status": 403,
"type": "yii\\web\\ForbiddenHttpException"
}
is there anything wrong or anything I can do to make this module work in REST API??
The text was updated successfully, but these errors were encountered:
biladina
changed the title
Access issue with REST API
Access and Assignment issue with REST API
Aug 8, 2021
hi, I just created REST API and want to use yii2-admin as control for API access, is it possible to do it with this module??
I tried to add
AccessControl
component to API controller, it recognize the user is logged in, but not recognize the user assignment and keep showing me403
response, even the user has rightassignment
for the URL..but if I remove the
access
part from controllerbehavior
, it works but no restriction to user assignment..this is my config,
main.php
:this is
index.php
:and this is the controller :
and this is the response from cURL :
is there anything wrong or anything I can do to make this module work in REST API??
The text was updated successfully, but these errors were encountered: