title: Symfony 4 "code": 401, "message": "Invalid credentials." jwt authentication error
body: <p>I'm trying to make a jwt authentication with Symfony 4  </p>
  
  <p>I configured my project as follow  </p>
  
  <pre class="lang-yaml prettyprint-override"><code>// security.yaml 
  
  security:
      encoders:
          App\Entity\User:
              algorithm: auto
  
      # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
      providers:
          # used to reload user from session &amp; other features (e.g. switch_user)
          app_user_provider:
              entity:
                  class: App\Entity\User
                  property: username
      firewalls:
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
  
          login:
              pattern:  ^/api/login
              stateless: true
              anonymous: true
              json_login:
                  check_path:               /api/login_check
                  success_handler:          lexik_jwt_authentication.handler.authentication_success
                  failure_handler:          lexik_jwt_authentication.handler.authentication_failure
  
          api:
                  pattern:   ^/api
                  stateless: true
                  guard:
                      authenticators:
                          - lexik_jwt_authentication.jwt_token_authenticator
  
          main:
              anonymous: true
              provider: app_user_provider
  
              # activate different ways to authenticate
              # https://symfony.com/doc/current/security.html#firewalls-authentication
  
              # https://symfony.com/doc/current/security/impersonating_user.html
              # switch_user: true
  
      # Easy way to control access for large sections of your site
      # Note: Only the *first* access control that matches will be used
      access_control:
          - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
          - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
  </code></pre>
  
  <pre class="lang-yaml prettyprint-override"><code>// routes.yaml
  
  api_login_check:
      path: /api/login_check
  </code></pre>
  
  <pre><code>// .env
  
  ###&gt; nelmio/cors-bundle ###
  CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
  ###&lt; nelmio/cors-bundle ###
  
  ###&gt; lexik/jwt-authentication-bundle ###
  JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
  JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
  JWT_PASSPHRASE=d96058cb8b34d7061148465f3d286ae4
  ###&lt; lexik/jwt-authentication-bundle ###
  </code></pre>
  
  <pre class="lang-yaml prettyprint-override"><code>//lexik_jwt_authentication.yaml
  
  lexik_jwt_authentication:
      secret_key:       '%kernel.project_dir%/config/jwt/private.pem' # required for token creation
      public_key:       '%kernel.project_dir%/config/jwt/public.pem'  # required for token verification
      pass_phrase:      'd96058cb8b34d7061148465f3d286ae4'
      token_ttl:        3600
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>//UserRepository.php
  
  class UserRepository extends ServiceEntityRepository
  {
      public function __construct(ManagerRegistry $registry)
      {
          parent::__construct($registry, User::class);
      }
  
      // /**
      //  * @return User[] Returns an array of User objects
      //  */
      /*
      public function findByExampleField($value)
      {
          return $this-&gt;createQueryBuilder('u')
              -&gt;andWhere('u.exampleField = :val')
              -&gt;setParameter('val', $value)
              -&gt;orderBy('u.id', 'ASC')
              -&gt;setMaxResults(10)
              -&gt;getQuery()
              -&gt;getResult()
          ;
      }
      */
  
      /*
      public function findOneBySomeField($value): ?User
      {
          return $this-&gt;createQueryBuilder('u')
              -&gt;andWhere('u.exampleField = :val')
              -&gt;setParameter('val', $value)
              -&gt;getQuery()
              -&gt;getOneOrNullResult()
          ;
      }
      */
  </code></pre>
  
  <p>and I generated 2 keys (private and public) in a folder named Jwt inside the config folder.</p>
  
  <p>Now according to a documentation that I followed if I run:</p>
  
  <pre class="lang-sh prettyprint-override"><code>curl -X POST -H "Content-Type: application/json" http://localhost/api/login_check -d '{"username":"johndoe","password":"test"}'
  </code></pre>
  
  <p>I'll be able to get a token like that in return </p>
  
  <pre><code>{
     "token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0MzQ3Mjc1MzYsInVzZXJuYW1lIjoia29ybGVvbiIsImlhdCI6IjE0MzQ2NDExMzYifQ.nh0L_wuJy6ZKIQWh6OrW5hdLkviTs1_bau2GqYdDCB0Yqy_RplkFghsuqMpsFls8zKEErdX5TYCOR7muX0aQvQxGQ4mpBkvMDhJ4-pE4ct2obeMTr_s4X8nC00rBYPofrOONUOR4utbzvbd4d2xT_tj4TdR_0tsr91Y7VskCRFnoXAnNT-qQb7ci7HIBTbutb9zVStOFejrb4aLbr7Fl4byeIEYgp2Gd7gY"
  }
  </code></pre>
  
  <p>but instead I got this error:</p>
  
  <pre><code>{"error":{"code":400,"message":"Bad Request","exception":[{"message":"Invalid JSON.","class":"Symfony\\Component\\HttpKernel\\Exception\\B [...]
  </code></pre>
  
  <p>and when I used postman 
  and send</p>
  
  <pre><code>{
    "username": "test",
    "password": "test"
  }`
  url : `http://localhost:8000/api/login_check`
  method : `POST`
  </code></pre>
  
  <p>I got this error
   <code>{
      "code": 401,
      "message": "Invalid credentials."
  }</code></p>
  
  <p>could you please tell me why i got this error and how to fix it 
  <a href="https://i.stack.imgur.com/LuER6.jpg" rel="nofollow noreferrer">Postman</a></p>