Closed danielrhodeswarp closed 1 year ago
Yup, this issue was due to my JavaScript front-end not catching, and re-sending to /2fa_check, the intermediary "logged in but still need 2FA" cookie that Scheb 2FA and Symfony dutifully send back to me when I pass the first traditional sign-in attempt.
Although I am very interested in any ways to send, catch and re-send the intermediary token that aren't cookies :-D
So don't mind me any more, nothing to see here folks.
It's a very interesting bundle, many thanks.
So I guess this can be closed now
Bundle version: 5.13.2 Symfony version: 4.4.49 PHP version: 7.4.33 Using authenticators (
enable_authenticator_manager: true
): YES / NODescription
Trying to integrate Scheb 2FA "on top of" my existing Lexik JWT integration. This is for an app split into a Symfony API back-end and a JavaScript front-end.
Lexik itself is working standardly and hasn't been customised. I POST email and password credentials to the endpoint and this either fails or works. The front-end knows what to do in either case.
I'm following this page of the official bundle docs to complete my integration: https://symfony.com/bundles/SchebTwoFactorBundle/current/api.html
I am able to override Lexik's regular success handler to send a packet like {"login": "success": "2fa_complete": false} to the front-end. This triggers the "You need to complete 2FA" form.
My issue after this is that, when submitting the user's one-time code to the configured /2fa_check endpoint for Scheb 2FA, I hit a 401 error: "Tried to perform two-factor authentication, but two-factor authentication is not in progress".
What causes this error is the $token being null in TwoFactorListener::authenticate():
Is this something dopey and obvious that I've missed? Or is it something more low-level and sinister? I'm not super knowledgeable about Symfony under the hood but I'm thinking things like:
[] Do I need to store the temporary token ("valid user but not completed 2FA") on the front-end and send that with the request to /2fa_check ?
[] Should my Symfony be doing the above automatically (cookies?) but my configuration is borked ?
It seems like my subsequent request to check the 2FA code isn't being recognised as belonging to the just-authenticated user.
Additional Context
SECURITY.YAML