mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
remote calendar: authenticate to ms graph api
This commit is contained in:
@@ -247,7 +247,7 @@ class CalendarController extends AbstractController
|
||||
}
|
||||
|
||||
if (!$this->remoteCalendarConnector->isReady()) {
|
||||
return $this->remoteCalendarConnector->getMakeReadyResponse();
|
||||
return $this->remoteCalendarConnector->getMakeReadyResponse($request->getUri());
|
||||
}
|
||||
|
||||
$view = '@ChillCalendar/Calendar/listByUser.html.twig';
|
||||
|
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Controller;
|
||||
|
||||
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MSGraphTokenStorage;
|
||||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use TheNetworg\OAuth2\Client\Provider\Azure;
|
||||
use TheNetworg\OAuth2\Client\Token\AccessToken;
|
||||
|
||||
class RemoteCalendarConnectAzureController
|
||||
{
|
||||
private ClientRegistry $clientRegistry;
|
||||
|
||||
private MSGraphTokenStorage $MSGraphTokenStorage;
|
||||
|
||||
public function __construct(
|
||||
ClientRegistry $clientRegistry,
|
||||
MSGraphTokenStorage $MSGraphTokenStorage
|
||||
) {
|
||||
$this->clientRegistry = $clientRegistry;
|
||||
$this->MSGraphTokenStorage = $MSGraphTokenStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/connect/azure", name="chill_calendar_remote_connect_azure")
|
||||
*/
|
||||
public function connectAzure(Request $request): Response
|
||||
{
|
||||
$request->getSession()->set('azure_return_path', $request->query->get('returnPath', '/'));
|
||||
|
||||
return $this->clientRegistry
|
||||
->getClient('azure') // key used in config/packages/knpu_oauth2_client.yaml
|
||||
->redirect([
|
||||
'User.Read', 'Calendars.Read', 'Calendars.Read.Shared',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/connect/azure/check", name="chill_calendar_remote_connect_azure_check")
|
||||
*/
|
||||
public function connectAzureCheck(Request $request): Response
|
||||
{
|
||||
/** @var Azure $client */
|
||||
$client = $this->clientRegistry->getClient('azure');
|
||||
|
||||
try {
|
||||
/** @var AccessToken $token */
|
||||
$token = $client->getAccessToken();
|
||||
|
||||
$this->MSGraphTokenStorage->setToken($token);
|
||||
} catch (IdentityProviderException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new RedirectResponse($request->getSession()->remove('azure_return_path', '/'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user