Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not accept MailerInterface type hinting on Guard Authenticator #2785

Open
BernardA opened this issue Apr 14, 2018 · 5 comments
Open

does not accept MailerInterface type hinting on Guard Authenticator #2785

BernardA opened this issue Apr 14, 2018 · 5 comments

Comments

@BernardA
Copy link

Symfony FOSUserBundle versions:

2.1.1 on Symfony 4.0.4

Description of the problem including expected versus actual behavior:

On Guard Authenticator, attempting to include FOS's services for, among other things, re-send e-mail confirmation in case user attempts to login but has still not been enabled on db.

It does accept UserManagerInterface and TokenGeneratorInterface, but for MailerInterface it throws the following error:

Cannot autowire service "app.form_login_authenticator": argument "$mailer" of method "App\Security\FormLoginA
uthenticator::__construct()" references interface "FOS\UserBundle\Mailer\MailerInterface" but no such service
exists. You should maybe alias this interface to one of these existing services: "fos_user.mailer.default",
"fos_user.mailer.twig_swift", "fos_user.mailer.noop". Did you create a class that implements this interface?

The mentioned mailer services ( default, twig_swift, noop ) do not show on the list of available services, if one tries to go that route.

Not sure what is particular about the MailerInterface as compared to the other 2 FOS's interfaces on that script.

Note that the sending of email on the 'regular' ON REGISTRATION SUCCESS event through FOSUserBundle works fine.

Here is the authenticator:

`
namespace App\Security;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Exception\DisabledException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Mailer\MailerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface;
use App\Entity\Login;

class FormLoginAuthenticator extends AbstractGuardAuthenticator
{
    const ALLOWED_FAILED_ALL = 100;
    const ALLOWED_FAILED_USER = 10;
    private $userManager;
    private $mailer;
    private $tokenGenerator;
    private $container;

    public function __construct(ContainerInterface $container, UserManagerInterface $userManager, MailerInterface $mailer, TokenGeneratorInterface $tokenGenerator)
{        
    $this->userManager = $userManager;
    $this->container = $container;
    $this->mailer = $mailer;
    $this->tokenGenerator = $tokenGenerator;
}
   ......

`

@MichaelBrock
Copy link

BernardA, did you ever figure this out? I'm experiencing the exact same problem, getting the exact same error, but only for MailerInterface.

@BernardA
Copy link
Author

Sorry, but I'm afraid not, and as you can see the so called 'friends of symfony' seem to be busy somewhere else.

@Tomsgu
Copy link

Tomsgu commented Aug 21, 2018

I don’t have the code near now, but it seems that there is no alias for MailerInterface. You should inject the Mailer class not MailerInterface or you can add a new alias.

Btw. Friends of Symfony are never busy.

@MichaelBrock
Copy link

Tomsgu, that makes sense and I'm pretty confident that path leads to success. I just ran into a similar situation with a different service.

@xabbuh
Copy link
Member

xabbuh commented Aug 21, 2018

Under some circumstances a fos_user.mailer alias is set which refers to the mailer to be used (see https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/DependencyInjection/FOSUserExtension.php#L133). It could make sense to also register an alias here whose name is the FQCN of the MailerInterface. But as long as that is not part of the bundle you do that yourself as @Tomsgu suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants