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.
Could you provide your routes.yaml ? Also what version of symfony are you using? Do you have a github project that reproduces this problem? Is this during the dev environment?
@kemicofa
register:
path: /register
controller: App\Controller\AuthController::register
methods: POST
api:
path: /v1
controller: App\Controller\AuthController::api
login:
path: /login
controller: App\Controller\AuthController::login
Done several new attempts though. At this moment, I am manually validating logins and I removed the /login_check. Manually creating tokens also.
Using Symfony 4.
Environment: Dev as well as prod.
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"}'
Same here, with Symfony 3.4
You are probably not sending a valid JSON request. The Content-Type header must beapplication/json (not obvious using postman)
Closing due to the lack of feedback.
@cbourgois thanks god, you saved me
Yep! The error changed in the new versions of Symfony.
It's not an Error 400 Bad Request anymore but 404 when the request is empty.
Be carrefull, some MOOC are not updated...
I have spent 1h on that ahah!
In addition to configure the header as @chalasr says, send your credentials in JSON:

I just removed main part of the configuration, and that workes for me
` firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
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
I had the same error and I try to use the solutions given in this issue but no result. To resolve this I return an empty array, at the beginning the function did nothing, for the getRoles function of my Entity (I do not take into account the role management in my project) and I send a JSON type for my informations (username and password) - before I used the TEXT type and finally it's works :)
public function getRoles()
{
return [];
}
Try to change order of your firewalls, example :
1 - dev
2 - login
3 - api
4 - main
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!!!
@bamjad Pull requests are more than welcome to document such common troubles.
Most helpful comment
You are probably not sending a valid JSON request. The
Content-Typeheader must beapplication/json(not obvious using postman)