Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 986 Bytes

9-access-authenticated-jwt-token.rst

File metadata and controls

26 lines (17 loc) · 986 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;
    }
  2. 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.