src/Controller/SecurityController.php line 43

  1. <?php
  2. namespace App\Controller;
  3. use Exception;
  4. use Firebase\JWT\JWT;
  5. use Firebase\JWT\Key;
  6. use App\Entity\Permission;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  14. use Symfony\Component\Security\Core\Security;
  15. use Symfony\Component\HttpClient\HttpClient;
  16. class SecurityController extends AbstractController
  17. {
  18.     private $security;
  19.     public function __construct(Security $security)
  20.     {
  21.        $this->security $security;
  22.     }
  23.     #[Route(path'/logins'name'app_login')]
  24.     public function login(AuthenticationUtils $authenticationUtils): Response
  25.     {
  26.         // if ($this->getUser()) {
  27.         //     return $this->redirectToRoute('target_path');
  28.         // }
  29.         // get the login error if there is one
  30.         $error $authenticationUtils->getLastAuthenticationError();
  31.         // last username entered by the user
  32.         $lastUsername $authenticationUtils->getLastUsername();
  33.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  34.     }
  35.     #[Route(path'/logout'name'app_logout')]
  36.     public function logout(): RedirectResponse
  37.     {
  38.         return $this->redirectToRoute('app_login');
  39.     }
  40.     
  41.     #[Route('/login'name'logins')]
  42.     public function index(Request $requestManagerRegistry $doctrine): Response
  43.     {
  44.         // Encode the token
  45.         $token JWT::encode(["appStats" => "appStats"], $_ENV['JWT_PUBLIC_KEY'], 'HS256');
  46.         $client HttpClient::create();
  47.         // Make a GET request to an API endpoint
  48.         $response $client->request('GET''https://dev.welcomeworkspaces.com/stats/login', [
  49.             'query' => [
  50.                 'token' => $token
  51.             ],
  52.         ]);
  53.         // Get the response body as a string
  54.         $content $response->getContent();
  55.         // Decode the JSON response into an associative array
  56.         $data json_decode($contenttrue);
  57.         dd($data);
  58.         return $this->json(["message" => "passed"]);
  59.     }
  60. }