scheb/two-factor-bundle

Google Authenticator does not load in DI container on Symfony 4.3.8

pavlakis opened this issue · 11 comments

Bundle version: 4.8.0
Symfony version: 4.3.8

Description

In Symfony 4, the Google Authenticator scheb_two_factor.security.google_authenticator is not loaded in the DI container.

To Reproduce

Steps to reproduce the behavior:

  1. Install bundle 4
  2. Use the flex recipe
  3. Run bin/console debug:container to see if it is loaded
  4. Create the action as shown in Documentation and see the autowire error
scheb commented

Do you have the "Google Authenticator" authentication activated in the bundle configuration?

https://github.com/scheb/two-factor-bundle/blob/master/Resources/doc/configuration.md

# config/packages/scheb_two_factor.yaml
scheb_two_factor:
    google:
        enabled: true                  # If Google Authenticator should be enabled, default false

Yes. As per the docs.
This is my setup:

scheb_two_factor:
    security_tokens:
        - Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
    google:
        enabled: true
scheb commented

Do you see any other "scheb_two_factor.*" services in the DI?

And please try to clear the cache.

Probably it was just cache as it is picking it up now. Thanks.

Should probably turn this into a support ticket.

For some reason 2FA does not kick in after a successful authentication.
Any guidance on that?

        main:
            context: web
            anonymous: ~
            two_factor:
                auth_form_path: 2fa_login
                check_path: 2fa_login_check

Thanks @scheb
The troubleshooting has been very helpful.

However, I'm stuck on 4 where
Scheb\TwoFactorBundle\Security\TwoFactor\Handler\TwoFactorProviderHandler::getActiveTwoFactorProviders() is not being called.

  • I've not set a Whitelist
  • I've cleared all cookies
  • Tried with different and incognito browsers
scheb commented

What kind of token class do you see after login? If it's not identical to Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken, you have to add the token class to the configuration.

It is the Symfony\Component\Security\Core\Authentication\Token\PostAuthenticationGuardToken

I have added it to security_tokens configuration, but it has made no difference.

scheb commented

Since you went through the troubleshooting guide, I assume that this is true:

  1. On login, do you reach the end (return statement) of method Scheb\TwoFactorBundle\Security\Authentication\Provider\AuthenticationProviderDecorator::authenticate()?

... so you should definitely end up here:

https://github.com/scheb/two-factor-bundle/blob/master/Security/TwoFactor/Handler/TwoFactorProviderHandler.php#L49

I'd suggest you further dig down (with xdebug or alike) what's happening in this call:

https://github.com/scheb/two-factor-bundle/blob/master/Security/Authentication/Provider/AuthenticationProviderDecorator.php#L90

@scheb Thanks for your guidance and patience on this.
I had made a mistake on copy/paste and was using Symfony\Component\Security\Core\Authentication\Token\PostAuthenticationGuardToken instead of the correct path of Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken.

Stepping through with Xdebug was really easy to find that.

scheb commented

Cool, glad you've been able to make it work :)