0

我按照 Sf4 沙箱安装 JWT Auth,但我仍然有这个响应:

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.
[Thu Jan  3 18:39:27 2019] 127.0.0.1:48564 [404]: /login_check

当我尝试这个命令时:

curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"email":"johndoe@test.fr","password":"test"}'

这是我的 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]

这是我的 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 }

我正在使用 PHP7.2 和Symfony 4.2。有人知道如何纠正这个错误吗?

谢谢,

阿德里安

4

2 回答 2

0

在 security.yaml中将登录防火墙放在首位

firewalls:
    login:
       #login context

    #other firewalls
于 2019-01-04T11:29:08.163 回答
0

在 security.yaml 中,删除

main:
    anonymous: true
于 2019-01-17T02:16:57.727 回答