【问题标题】:Symfony - lexik jwt authentication - token not foundSymfony - lexik jwt 身份验证 - 找不到令牌
【发布时间】:2018-02-02 07:53:18
【问题描述】:

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

{
    "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: ApiBundle\Entity\FosUser
   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

【问题讨论】:

标签: symfony lexikjwtauthbundle


【解决方案1】:

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

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

【讨论】:

  • 您好,谢谢您的回答。我试过了,但没有任何改变。
猜你喜欢
  • 2022-07-14
  • 2016-05-17
  • 2017-10-22
  • 1970-01-01
  • 2020-07-07
  • 2019-08-04
  • 2019-01-22
  • 2020-08-23
  • 1970-01-01
相关资源
最近更新 更多