使用自定义用户提供程序的Symfony lexik jwt身份验证错误:“在null上调用成员函数getUsername()”

时间:2018-10-16 09:55:32

标签: php symfony jwt lexikjwtauthbundle

我将Lexik jwt authenticationcustom user provider结合起来,然后运行LexikJWT Sandbox usage guide

一切正常,除了本指南的最后一步。

$ curl -H "256tokencharacters" http://localhost:8000/api导致以下错误:

{
    "code": 500,
    "message": "Call to a member function getUsername() on null"
}

getUsername()函数来自the suggested Lexik api() function in my DefaultController

这是由于$ this-> getUser()返回null,这是由于 $this->container->get('security.token_storage')返回null。

因此由于某种原因,此“ security.token_storage”保持为空。 我不确定这是什么意思。

security.yaml

security:
  encoders:
    App\Security\User\WebserviceUser: plaintext

  role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

  providers:
    webservice:
      id: App\Security\User\WebserviceUserProvider
    jwt:
      lexik_jwt:
        class: App\Security\User\WebserviceUser

  firewalls:
    dev:
      pattern: ^/(_(profiler|wdt)|css|images|js)/
      security: false

    login:
      pattern:  ^/api/login
      stateless: true
      anonymous: true
      provider: webservice
      json_login:
        check_path: /api/login_check
        success_handler: lexik_jwt_authentication.handler.authentication_success
        failure_handler: lexik_jwt_authentication.handler.authentication_failure

    client_list:
      pattern:  ^/api/client/active
      stateless: true
      anonymous: true

    secured_area:
      pattern: ^/api/
      provider: webservice
      stateless: true
      guard:
        authenticators:
        - lexik_jwt_authentication.jwt_token_authenticator

  access_control:
    - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
    - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/api/client/active, roles: IS_AUTHENTICATED_ANONYMOUSLY }

0 个答案:

没有答案