Hello,
I followed the Sf4 sandbox to install JWT Auth, but still I have this response :
2019-01-03T18:39:27+01:00 [info] Matched route "login_check".
2019-01-03T18:39:27+01:00 [info] Populated the TokenStorage with an anonymous Token.
2019-01-03T18:39:27+01:00 [warning] Unable to look for the controller as the "_controller" parameter is missing.
2019-01-03T18:39:27+01:00 [critical] Uncaught Exception: Unable to find the controller for path "/login_check". The route is wrongly configured.
When I try this command :
curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"email":"[email protected]","password":"test"}'
Here is my routes.yaml :
index:
path: /
controller: App\Controller\DefaultController::index
register:
path: /register
controller: App\Controller\DefaultController::register
methods: POST
api:
path: /api
controller: App\Controller\DefaultController::api
login_check:
path: /login_check
methods: [POST]
And here is my security.yaml :
security:
encoders:
App\Entity\User:
algorithm: bcrypt
cost: 12
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
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
username_path: email
password_path: password
api:
pattern: ^/
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
I am using PHP7.2 and Symfony 4.2.
Does someone know how to correct this error ?
Thanks,
Adrien
I can confirm same issue on php 7.2 symfony 4.2.
Still trying to figure this out.
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 }
@adrienlefebvre92 try removing section:
main:
anonymous: true
this was the problem in my case
@adrienlefebvre92 if you're using symfony serve then ensure you're using https
curl -X POST -H "Content-Type: application/json" https://localhost:8000/login_check -d '{"email":"[email protected]","password":"test"}' -vvv -k
If that doesn't work add the options -vvv -k to follow redirections.
curl -X POST -H "Content-Type: application/json" https://localhost:8000/login_check -d '{"email":"[email protected]","password":"test"}' -vvv -k
Alternatively, you can run symfony server in http:
symfony serve --allow-http=true
While I'm not getting the error via the curl request, I am getting a similar error when running tests as mentioned in #610
Here is my test.log
[2019-01-29 21:30:24] request.INFO: Matched route "api_admin_login". {"route":"api_admin_login","route_parameters":{"_route":"api_admin_login"},"request_uri":"http://localhost/api/admin/login_check","method":"POST"} []
[2019-01-29 21:30:24] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-01-29 21:30:24] request.WARNING: Unable to look for the controller as the "_controller" parameter is missing. [] []
Though when it matches the route, "request_uri":"http://localhost/api/admin/login_check" looks fishy.
Got around it by moving the 'main' block after all other firewalls.
main:
anonymous: true
I had the same issue at some point but remember fixing it. I simply forgot the HTTP header content-type: application/json in the request headers.
You need to make sure that you are sending a POST request with HEADER 'content-type': 'application/json' and the data must be in JSON
Closing as explained. Please open a PR if you think you can improve the documentation.
I have the same issue and if I remove the part anonymous: true I get an 502 Bad Gateway error.
Try to change order of your firewalls, example :
1 - dev
2 - login
3 - api
4 - main
Most helpful comment
@adrienlefebvre92 try removing section:
this was the problem in my case