src/Controller/SecurityController.php line 15

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use App\Security\AzureAuthenticator;
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route('/login'name'app_login')]
  12.     public function login(Request $request): Response
  13.     {
  14.         if ($this->getUser()) {
  15.             return $this->redirectToRoute('app_index');
  16.         }
  17.         return $this->render('security/login.html.twig');
  18.     }
  19.     #[Route('/login/azure/check'name'app_login_azure')]
  20.     public function azure(Request $requestAuthenticationUtils $authenticationUtilsAzureAuthenticator $azureAuthenticator): Response
  21.     {
  22.         if($request->isMethod('POST')) {
  23.             $baseGraphUri $azureAuthenticator->getAzureProvider()->getRootMicrosoftGraphUri(null);
  24.             $authorizationUrl $azureAuthenticator->getAzureProvider()->getAuthorizationUrl(['scope' => $azureAuthenticator->getAzureProvider()->scope]);
  25.             $request->getSession()->set(
  26.                'azure_api_state',
  27.                $azureAuthenticator->getAzureProvider()->getState()
  28.             );
  29.             return $this->redirect($authorizationUrl);
  30.         }
  31.         return $this->redirectToRoute('app_login');
  32.     }
  33.     #[Route('/logout'name'app_logout')]
  34.     public function logout()
  35.     {
  36.         throw new \Exception('This method can be blank - it will be intercepted by the logout key on the firewall');
  37.     }
  38. }