跳到内容

访问已验证的 JWT 令牌

编辑此页

如果您需要从控制器或服务中获取 JWT 令牌的信息以用于某些目的,您可以

  1. 注入 TokenStorageInterfaceJWTTokenManagerInterface

    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;
    }
  2. 在 jwtManager 中调用 decode(),并在 TokenStorageInterface 中调用 getToken()

    1
    $decodedJwtToken = $this->jwtManager->decode($this->tokenStorageInterface->getToken());

这将返回当前请求中发送的 JWT 令牌的解码信息。

这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本