Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 899 Bytes

9-access-authenticated-jwt-token.md

File metadata and controls

25 lines (18 loc) · 899 Bytes

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:

  1. 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;
}
  1. Call decode() in jwtManager, and getToken() in tokenStorageInterface.
$decodedJwtToken = $this->jwtManager->decode($this->tokenStorageInterface->getToken());

This returns the decoded information of the JWT token sent in the current request.