LexikJWTAuthenticationBundle: Another Unable to find the controller for path "/login_check". The route is wrongly configured

So obviously, there is a lot of issues already with this error message. Only a few has been addressed.

I feel I have been through all the issues now, and I have attempted many different configurations to see if I could get a working result, with no luck.

Error message

Unable to find the controller for path "/login_check". The route is wrongly configured
security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt
    role_hierarchy:
        ROLE_READER: ROLE_USER
        ROLE_ADMIN: ROLE_READER
    providers:
        entity_provider:
            entity:
                class: App\Entity\User
                property: username
    firewalls:
        # Removed main entirely as suggested in a different issue, with no luck. Also attempted to move dev
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        login:
            pattern:  ^/login
            stateless: true
            anonymous: true
            json_login:
                check_path: /login_check
                # Attempted with specific username_path and password_path config as well as without
                username_path: username
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
        register:
            pattern:  ^/register
            stateless: true
            anonymous: true
        api:
            pattern:   ^/v1
            stateless: true
            anonymous: true
            provider: entity_provider
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/v1, roles: IS_AUTHENTICATED_FULLY }
        - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }

Creating users with /register works fine. However, all users created through register returns the error message regarding a missing controller. However, that only occures if the username/password credentials is correct, if I type in a wrong password, it returns bad credentials as expected.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17

Most upvoted comments

Try to change order of your firewalls, example : 1 - dev 2 - login 3 - api 4 - main

You are probably not sending a valid JSON request. The Content-Type header must beapplication/json (not obvious using postman)

In addition to configure the header as @chalasr says, send your credentials in JSON:

image

I have the exact problem when trying to invoke request in Postman with wrong Body type (x-www-form-urlencoded vs raw)…does something like this from command line also producing the error ?

curl -X POST -H "Content-Type: application/json" http://yourhost:yourport/api/login_check -d '{"username":"admin","password":"xxxxxxx"}'

I just removed main part of the configuration, and that workes for me ` firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false

main:

anonymous: lazy

provider: app_user_provider

    login:
        pattern:  ^/login
        stateless: true
        anonymous: true
        json_login:
            check_path: /login_check
            success_handler: lexik_jwt_authentication.handler.authentication_success
            failure_handler: lexik_jwt_authentication.handler.authentication_failure

    register:
        pattern:  ^/register
        stateless: true
        anonymous: true

    api:
        pattern:  ^/api
        stateless: true
        anonymous: false
        provider: app_user_provider
        guard:
            authenticators:
                - lexik_jwt_authentication.jwt_token_authenticator
        # activate different ways to authenticate
        # https://symfony.com/doc/current/security.html#firewalls-authentication

        # https://symfony.com/doc/current/security/impersonating_user.html`

It worked for me using:

curl -k -X POST -H "Content-Type: application/json" -d "{\"username\":\"user", \"password\":\"user\"}" https://127.0.0.1:8000/api/login_check

Try to change order of your firewalls, example : 1 - dev 2 - login 3 - api 4 - main

You are a life saver. Why does it have to be so hard. Seriously, this needs to be documented. Wasted hours and hours on something that should not have taken some minutes!!!

Try to change order of your firewalls, example : 1 - dev 2 - login 3 - api 4 - main

i work for me thanks

@bamjad Pull requests are more than welcome to document such common troubles.