无法使用Symfony 3.4上的LexikJWTAuthenticationBundle进行身份验证

无法使用Symfony 3.4上的LexikJWTAuthenticationBundle进行身份验证,symfony,http-status-code-401,symfony-3.4,lexikjwtauthbundle,jwt-auth,Symfony,Http Status Code 401,Symfony 3.4,Lexikjwtauthbundle,Jwt Auth,在我的带有FOSUserBundle(2.0.2)的Symfony(3.4.24)项目中,我安装了LexikJWTAuthenticationBundle(2.6.3) 我安装并配置了github页面上所说的一切。 运行以下建议的curl命令时 curl -X POST -H "Content-Type: application/json" http://127.0.0.1:8000/app_dev.php/api/login_check -d "{\"username\":\"johndoe\

在我的带有FOSUserBundle(2.0.2)的Symfony(3.4.24)项目中,我安装了LexikJWTAuthenticationBundle(2.6.3)

我安装并配置了github页面上所说的一切。 运行以下建议的curl命令时

curl -X POST -H "Content-Type: application/json" http://127.0.0.1:8000/app_dev.php/api/login_check -d "{\"username\":\"johndoe\",\"password\":\"test\"}"
我总是得到下面的回答。 对于不存在的用户或错误的密码以及具有正确密码的现有有效用户,响应是相同的

{"code":401,"message":"Bad credentials"}
我的设置如下所示:

config.yml: (如果我需要添加更多详细信息,请告知我)

security.yml:

    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    ...

    providers:
        in_memory:
            memory: ~
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # Login for Lexik Json Web Token Authentication
        login:
            pattern:  ^/api/login
            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
                require_previous_session: false

        # API for Lexik Json Web Token Authentication
        api:
            pattern:   ^/api
            stateless: true
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

        main:
            pattern: ^/
            form_login:
                provider:                       fos_userbundle
                check_path:                     fos_user_security_check
                login_path:                     fos_user_security_login
                csrf_token_generator:           security.csrf.token_manager
                default_target_path:            fos_user_profile_show
                always_use_default_target_path: true
            logout:
                  path:                         fos_user_security_logout
                  target:                       default_loged_out_target
            logout_on_user_change: true
            anonymous:    true
            switch_user:
                role:       ROLE_ADMIN
                provider:   fos_userbundle
            remember_me:
                secret:   '%secret%'
                lifetime: 15552000
                path:     /

    access_control:
        ...
        - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
...
api_login_check:
    path: /api/login_check
路由。yml:

    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    ...

    providers:
        in_memory:
            memory: ~
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        # Login for Lexik Json Web Token Authentication
        login:
            pattern:  ^/api/login
            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
                require_previous_session: false

        # API for Lexik Json Web Token Authentication
        api:
            pattern:   ^/api
            stateless: true
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

        main:
            pattern: ^/
            form_login:
                provider:                       fos_userbundle
                check_path:                     fos_user_security_check
                login_path:                     fos_user_security_login
                csrf_token_generator:           security.csrf.token_manager
                default_target_path:            fos_user_profile_show
                always_use_default_target_path: true
            logout:
                  path:                         fos_user_security_logout
                  target:                       default_loged_out_target
            logout_on_user_change: true
            anonymous:    true
            switch_user:
                role:       ROLE_ADMIN
                provider:   fos_userbundle
            remember_me:
                secret:   '%secret%'
                lifetime: 15552000
                path:     /

    access_control:
        ...
        - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
...
api_login_check:
    path: /api/login_check
就像我说的,我总是得到这样的回答:

{"code":401,"message":"Bad credentials"}

有人能指出正确的方向来解决这个问题吗?

一切似乎都很好,但我怀疑,既然您有两个提供商(内存和fos\u userbundle),Lexik JWT会从其中哪一个查找凭据?如果不使用内存中的提供程序,应尝试将其删除。

谢谢。好的,这改变了“sth”^^我现在得到一个500错误和一个Symfony错误html页面,声明“无法从给定配置创建签名JWT”。这就是。。。不同,但我仍然不知道该怎么办:-)错误消息足够清楚,您应该检查您的配置。也许,重新生成您的SSH密钥。我不太清楚(重新生成密钥没有帮助),但这确实是另一个问题。然而,您知道如何使用in_内存提供程序来解决最初的问题吗?重新生成密钥实际上就解决了这个问题。我重新生成了它们,但放入了一个错误的文件夹。。。我不会再评论了:D