diff --git a/config/services.yaml b/config/services.yaml index a438986..0d3aa13 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -7,6 +7,7 @@ parameters: aws_url: '%env(AWS_ENDPOINT)%' aws_public_url: '%env(AWS_ENDPOINT)%' aws_bucket: '%env(S3_PORTAL_BUCKET)%' + mercure_secret: '%env(MERCURE_JWT_SECRET)%' logos_directory: '%kernel.project_dir%/public/uploads/logos' services: diff --git a/src/Controller/MercureController.php b/src/Controller/MercureController.php index 4433664..096871b 100644 --- a/src/Controller/MercureController.php +++ b/src/Controller/MercureController.php @@ -8,6 +8,7 @@ use Lcobucci\JWT\Signer\Hmac\Sha256; use Lcobucci\JWT\Signer\Key\InMemory; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class MercureController extends AbstractController @@ -16,15 +17,17 @@ class MercureController extends AbstractController { } #[Route(path: '/mercure-token', name: 'mercure_token', methods: ['GET'])] - public function getMercureToken(): JsonResponse + public function getMercureToken(Request $request): JsonResponse { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); - $topic = sprintf('http://portail.solutions-easy.moi/notifications/user/%d', $user->getId()); + $domain = $request->getSchemeAndHttpHost(); + + $topic = sprintf('%s/notifications/user/%d', $domain, $user->getId()); // Generate JWT token for Mercure subscription - $secret = $_ENV['MERCURE_JWT_SECRET']; + $secret = $this->getParameter('mercure_secret'); $config = Configuration::forSymmetricSigner( new Sha256(),