dsp15140275697 2019-01-04 07:38
浏览 76
已采纳

使用Sf4进行Lexik JWT身份验证:未捕获异常:无法找到路径“/ login_check”的控制器

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

When I try this command :

curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"email":"johndoe@test.fr","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

  • 写回答

2条回答 默认 最新

  • duancaiyi7567 2019-01-04 11:29
    关注

    In security.yaml put login firewall at the first place

    firewalls:
        login:
           #login context
    
        #other firewalls
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求恶意流量检测系统搭建教程( C++ python C)
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys