<?php
namespace App\Controller\User;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
class ResetTokenController extends AbstractController
{
public function __invoke(Security $security, JWTTokenManagerInterface $JWTTokenManager): JsonResponse
{
$user = $security->getUser();
$token = $JWTTokenManager->create($user);
return new JsonResponse(['token' => $token]);
}
}
1条答案
按热度按时间li9yvcax1#
下面是一个Controller,用于从用户创建新令牌。
更多信息请查看此文档https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/7-manual-token-creation.rst#creating-jwt-tokens-programmatically