Closed adrolter closed 2 months ago
Honestly, no idea 🤷. The setup looks to good to me.
Would be interesting where that AccessDeniedException
is coming from and how the security looked like in that moment.
Did you have a look at your Symfony profiler's Events panel ?
Do you have any Security related listeners that could interfere ?
Things that would listent to CheckPassportEvent::class
, AuthenticationTokenCreatedEvent::class
, LoginSuccessEvent::class
, AuthenticationEvents::*
and so on...
Thank you for the replies! I hadn't had time to poke at this for a couple of weeks, but after taking another look it was indeed a problem with my legacy (PHP Bridge) sessions, as I had suspected.
I was calling \session_start()
too late...often in the supports()
of my custom authenticators, which was after Firewall\ContextListener->authenticate()
. This was fine so long as my custom authenticators were the only ones in the mix, but obviously couldn't work with this bundle because it reads from TokenStorage
before any of that happens.
To resolve it I made a kernel.request
listener with higher priority than the firewall's, in which I can initialize my legacy sessions.
Bundle version: 7.5.0 Symfony version: 7.1.2 PHP version: 8.3.9
Description
I'm attempting to setup 2FA via email after a username/password-based form login. I can get to the 2FA code form and see that I'm partially authenticated with a
TwoFactorToken
, and refreshing the page reliably loads the form again and again without loss of the token, but any submission of the form (with either the correct or incorrect code) drops the token and leads to a redirect back to the start of the process (my login form at/login
).I followed the "Not logged in after completing two-factor authentication" part of the troubleshooting guide:
Disabling the
two_factor
section ofsecurity.yaml
results in a functioning login process without 2FA.Inspecting the security token when the 2FA form page loads reveals a

TwoFactorToken
which encapsulates aUsernamePasswordToken
that does not have anauthenticated
property (according to my inspection with Xdebug):Upon submission to

/2fa_check
, I'm redirected back to the start. Here are the Authenticator debug messages from that request which ends up in that 302 back to/login
:Additional Context
packages/scheb_2fa.yaml
:routes/scheb_2fa.yaml
:I have multiple firewalls, but I'm only trying to use the bundle on
main
at the moment...packages/security.yaml
:I have a bit of a funky session setup at the moment due to legacy code, but I tried disabling all that and reverting to default session settings to see if that would fix 2FA, but it didnt...
packages/framework.yaml
:Any ideas or more troubleshooting steps would be very welcome. Thank you!