src/Controller/SecurityController.php line 43
<?php
namespace App\Controller;
use Exception;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use App\Entity\Permission;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpClient\HttpClient;
class SecurityController extends AbstractController
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
#[Route(path: '/logins', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): RedirectResponse
{
return $this->redirectToRoute('app_login');
}
#[Route('/login', name: 'logins')]
public function index(Request $request, ManagerRegistry $doctrine): Response
{
// Encode the token
$token = JWT::encode(["appStats" => "appStats"], $_ENV['JWT_PUBLIC_KEY'], 'HS256');
$client = HttpClient::create();
// Make a GET request to an API endpoint
$response = $client->request('GET', 'https://dev.welcomeworkspaces.com/stats/login', [
'query' => [
'token' => $token
],
]);
// Get the response body as a string
$content = $response->getContent();
// Decode the JSON response into an associative array
$data = json_decode($content, true);
dd($data);
return $this->json(["message" => "passed"]);
}
}