-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Description
Symfony version(s) affected
6.2
Description
The new ability to programmatically login does not work if at least one authenticator is not declared in config.
How to reproduce
- Create auth controller with $security (Symfony\Bundle\SecurityBundle\Security) and u user repo.
- Fetch any profile from repo and use $security->login($user).
- Catch exception "Call to a member function getProvidedServices() on null" in vendor/symfony/security-bundle/Security.php:122.
Possible Solution
I "solved" the problem by adding an empty authenticator to the project.
security:
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
app_user_provider:
entity:
class: App\Entity\User
property: username
# used to reload user from session & other features (e.g. switch_user)
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: false
provider: app_user_provider
custom_authenticators:
- App\Security\EmptyAuthenticator
Additional Context
No response