예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function makeApiCall(RequestInterface $request)
 {
     $response = null;
     if ($this->authenticator->getAccessToken() !== null) {
         $authenticatedRequest = new OAuthDecorator($request);
         $authenticatedRequest->setAccessToken($this->authenticator->getAccessToken());
         $authenticatedRequest->addAuthentication();
         $response = $this->client->makeCall($authenticatedRequest->getFullUrl(), $this->addDefaultHeaders($authenticatedRequest->getHeaders()), $authenticatedRequest->getOptions());
         if ($response['status'] == 200) {
             $this->authenticationRetryLimit = 0;
             try {
                 return new Response($response['body'], $response['headers']);
             } catch (ResponseException $e) {
                 throw new ClientException($e->getMessage(), $e->getCode(), $e);
             }
         }
     }
     if ($response === null || $response['status'] == 401) {
         $this->authenticationRetryLimit++;
         if ($this->authenticationRetryLimit > self::MAX_RETRY_LIMIT) {
             throw new AccessDeniedException('Authentication retry limit reached.');
         }
         try {
             $this->authenticator->setBaseUrl($request->getBaseUrl());
             $this->authenticator->getAuthenticationTokens();
             // Reexecute event
             return $this->makeApiCall($request);
         } catch (AccessDeniedException $e) {
             throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
         } catch (AuthenticationException $e) {
             throw new AccessDeniedException('Could not authenticate against API.', $e->getCode(), $e);
         }
     }
     throw new ClientException(sprintf('The server returned an error with status %s.', $response['status']));
 }
 /**
  * Refreshes the token via then authenticator.
  *
  * @param  RequestInterface $request
  *
  * @return void
  */
 protected function getNewToken(RequestInterface $request)
 {
     try {
         $this->authenticator->setBaseUrl($request->getBaseUrl());
         $this->authenticator->getAuthenticationTokens();
     } catch (AuthenticationException $e) {
         throw new AccessDeniedException('Could not authenticate against API.', $e->getCode(), $e);
     }
     return;
 }
 /**
  * {@inheritdoc}
  */
 public function getFullUrl()
 {
     return $this->decoratedRequest->getFullUrl();
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 protected function sendRequest(RequestInterface $request)
 {
     $request->setOptions($this->addDefaultOptions($request->getOptions()));
     return parent::sendRequest($request);
 }