gpt4 book ai didi

php - Slim Basic Auth 的身份验证失败

转载 作者:行者123 更新时间:2023-12-05 05:23:39 25 4
gpt4 key购买 nike

所以我正在使用 tuupola/slim-basic-auth 和 Slim。我想我正确地遵循了这些步骤,但有些东西无法正常工作。

这是我的 index.php

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"users" => [
"user" => "Carla",
"password" => "123"
],
"realm" => "Protected",
"secure" => false,
"path" => '/',
"error" => function ($request, $response, $arguments) {
$data = [];
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response->write(json_encode($data, JSON_UNESCAPED_SLASHES));
}
]));

我正在使用 Postman 对其进行测试,我使用我的凭据填充身份验证,然后我得到了 401 未授权。知道我做错了什么吗?

提前致谢。

编辑:

我终于明白哪里不对了。原来它缺少这一行:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

.htaccess 文件上。

感谢您的帮助:)

最佳答案

如果您想要的用户名是 Carla 和密码 123 然后像这样初始化中间件:

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"users" => [
"Carla" => "123"
]
]));

关于php - Slim Basic Auth 的身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37140472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com