title: How to get jwt token from controller (user already logged in)
body: <p>So I'm using Lexik JWT bundle (Symfony 2.8) to authenticate over Google and when user is logging in it works well. My Success handler looks like this:</p>
  
  <pre><code>public function onAuthenticationSuccess(Request $request, TokenInterface $token)
  {
      $user = $token-&gt;getUser();
      $jwt  = $this-&gt;jwtManager-&gt;create($user);
      $response = new JsonResponse();
      $event    = new AuthenticationSuccessEvent(['token' =&gt; $jwt], $user, $response);
      $this-&gt;dispatcher-&gt;dispatch(Events::AUTHENTICATION_SUCCESS, $event);
      $redirectResponse = new RedirectResponse('http://localhost:3000?token='.$event-&gt;getData()['token']."&amp;username=".$user-&gt;getUsername());
      return $redirectResponse;
  }
  </code></pre>
  
  <p>So I'm redirecting user to some localhost and passing token as "token" <code>get</code> variable and that works well. Later I can pass that token value trough header and I get authenticated.</p>
  
  <p>Problem is - I want to get the same token from my controller. I'm using the similar code:</p>
  
  <pre><code>$jwtManager = $this-&gt;get('lexik_jwt_authentication.jwt_manager');
  
  $tokenStorage = $this-&gt;get('security.token_storage');
  $token = $tokenStorage-&gt;getToken();
  
  $user = $token-&gt;getUser();
  $jwt  = $jwtManager-&gt;create($user);
  $response = new JsonResponse();
  $event    = new AuthenticationSuccessEvent(['token' =&gt; $jwt], $user, $response);
  $token = $event-&gt;getData()['token'];
  echo $token;
  </code></pre>
  
  <p>And I really get some token, but that's not the same one I get from success handler. Tried passing it as header "Autorization" parameter, but it doesn't work. I'm getting 401 error and message:</p>
  
  <p><em>Unable to verify the given JWT through the given configuration. If the \"lexik_jwt_authentication.encoder\" encryption options have been changed since your last authentication, please renew the token. If the problem persists, verify that the configured keys/passphrase are valid.</em></p>
  
  <p>What I'm doing wrong here? Why I'm getting different token and how can I get token I'm getting form success handler?</p>