You can optionally pass a user loader as second argument to the UserBadge. This callable receives the $userIdentifier and must return a UserInterface object (otherwise a UserNotFoundException is thrown):
return new Passport(
new UserBadge($email, function ($userIdentifier) {
return $this->userRepository->findOneBy(['email' => $userIdentifier]);
}),
$credentials
);
Problem is that UserNotFoundException is not thrown, but AuthenticationServiceException is instead, which results in weird message when logging in "Authentication request could not be processed due to a system problem." instead of simple "Invalid credentials".
For example this works as expected:
return new Passport(
new UserBadge($email),
$credentials
);
How to reproduce
Create custom login authenticator and compare different behaviour between new UserBadge when no $userLoader is provided and when $userLoader is provided while trying to login with non-existing user email address.
Possible Solution
No response
Additional Context
Symfony\Component\Security\Core\Exception\AuthenticationServiceException: The user provider must return a UserInterface object, "null" given. in ...\vendor\symfony\security-http\Authenticator\Passport\Badge\UserBadge.php:69
The text was updated successfully, but these errors were encountered:
In my humble opinion, it comes from Symfony\Component\Security\Http\Authenticator\Passport\Badge.
The getUser method will call the custom callback given to the second argument of the Badge class. If the custom callback returns "null" (which is "normal" when the request doesn't match to any user), it throws an AuthenticationServiceException because null is not an instanceof UserInterface … (see here)
I think it should throws an UserNotFoundException if null is found.
Symfony version(s) affected
5.4
Description
In documentation here https://symfony.com/doc/5.4/security/custom_authenticator.html is written:
Problem is that UserNotFoundException is not thrown, but AuthenticationServiceException is instead, which results in weird message when logging in "Authentication request could not be processed due to a system problem." instead of simple "Invalid credentials".
For example this works as expected:
How to reproduce
Create custom login authenticator and compare different behaviour between new UserBadge when no $userLoader is provided and when $userLoader is provided while trying to login with non-existing user email address.
Possible Solution
No response
Additional Context
The text was updated successfully, but these errors were encountered: