title: 401 JWT Token not found
body: <p>I provided two versions of the <code>security.yaml</code> file. The second version according to <a href="https://api-platform.com/docs/core/jwt" rel="noreferrer">API Platform</a> documentation. <a href="https://api-platform.com/docs/core/jwt" rel="noreferrer">API Platform</a> sends to the <a href="http://symfony.com/doc/current/security/custom_provider.html" rel="noreferrer">creation a custom user provider</a>. For the second option <code>security.yaml</code> recommended at API Platform docs, I need to create two additional files. I did not attach them to the topic, but will do it if necessary.</p>
  
  <p>But I think that problem it is in JWT.</p>
  
  <p><strong>Environment:</strong></p>
  
  <ul>
  <li>node v8.9.4</li>
  <li>chrome 64.0.3282.119</li>
  <li>Ubuntu 16.04</li>
  <li>axios version: 0.16.2</li>
  <li>Vue.js 2.4.2</li>
  <li>vue-axios 2.0.2</li>
  <li>api-platform/api-pack: 1.0</li>
  <li>Symfony 4.0.4</li>
  </ul>
  
  <h2><strong>User.php</strong></h2>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Security\Core\User\UserInterface;
  
  /**
   * @ORM\Table(name="app_users")
   * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
   */
  class User implements UserInterface, \Serializable
  {
      /**
       * @ORM\Column(type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=25, unique=true)
       */
      private $username;
  
      /**
       * @ORM\Column(type="string", length=64)
       */
      private $password;
  
      /**
       * @ORM\Column(type="string", length=60, unique=true)
       */
      private $email;
  
      /**
       * @ORM\Column(name="is_active", type="boolean")
       */
      private $isActive;
  
      public function __construct() // add $username
      {
          $this-&gt;isActive = true;
      }
  
      public function getUsername()
      {
          return $this-&gt;username;
      }
  
      public function getSalt()
      {
          // you *may* need a real salt depending on your encoder
          // see section on salt below
          return null;
      }
  
      public function getPassword()
      {
          return $this-&gt;password;
      }
  
      public function getRoles()
      {
          return array('ROLE_ADMIN');
      }
  
      public function eraseCredentials()
      {
      }
  
      /** @see \Serializable::serialize() */
      public function serialize()
      {
          return serialize(array(
              $this-&gt;id,
              $this-&gt;username,
              $this-&gt;password,
              // see section on salt below
              // $this-&gt;salt,
          ));
      }
  
      /** @see \Serializable::unserialize() */
      public function unserialize($serialized)
      {
          list (
              $this-&gt;id,
              $this-&gt;username,
              $this-&gt;password,
              // see section on salt below
              // $this-&gt;salt
          ) = unserialize($serialized);
      }
  }
  </code></pre>
  
  <h2><strong>First option security.yaml</strong></h2>
  
  <pre><code>security:
  
      encoders:
          App\Entity\User:
              algorithm: bcrypt
  
      providers:
  
          our_db_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
              form_login:
                  check_path:               /api/login_check
                  success_handler:          lexik_jwt_authentication.handler.authentication_success
                  failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                  require_previous_session: false
  
          api:
              pattern:   ^/api
              stateless: true
              provider: our_db_provider
              guard:
                  authenticators:
                      - lexik_jwt_authentication.jwt_token_authenticator
  
      access_control:
          - { path: ^/admin, roles: ROLE_ADMIN }
          - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
          - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
  </code></pre>
  
  <h2><strong>Second option security.yaml</strong></h2>
  
  <pre><code>security:
  
      encoders:
          App\Entity\User:
              algorithm: bcrypt
  
          App\Security\User\WebserviceUser: bcrypt
  
      providers:
  
          our_db_provider:
              entity:
                  class: App\Entity\User
                  property: username
  
          webservice:
              id: App\Security\User\WebserviceUserProvider
  
      firewalls:
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
  
          login:
              pattern:  ^/api/login
              stateless: true
              anonymous: true
              provider: webservice
              form_login:
                  check_path:               /api/login_check
                  success_handler:          lexik_jwt_authentication.handler.authentication_success
                  failure_handler:          lexik_jwt_authentication.handler.authentication_failure
                  require_previous_session: false
  
          api:
              pattern:   ^/api
              stateless: true
              provider: our_db_provider
              guard:
                  authenticators:
                      - lexik_jwt_authentication.jwt_token_authenticator
      access_control:
          - { path: ^/admin, roles: ROLE_ADMIN }
          - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
          - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }
  </code></pre>
  
  <h2><strong>Headers</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/Ysfab.png" alt="headers"></p>
  
  <h2><strong>curl</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/kO5sk.png" alt="curl"></p>
  
  <h2><strong>curl with headers</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/jNu9P.png" alt="curl with headers"></p>
  
  <h2><strong>In browser</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/oJZHm.png" alt="in browser"></p>
  
  <h2><strong>.env</strong></h2>
  
  <pre><code>###&gt; lexik/jwt-authentication-bundle ###
  # Key paths should be relative to the project directory 
  JWT_PRIVATE_KEY_PATH=var/jwt/private.pem
  JWT_PUBLIC_KEY_PATH=var/jwt/public.pem
  JWT_PASSPHRASE=d70414362252a41ce772dff4823d084d
  ###&lt; lexik/jwt-authentication-bundle ###
  </code></pre>
  
  <h2><strong>lexik_jwt_authentication.yaml</strong></h2>
  
  <pre><code>lexik_jwt_authentication:
      private_key_path: '%kernel.project_dir%/%env(JWT_PRIVATE_KEY_PATH)%'
      public_key_path:  '%kernel.project_dir%/%env(JWT_PUBLIC_KEY_PATH)%'
      pass_phrase:      '%env(JWT_PASSPHRASE)%'
  </code></pre>