domain-watchdog/src/Controller/HomeController.php

34 lines
1.1 KiB
PHP
Raw Normal View History

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-19 02:28:05 +02:00
class HomeController extends AbstractController
{
#[Route(path: "/", name: "index")]
public function index(): Response
{
2024-07-21 19:47:25 +02:00
return $this->render('index.html.twig');
2024-07-19 02:28:05 +02:00
}
2024-07-22 02:17:42 +02:00
#[Route(path: "/login/oauth", name: "connect_start")]
public function connectAction(ClientRegistry $clientRegistry): Response
{
return $clientRegistry->getClient('oauth')->redirect();
}
#[Route(path: "/login/oauth/token", name: "login_oauth_token")]
public function getToken(UserInterface $user, JWTTokenManagerInterface $JWTManager): JsonResponse
{
return new JsonResponse(['token' => $JWTManager->create($user)]);
}
2024-07-19 02:28:05 +02:00
}