<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class HomeController extends AbstractController
|
|
{
|
|
#[Route('/', name: 'app_home')]
|
|
public function index(): Response
|
|
{
|
|
return $this->render('home/index.html.twig', [
|
|
]);
|
|
}
|
|
|
|
#[Route('/osm/request', name: 'app_osm_request')]
|
|
public function osmRequest(ClientRegistry $clientRegistry): Response
|
|
{
|
|
return $clientRegistry
|
|
->getClient('openstreetmap')
|
|
->redirect([
|
|
'read_prefs',
|
|
]);
|
|
}
|
|
|
|
#[Route('/osm/callback', name: 'app_osm_callback')]
|
|
public function osmCallback(Request $request, ClientRegistry $clientRegistry): Response
|
|
{
|
|
$client = $clientRegistry->getClient('openstreetmap');
|
|
|
|
if ($request->query->has('error')) {
|
|
$this->addFlash('danger', sprintf(
|
|
'Échec de l’authentification (%s)',
|
|
$request->query->has('error_description') ? $request->query->get('error_description') : $request->query->get('error')
|
|
));
|
|
} else {
|
|
$this->addFlash('success', 'Authentification OSM réussie !');
|
|
}
|
|
|
|
return $this->redirectToRoute('app_home');
|
|
}
|
|
|
|
#[Route('/osm/logout', name: 'app_osm_logout')]
|
|
public function osmLogout(Security $security): Response
|
|
{
|
|
return $security->logout();
|
|
}
|
|
|
|
|
|
}
|