public function onBeforeClientRequestEvent(BeforeClientRequestEvent $event) { if ($event->isSecured()) { if (null === $this->session->getAuthToken()) { $this->authenticateEntryPoint->login(); } } }
/** * @param ClientHttpErrorEvent $event */ public function onClientHttpErrorEvent(ClientHttpErrorEvent $event) { //If we already are in intercepted response, don't do it again if ($this->intercepted) { return; } $response = $event->getResponse(); if (401 !== $response->getStatusCode()) { return; } try { $this->intercepted = true; $this->authenticateEntryPoint->login(); $originalRequest = $event->getOriginalRequest(); $interceptedResponse = $this->client->request($originalRequest['method'], $originalRequest['uri'], $originalRequest['queryParams'], $originalRequest['requestParams'], $originalRequest['option'], $originalRequest['secured']); $event->setInterceptedResponse($interceptedResponse); $event->stopPropagation(); } catch (Exception $e) { //Ignore any exception that got here } finally { $this->intercepted = false; } }