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([ 'https://graph.microsoft.com/.default' ]); } /** * @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', '/')); } }