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

Symfony API : Unable to find the controller for path "/auth/2fa_check". The route is wrongly configured. #263

Open
Kokuga opened this issue Jan 28, 2025 · 1 comment
Labels

Comments

@Kokuga
Copy link

Kokuga commented Jan 28, 2025

Bundle version: 7.6
Symfony version: 6.4.11
PHP version: 8.3

Description

Hey, i'm having a probleme with the 2fa. I want to do a 2fa login in Vuejs and Symfony.
I want to implement a 2fa with email.

When logging in, i get a mail with the code inside but when comes the moment where i want to validate the code with the route /auth/2fa_check, i get this error : Unable to find the controller for path "/auth/2fa_check". The route is wrongly configured.

I did exactly the same as the documentation provided.

Additional Context
Here is my configurations:
Security.yml

security:
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        login: 
            pattern: ^/auth
            stateless: false
            jwt: ~
            json_login:
                check_path: /auth/login
                success_handler: handler.authentication_success_handler
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            two_factor:
                post_only: false
                auth_form_path: 2fa_login
                check_path: 2fa_login_check
                prepare_on_login: true
                prepare_on_access_denied: true
                auth_code_parameter_name: _auth_code
                authentication_required_handler: handler.two_factor_authentication_required_handler
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: handler.two_factor_authentication_failure_handler

        api:
            pattern: ^/api
            stateless: true
            entry_point: jwt
            jwt: ~
            refresh_jwt:
                check_path: /api/token/refresh


    access_control:
        - { path: ^/api/(token/refresh), roles: PUBLIC_ACCESS }
        - { path: ^/api/forgot_password, role: PUBLIC_ACCESS }
        - { path: ^/api/docs, roles: PUBLIC_ACCESS }
        - { path: ^/api/register, roles: PUBLIC_ACCESS }
        - { path: ^/auth, roles: PUBLIC_ACCESS }
        - { path: ^/auth/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS }
        - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
        - { path: ^/documents, roles: IS_AUTHENTICATED_FULLY }


when@test:
    security:
        password_hashers:

            Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface:
                algorithm: auto
                cost: 4
                time_cost: 3
                memory_cost: 10

config/packages/scheb_2fa.yml

# See the configuration reference at https://symfony.com/bundles/SchebTwoFactorBundle/6.x/configuration.html
scheb_two_factor:
    security_tokens:
        - Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
        - Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken
        - Lexik\Bundle\JWTAuthenticationBundle\Security\Authenticator\Token\JWTPostAuthenticationToken
        - Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token\JWTUserToken
    email:
        enabled: true                 
        mailer: mail.two_fa_service 
        sender_email: '[email protected]'   
        sender_name: 'test'        
        digits: 6                     
        template: security/2fa_form.html.twig 

config/routes/scheb_2fa.yml

2fa_login:
    path: /auth/2fa
    defaults:
        _controller: "scheb_two_factor.form_controller::form"

2fa_login_check:
    path: /auth/2fa_check

Here is what I send from vue

POST /auth/2fa_check
{
    "_auth_code": 123456
}

Thanks for your answers.

@Kokuga Kokuga added the Support label Jan 28, 2025
@scheb
Copy link
Owner

scheb commented Jan 28, 2025

What's the security token that you see on that POST request? (You should see that in the profiler, make sure to pick the right request). If it's not a TwoFactorToken, then that's the problem. Then you've likely "lost" the session.

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

No branches or pull requests

2 participants