通过带有Apigility的DB进行HTTP基本身份验证

时间:2017-02-05 15:43:29

标签: zend-framework basic-authentication apigility

我一直在尝试启用HTTP Basic Authentification,使用我的PSQL DB中的信息存储而不是htpasswd文件,但我似乎无法在Apigility中找到这样做的方法。

据我所知,我需要创建一个实现ResolverInterface的适配器并返回一个“已解决”的方法(在需要验证之后)。

但是我不知道如何处理它以便成为HTTP Basic Authentification使用的适配器。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

实现此目的的一种方法是在配置中覆盖ZF \ MvcAuth \ Authentication \ AuthHttpAdapter的工厂:

'service_manager' => array(
    'factories' => array(
        'ZF\MvcAuth\Authentication\AuthHttpAdapter' => 'MyNamespace\MyHttpAdapterFactory',
    )
);

在您的工厂中,您可以将解析器设置为基本解析器:

public function createService(ServiceLocatorInterface $services)
{
    $httpAdapter = parent::createService($services); // Assuming you are extending from DefaultHttpAdapterFactory
    $myResolver = $serviceManager->get('MyResolver');
    $httpAdapter->setBasicResolver($myResolver);

    return $httpAdapter;
}
相关问题