PHP - REST - Slim Framework HTTP Basic Auth - 401未经授权

时间:2017-09-02 19:48:52

标签: php rest authentication frameworks slim

我想在我的REST API(PHP - Slim Framework)中实现HTTP-Basic-Authentication。 如果我向受保护的URL发送POST请求,它会显示一个“需要身份验证”窗口,我可以在其中填写我的凭据,但我总是收到错误 401未经授权

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
"path" => "/api/v1/video/add",
"realm" => "Protected",
"secure" => false,
"users" => [
    "root" => "root123",
    "user" => "user"
]
]));

路线:

$app->post('/api/v1/video/add', function (Request $request, Response $response) {

// get POST-Variables
$allPostVars = $request->getParsedBody(); 
$id = $allPostVars['id'];
[....]
}

1 个答案:

答案 0 :(得分:1)

如果您需要实施基本身份验证,请使用https://github.com/tuupola/slim-basic-auth