If you need to get the information of JWT token from a Controller or Service for some purposes, you can:
Inject TokenStorageInterface and JWTTokenManagerInterface:
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.$decodedJwtToken = $this->jwtManager->decode($this->tokenStorageInterface->getToken());
This returns the decoded information of the JWT token sent in the current request.