I am authenticating on my base controller using HTTPBearerAuth
public function behaviors()
{
$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'authMethods' => [
HttpBearerAuth::className(),
],
];
return $behaviors;
}
On my UserController extending base controller and using AccessControl to allow guest users to access login.
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access'] = [
'class' => AccessControl::className(),
'only' => ['login', 'logout', 'signup'],
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
];
$behaviors['verbs'] = [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
];
return $behaviors;
}
When I try to access login without authentication details, I get
{
"name": "Unauthorized",
"message": "You are requesting with an invalid credential.",
"code": 0,
"status": 401,
"type": "yii\web\UnauthorizedHttpException"
}
Unauthorized 401. With authentication details, I get
{
"name": "Forbidden",
"message": "You are not allowed to perform this action.",
"code": 0,
"status": 403,
"type": "yii\web\ForbiddenHttpException"
}
Why am I getting this? I also asked the question on StackOverflow.