0

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

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

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

谢谢

配置.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: ApiBundle\Entity\FosUser
   from_email:
      address: "%mailer_user%"
      sender_name: "%mailer_user%"

安全性.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
4

1 回答 1

0

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

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/,       roles: IS_AUTHENTICATED_FULLY }
于 2018-02-02T08:03:42.023 回答