Accessing the authenticated JWT token
If you need to get the information of JWT token from a Controller or Service for some purposes, you can:
Inject TokenStorageInterface and JWTTokenManagerInterface:
1 2 3 4 5 6 7 8
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; public function __construct(TokenStorageInterface $tokenStorageInterface, JWTTokenManagerInterface $jwtManager) { $this->jwtManager = $jwtManager; $this->tokenStorageInterface = $tokenStorageInterface; }
Call
decode()
in jwtManager, andgetToken()
in TokenStorageInterface.1
$decodedJwtToken = $this->jwtManager->decode($this->tokenStorageInterface->getToken());
This returns the decoded information of the JWT token sent in the current request.
This work, including the code samples, is licensed under a
Creative Commons BY-SA 3.0 license.