2024-07-19 02:28:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
2024-07-22 02:17:42 +02:00
|
|
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
|
|
|
|
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
|
2024-07-19 02:28:05 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2024-07-22 02:17:42 +02:00
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2024-07-19 02:28:05 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
2024-07-22 02:17:42 +02:00
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
2024-07-22 13:39:45 +02:00
|
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
2024-07-19 02:28:05 +02:00
|
|
|
|
|
|
|
|
class HomeController extends AbstractController
|
|
|
|
|
{
|
|
|
|
|
|
2024-07-22 13:39:45 +02:00
|
|
|
#[Route(path: "/login/oauth", name: "oauth_connect")]
|
2024-07-22 02:17:42 +02:00
|
|
|
public function connectAction(ClientRegistry $clientRegistry): Response
|
|
|
|
|
{
|
|
|
|
|
return $clientRegistry->getClient('oauth')->redirect();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 13:39:45 +02:00
|
|
|
#[Route(path: "/login/oauth/token", name: "oauth_connect_token")]
|
|
|
|
|
#[IsGranted('IS_AUTHENTICATED_FULLY')]
|
|
|
|
|
public function loginOAuthToken(UserInterface $user, JWTTokenManagerInterface $JWTManager): JsonResponse
|
2024-07-22 02:17:42 +02:00
|
|
|
{
|
|
|
|
|
return new JsonResponse(['token' => $JWTManager->create($user)]);
|
|
|
|
|
}
|
2024-07-22 13:39:45 +02:00
|
|
|
}
|