예제 #1
0
 /**
  * @param array|string        $config     Array with configuration or path to PHP file that will return array
  * @param HttpClientInterface $httpClient
  * @param StorageInterface    $storage
  * @param LoggerInterface     $logger
  *
  * @throws InvalidArgumentException
  */
 public function __construct($config = [], HttpClientInterface $httpClient = null, StorageInterface $storage = null, LoggerInterface $logger = null)
 {
     if (is_string($config) && file_exists($config)) {
         $config = (include $config);
     } elseif (!is_array($config)) {
         throw new InvalidArgumentException('Hybriauth config does not exist on the given path.');
     }
     $this->config = $config + ['debug_mode' => Logger::NONE, 'debug_file' => '', 'curl_options' => null, 'providers' => []];
     $this->storage = $storage ?: new Session();
     $this->logger = $logger ?: new Logger($this->config['debug_mode'], $this->config['debug_file']);
     $this->httpClient = $httpClient ?: new HttpClient();
     if ($this->config['curl_options'] && method_exists($this->httpClient, 'setCurlOptions')) {
         $this->httpClient->setCurlOptions($this->config['curl_options']);
     }
     if (method_exists($this->httpClient, 'setLogger')) {
         $this->httpClient->setLogger($this->logger);
     }
 }
예제 #2
0
 /**
  * Validate Signed API Requests responses.
  *
  * Since the specifics of error responses is beyond the scope of RFC6749 and OAuth Core specifications,
  * Hybridauth will consider any HTTP status code that is different than '200 OK' as an ERROR.
  *
  * @throws HttpClientFailureException
  * @throws HttpRequestFailedException
  */
 protected function validateApiResponse()
 {
     if ($this->httpClient->getResponseClientError()) {
         throw new HttpClientFailureException('HTTP client error: ' . $this->httpClient->getResponseClientError() . '.');
     }
     if (200 != $this->httpClient->getResponseHttpCode()) {
         throw new HttpRequestFailedException('HTTP error ' . $this->httpClient->getResponseHttpCode() . '. Raw Provider API response: ' . $this->httpClient->getResponseBody() . '.');
     }
 }