Argument #1 ($userProvider) must be of type ... UserProviderInterface

899 Views Asked by At

I have installed the Sonata User Bundle using the instructions. The process of loading user fixtures and clearing the cache work fine, but once I try to access an area requiring authentication in the browser, I get this exception:

Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider::__construct(): Argument #1 ($userProvider) must be of type Symfony\Component\Security\Core\User\UserProviderInterface, Sonata\UserBundle\Entity\UserManager given, called in /var/www/var/cache/dev/ContainerKw1JrEb/srcApp_KernelDevDebugContainer.php on line 7756

The exception is traced to:

vendor/symfony/security-core/Authentication/Provider/DaoAuthenticationProvider.php (line 35)

... which is a constructor that looks like this:

class DaoAuthenticationProvider extends UserAuthenticationProvider
{
    private $encoderFactory;
    private $userProvider;
    public function __construct(UserProviderInterface $userProvider, UserCheckerInterface $userChecker, string $providerKey, EncoderFactoryInterface $encoderFactory, bool $hideUserNotFoundExceptions = true)
    {
        parent::__construct($userChecker, $providerKey, $hideUserNotFoundExceptions);
        $this->encoderFactory = $encoderFactory;
        $this->userProvider = $userProvider;
        ...

My fos_user.yaml file looks like this:

fos_user:
  db_driver: orm
  firewall_name: main
  user_class: App\Entity\User
  group:
    group_class:   FOS\UserBundle\Entity\Group
    group_manager: sonata.user.orm.group_manager

  from_email:
    address: "[email protected]"
    sender_name: "No Reply"

  service:
    user_manager: sonata.user.orm.user_manager

Does anyone know what I need to do in order to get things working?

(Note: I checked for duplicates, but while there are a couple questions that look similar, the error messages differ slightly from the one I'm seeing. Please double-check the wording instead of just immediately asking that this question be closed, as people are likely to google for my exception's specific wording.)

1

There are 1 best solutions below

0
Robbert van den Bogerd On BEST ANSWER

Which version of symfony are you using? The FosUserBundle is not compatible with symfony5, also the Sonata User bundle is ONLY compatible with symfony 4.4, which is almost end-of-life. I think you should walk a different path. Setting up your own user manager is not as difficult as you might think. See the recommendations on https://github.com/FriendsOfSymfony/FOSUserBundle#maintenance-status

This tutorial might also help you in the right direction: https://symfonycasts.com/screencast/symfony5-security