title: Try to build auth with Symfony 4 / Apli Platform Token not found 401
body: <p>I wanna make a REST API with <a href="https://api-platform.com/" rel="nofollow noreferrer">API PLATFORM</a> and Symfony 4.2
  I'm just trying to make the user auth but it fail every times.</p>
  
  <p>I'll will give you each step so may You see where/why I fail:</p>
  
  <p>Create Symfony projet and require all needed : </p>
  
  <pre><code>composer create-project symfony/skeleton stackoverflow
  cd ./stackoverflow
  composer req api server maker
  </code></pre>
  
  <p>Then I create user and it's create the security provider etc automatically :</p>
  
  <pre><code>php bin/console make:user
  </code></pre>
  
  <p>Then I follow <a href="http://LexikJWTAuthenticationBundle" rel="nofollow noreferrer">LexikJWTAuthenticationBundle</a> install instructions :</p>
  
  <pre><code>composer req "lexik/jwt-authentication-bundle"
  /**
  * config/bundles.php
  */
  return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class =&gt; ['all' =&gt; true],
    Symfony\Bundle\TwigBundle\TwigBundle::class =&gt; ['all' =&gt; true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class =&gt; ['all' =&gt; true],
    Nelmio\CorsBundle\NelmioCorsBundle::class =&gt; ['all' =&gt; true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class =&gt; ['all' =&gt; true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class =&gt; ['all' =&gt; true],
    ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class =&gt; ['all' =&gt; true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class =&gt; ['all' =&gt; true],
    Symfony\Bundle\MakerBundle\MakerBundle::class =&gt; ['dev' =&gt; true],
    Symfony\Bundle\WebServerBundle\WebServerBundle::class =&gt; ['dev' =&gt; true],
    Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class =&gt; ['all' =&gt; true],
  ];
  mkdir -p config/jwt
  openssl genrsa -out config/jwt/private.pem -aes256 4096 // pw: stackoverflow
  openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem // pw : stackoverflow
  /**
  * config/packages/lexik_jwt_authentication.yaml
  */
  lexik_jwt_authentication:
   secret_key:  '%env(resolve:JWT_SECRET_KEY)%'
   public_key:  '%env(resolve:JWT_PUBLIC_KEY)%'
   pass_phrase: '%env(JWT_PASSPHRASE)%'
   token_ttl:   3600
  /**
  * config/packages/security.yaml
  */
  security:
  encoders:
      App\Entity\User:
          algorithm: argon2i
  
  providers:
      app_user_provider:
          entity:
              class: App\Entity\User
              property: email
  
  firewalls:
      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
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
      main:
          anonymous: true
  
  access_control:
      - { path: ^/admin/users, roles: ROLE_SUPER_ADMIN }
      - { path: ^/admin, roles: ROLE_ADMIN }
  </code></pre>
  
  <p>I start server :</p>
  
  <pre><code>php bin/console server:run
  </code></pre>
  
  <p>And I try the test from the documentation:</p>
  
  <blockquote>
    <p>curl -X POST -H "Content-Type: application/json"
    <a href="http://localhost/api/login_check" rel="nofollow noreferrer">http://localhost/api/login_check</a> -d
    '{"username":"johndoe","password":"test"}'</p>
    
    <p>If it works, you will receive something like this:</p>
    
    <p>{    "token" :
    "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0MzQ3Mjc1MzYsInVzZXJuYW1lIjoia29ybGVvbiIsImlhdCI6IjE0MzQ2NDExMzYifQ.nh0L_wuJy6ZKIQWh6OrW5hdLkviTs1_bau2GqYdDCB0Yqy_RplkFghsuqMpsFls8zKEErdX5TYCOR7muX0aQvQxGQ4mpBkvMDhJ4-pE4ct2obeMTr_s4X8nC00rBYPofrOONUOR4utbzvbd4d2xT_tj4TdR_0tsr91Y7VskCRFnoXAnNT-qQb7ci7HIBTbutb9zVStOFejrb4aLbr7Fl4byeIEYgp2Gd7gY"
    }</p>
  </blockquote>
  
  <p>I must add localhost:8000 of course and I get a very big error, it look like a 1000 lines js script source.</p>
  
  <p>So I skip and try to add the authorize button to swagger :</p>
  
  <pre><code>/**
  * config/packages/api_platform.yaml
  */
  api_platform:
  mapping:
      paths: ['%kernel.project_dir%/src/Entity']
  swagger:
       api_keys:
           apiKey:    
              name: Authorization
              type: header
  </code></pre>
  
  <p>And when I gonna localhost:8000 I see :     </p>
  
  <pre><code>code    401
  message "JWT Token not found"
  </code></pre>
  
  <p>I also try all this answer : <a href="https://github.com/lexik/LexikJWTAuthenticationBundle/issues/451#issuecomment-443216804" rel="nofollow noreferrer">https://github.com/lexik/LexikJWTAuthenticationBundle/issues/451#issuecomment-443216804</a></p>
  
  <p>I found this if it can help either: <em>var\cache\dev\ContainerT2hNySI\getSecurity_Authentication_Listener_Json_LoginService.php</em></p>
  
  <pre><code>use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
  use Symfony\Component\DependencyInjection\Exception\RuntimeException;
  // This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
  // Returns the private 'security.authentication.listener.json.login' shared service.
  
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Firewall/ListenerInterface.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Firewall/UsernamePasswordJsonAuthenticationListener.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Authentication/AuthenticationSuccessHandlerInterface.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Authentication/CustomAuthenticationSuccessHandler.php';
  include_once $this-&gt;targetDirs[3].'/vendor/lexik/jwt-authentication-bundle/Security/Http/Authentication/AuthenticationSuccessHandler.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Authentication/AuthenticationFailureHandlerInterface.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Authentication/CustomAuthenticationFailureHandler.php';
  include_once $this-&gt;targetDirs[3].'/vendor/lexik/jwt-authentication-bundle/Security/Http/Authentication/AuthenticationFailureHandler.php';
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Session/SessionAuthenticationStrategyInterface.php';
  
  include_once $this-&gt;targetDirs[3].'/vendor/symfony/security-http/Session/SessionAuthenticationStrategy.php';
  
  $a = ($this-&gt;services['event_dispatcher'] ?? $this-&gt;getEventDispatcherService());
  
  $this-&gt;privates['security.authentication.listener.json.login'] = $instance = new \Symfony\Component\Security\Http\Firewall\UsernamePasswordJsonAuthenticationListener(($this-&gt;services['security.token_storage'] ?? ($this-&gt;services['security.token_storage'] = new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage())), ($this-&gt;privates['security.authentication.manager'] ?? $this-&gt;getSecurity_Authentication_ManagerService()), ($this-&gt;privates['security.http_utils'] ?? $this-&gt;load('getSecurity_HttpUtilsService.php')), 'login', new \Symfony\Component\Security\Http\Authentication\CustomAuthenticationSuccessHandler(new \Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler(($this-&gt;services['lexik_jwt_authentication.jwt_manager'] ?? $this-&gt;load('getLexikJwtAuthentication_JwtManagerService.php')), $a), array(), 'login'), new \Symfony\Component\Security\Http\Authentication\CustomAuthenticationFailureHandler(new \Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationFailureHandler($a), array()), array('check_path' =&gt; '/api/login_check', 'use_forward' =&gt; false, 'require_previous_session' =&gt; false, 'username_path' =&gt; 'username', 'password_path' =&gt; 'password'), ($this-&gt;privates['logger'] ?? ($this-&gt;privates['logger'] = new \Symfony\Component\HttpKernel\Log\Logger())), $a, ($this-&gt;privates['property_accessor'] ?? $this-&gt;getPropertyAccessorService()));
  
  $instance-&gt;setSessionAuthenticationStrategy(new \Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy('none'));
  
  return $instance;
  </code></pre>
  
  <p>My localhost:8000/api headers:</p>
  
  <blockquote>
    <p>Cache-Control: no-cache, private Connection: close Content-Type:
    application/json Date: Thu, 24 Jan 2019 21:51:51 +0100, Thu, 24 Jan
    2019 20:51:51 GMT Host: localhost:8000 Link:
    <a href="http://localhost:8000/api/docs.jsonld" rel="nofollow noreferrer">http://localhost:8000/api/docs.jsonld</a>;
    rel="http://www.w3.org/ns/hydra/core#apiDocumentation"
    WWW-Authenticate: Bearer X-Powered-By:
    PHP/7.2.14-1+ubuntu18.04.1+deb.sury.org+1</p>
    
    <p>Accept:
    text/html,application/xhtml+xml,application/xml;q=0.9,<em>/</em>;q=0.8
    Accept-Encoding: gzip, deflate Accept-Language:
    fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3 Cache-Control: max-age=0
    Connection: keep-alive DNT: 1 Host: localhost:8000
    Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0;
    Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0</p>
  </blockquote>
  
  <p>The problem may be I cannot do 2nd / 3rd PARTS Obtain the token &amp; Use the token, I don't know if it does matter. (I'm thinking, it's the name of the error "token not found") so all of that for this FFS).</p>
  
  <p>The error I get when I try to obtain the token is like a 1000 lines JS script source, I cannot tell more (I guess it's not allowed to paste as long).</p>
  
  <p>Need some help, thanks.</p>