【发布时间】:2019-12-21 19:04:40
【问题描述】:
我正在 PHP / Symfony 4.0 中编写一个 REST API 端点,我想使用基本身份验证,并使用密码为空的内存用户。当我尝试使用这些凭据调用端点时,我收到一个 BadCredentialsException 说“提供的密码不能为空”。
DaoAuthenticationProvider 似乎正在引发异常。
如何在 Symfony 中配置基本身份验证以允许空密码?
上下文:我正在为一个简单的端点设置基本身份验证,该端点将用作集成字段的 Prismic 自定义 API(请参阅https://user-guides.prismic.io/en/articles/1401183-connect-to-a-custom-api)。 Prismic 对此支持基本身份验证,您可以在其中输入将用作用户名的密钥,而密码将留空。
我正在使用 PHP / Symfony 4.0 编写此内容,并且我一直在关注 https://symfony.com/doc/current/security.html 的文档。
我的 config/packages/security.yaml 文件是:
security:
firewalls:
secured_area:
pattern: ^/api/my-endpoint
http_basic: ~
security: true
main:
security: false
providers:
in_memory:
memory:
users:
test:
password: ''
encoders:
Symfony\Component\Security\Core\User\User: plaintext
我的日志中的完整错误消息是:
用户的基本身份验证失败。 {"username":"test","exception":"[object] (Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): Bad credentials. at my-project\vendor\symfony\security\Core \Authentication\Provider\UserAuthenticationProvider.php:84, Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): 提供的密码不能为空。在 my-project\vendor\symfony\security\Core\Authentication\ Provider\DaoAuthenticationProvider.php:54)"} []
【问题讨论】:
-
只是为了澄清:您使用哪个 Symfony 版本?您是否尝试将其更新到 4.3 的最新版本?
-
Symfony 4.0。我尝试更新到 Symfony 4.3,但我得到了同样的异常。
标签: php symfony symfony4 basic-authentication symfony-security