Symfony - lexik jwt authentication - 找不到令牌



我在后端使用 simfony 3.3 的 lexik_jwt_authentication。我的问题是,当我尝试登录时,响应是:

{
    "code": 401,
    "message": "JWT Token not found"
}

此外,如果我浏览我的网站,捆绑包告诉我在所有页面中提供一个令牌。这没关系,但是当我在"login_check"中检查登录名时,这不应该发生,在这种情况下,我无法生成令牌。我做错了什么?

谢谢

config.yml:

lexik_jwt_authentication:
    private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
    public_key_path:  '%kernel.root_dir%/../var/jwt/public.pem'
    pass_phrase:      '%jwt_key_pass_phrase%'
    token_ttl:        3600
fos_user:
   db_driver: orm
   firewall_name: main
   user_class: ApiBundleEntityFosUser
   from_email:
      address: "%mailer_user%"
      sender_name: "%mailer_user%"

security.yml:

    firewalls:        
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            fr3d_ldap:  ~
            security: false
            form_login:
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false
            logout: true
            stateless: true
            anonymous: true
        api:
            pattern: ^/
            stateless: true
            provider: fos_userbundle
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator
        main:
            pattern: ^/
            fr3d_ldap:  ~
            form_login:
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false
            logout: true
            stateless: true
            anonymous: true
在您的

security.yml中,您需要指定登录access_control不像这样完全进行身份验证:

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/,       roles: IS_AUTHENTICATED_FULLY }

最新更新