【问题标题】:How to get the Basic HTTP Authentication working for an Apigility application?如何使基本 HTTP 身份验证适用于 Apigility 应用程序?
【发布时间】:2015-05-12 12:31:08
【问题描述】:

我按照Apigility docu 所述设置基本身份验证(文档不再是最新的,但主要步骤保持不变)。因此,我创建了一个users.htpasswd 文件并添加了一个身份验证适配器。我的/config/autoload/local.php 已更新并获得适配器配置:

return array(
    ...
    'zf-mvc-auth' => array(
        'authentication' => array(
            'adapters' => array(
                'dummy basic auth' => array(
                    'adapter' => 'ZF\\MvcAuth\\Authentication\\HttpAdapter',
                    'options' => array(
                        'accept_schemes' => array(
                            0 => 'basic',
                        ),
                        'realm' => 'Dummy Realm',
                        'htpasswd' => 'data/users.htpasswd',
                    ),
                ),
            ),
        ),
    ),
);

到目前为止一切顺利:

Test: I sent a `GET` request got the data just like before the auth setup.
Expected: `200 OK`
Result: `200 OK`
OK

然后我去Apigility Admin Backend -> My API -> My Rest Service -> Authorization 并标记了方法和端点,我想要求授权。

Test: I sent a new request without credentials / authentication token.
Expected: `403 Forbidden`
Result: `403 Forbidden`
OK

Test: I sent another request with wrong credentials / authentication token.
Expected: `401 Unauthorized`
Result: `403 Forbidden`
FAIL

Test: I sent a request with correct credentials / authentication token.
Expected: `200 OK`
Result: `403 Forbidden`
FAIL

我做错了什么? 如何使基本 HTTP 身份验证正常工作?

【问题讨论】:

    标签: php authentication zend-framework2 basic-authentication laminas-api-tools


    【解决方案1】:

    从 Apigility 的新版本开始(不确定是哪一个,但大于 1.0),可以创建多个 Auth 适配器并将每个 API 关联到不同的 Auth 适配器。

    如果您创建了一个身份验证适配器(顶部的身份验证 -> 适配器 -> 新适配器),您将拥有您设置的 HTTP Basic 的适配器名称。记下来。

    然后转到您的 API(与包含您的资源的模块名称匹配的 API,而不是单个资源)。在该屏幕上,您会在左上角看到带有下拉菜单的“身份验证”。

    在下拉列表中,选择您创建的身份验证适配器并保存您的选择。现在,您在该 API 下的资源应该会根据您是否经过身份验证正确响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-08
      • 2018-04-19
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多