1

Symfony 5.4, api-platform 2.6

I tried to follow the Extending Authenticator example from Github (https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/6-extending-jwt-authenticator.md#extending-authenticator), but now I got the error saying "request body is empty" when I enable the custom authenticator in security.yaml. If I disable this authenticator then error gone.

here is the security.yaml

security:
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        #app_user_provider:
        #    id: App\Security\UserProvider
        jwt:
            lexik_jwt:
                class: App\Security\User
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        login:
            stateless: true
            pattern: ^/login

        main:
            stateless: true
            provider: jwt
            # If disable the following custom authenticator, then the error gone. tried jwt: ~, but got same error.
            jwt:
                authenticator: app.fp_jwt_authenticator

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    # IS_AUTHENTICATED_ANONYMOUSLY, IS_AUTHENTICATED_FULLY
    access_control:
        # - { path: ^/admin, roles: ROLE_ADMIN }
        # - { path: ^/profile, roles: ROLE_USER }
        - { path: ^/docs, roles: PUBLIC_ACCESS }
        - { path: ^/login, roles:  PUBLIC_ACCESS}
        - { path: ^/, roles: ROLE_USER }

here is the returned error.

{
  "type": "https://tools.ietf.org/html/rfc2616#section-10",
  "title": "An error occurred",
  "detail": "Request body is empty.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/srv/api/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 77,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "HttpKernel",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "->",
      "function": "handle",
      "file": "/srv/api/vendor/symfony/http-kernel/Kernel.php",
      "line": 202,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpFoundation\\Request"
        ],
        [
          "integer",
          1
        ],
        [
          "boolean",
          true
        ]
      ]
    },
    {
      "namespace": "Symfony\\Component\\HttpKernel",
      "short_class": "Kernel",
      "class": "Symfony\\Component\\HttpKernel\\Kernel",
      "type": "->",
      "function": "handle",
      "file": "/srv/api/public/index.php",
      "line": 20,
      "args": [
        [
          "object",
          "Symfony\\Component\\HttpFoundation\\Request"
        ]
      ]
    }
  ]
}
bluemoonJ
  • 11
  • 2

0 Answers0