I am writing a REST API endpoint in PHP / Symfony 4.0 and I want to use basic authentication, with an in-memory user whose password is blank. When I try to call the endpoint with these credentials, I get a BadCredentialsException
saying 'The presented password cannot be empty'.
It appears that the exception is being thrown by the DaoAuthenticationProvider
.
How can I configure basic authentication in Symfony to allow an empty password?
Context: I'm setting up basic authentication for a simple endpoint that will be used as a Prismic custom API for an integration field (see https://user-guides.prismic.io/en/articles/1401183-connect-to-a-custom-api). Prismic supports basic authentication for this, where you enter a key which will be used as the username, and the password will be left blank.
I am writing this in PHP / Symfony 4.0, and I have been following the docs at https://symfony.com/doc/current/security.html .
My config/packages/security.yaml file is:
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
The full error message in my logs is:
Basic authentication failed for user. {"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): The presented password cannot be empty. at my-project\vendor\symfony\security\Core\Authentication\Provider\DaoAuthenticationProvider.php:54)"} []