【问题标题】:PHP - REST - Slim Framework HTTP Basic Auth - 401 UnauthorizedPHP - REST - Slim 框架 HTTP 基本身份验证 - 401 未经授权
【发布时间】:2017-09-05 14:36:20
【问题描述】:

我想在我的 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'];
[....]
}

【问题讨论】:

  • 你能展示一下 curl 请求如何访问你的 api 吗?比如:$ curl --include --user root:root123 --request POST example.com

标签: php rest authentication frameworks slim


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-08-24
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    相关资源
    最近更新 更多