【发布时间】:2017-10-27 01:50:36
【问题描述】:
我在 xampp 上设置了以下虚拟主机名:reporting.dev
public function userIsAuthenticated(\ApiTester $I)
{
$I->amGoingTo('Check Authentication works');
// i've tried both of these ways to authenticate
$I->amHttpAuthenticated('my_email', 'my_password');
$I->haveHttpHeader('Authorization', 'Basic super_long_token');
$I->sendGET(Url::toRoute('/api/reports', true));
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->deleteHeader('Authorization');
}
以下请求在邮递员http://reporting.dev/api/reports 中使用基本身份验证标头和上述测试中的相同令牌。
这是我的 api 套件配置:
class_name: ApiTester
modules:
enabled:
- REST:
depends: PhpBrowser
#url: /api/
part: Json
- Yii2:
part: [orm, fixtures]
configFile: 'config/web.php'
我正在使用 Yii2,如果我从我的 api 控制器中删除将身份验证确定为基本身份验证的行为函数,我会得到 200 响应和预期的 json。
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'except' => [],
];
return $behaviors;
}
所以我不确定我还能在这里做什么或为什么我没有通过身份验证
【问题讨论】:
-
amHttpAuthenticated 的 PhpBrowser 方法(以及使用 PhpBrowser 时的 REST)设置 Authorization 标头,因此使用 haveHttpHeader 设置它是多余的,可能会导致问题。
-
我删除了有关冲突模块的 cmets,因为您启用了正确的部分。
-
@Naktibalda 那么你有什么建议,我已经分别尝试了它们,我得到了 401s
-
echo base64_decode('token');并检查您是否收到相同的电子邮件和密码
标签: yii2 codeception