Search code examples
symfony4lexikjwtauthbundle

Symfony 4.2: LexikJWT: Unable to find the controller for path "/api/login_check". The route is wrongly configured


welcome in my first stack post :)

Issue on php 7.2 symfony 4.2. I cant figure this out for two days.

I got the following logs when trying to access via POST /api/login_check with header Content-Type application/json.

2019-01-10T23:33:11+01:00 [info] Matched route "api_login_check".
2019-01-10T23:33:11+01:00 [info] Populated the TokenStorage with an anonymous Token.
2019-01-10T23:33:11+01:00 [warning] Unable to look for the controller as the "_controller" parameter is missing.
2019-01-10T23:33:11+01:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Unable to find the controller for path "/api/login_check". The route is wrongly configured." at /home/mateusz/Workspace/api-platform/vendor/symfony/http-kernel/HttpKernel.php line 134
[Thu Jan 10 23:33:11 2019] 127.0.0.1:56616 [404]: /api/login_check

My config:

security:
    encoders:
        App\Entity\User: bcrypt
    providers:
        database:
            entity:
                class: App\Entity\User
                property: username
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true
        api:
            pattern: ^/api
            stateless: true
            anonymous: true
            json_login:
                check_path: /api/login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

    access_control:
        - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }

The jwt.yaml in /routes is defined as: api_login_check: path: /api/login_check

Help would be much appreciated :)


Solution

  • Remove or put at bottom:

    main:
        anonymous: true
    

    Because of that entry, the router never get your api firewall.