feat: implement OAuth 2.0 login flow

This commit is contained in:
Maël Gangloff
2024-07-22 02:17:42 +02:00
parent c48f37696c
commit 9e8523fa53
12 changed files with 850 additions and 2 deletions

View File

@@ -2,9 +2,13 @@
namespace App\Controller;
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Core\User\UserInterface;
class HomeController extends AbstractController
{
@@ -16,4 +20,15 @@ class HomeController extends AbstractController
}
#[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)]);
}
}