From 560a12f0bd6347a335f8ed5201d6d9562d03d4bc Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 3 May 2014 22:24:03 -0400 Subject: Add Google authentication --- vendor/OAuth/Common/Http/Client/StreamClient.php | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 vendor/OAuth/Common/Http/Client/StreamClient.php (limited to 'vendor/OAuth/Common/Http/Client/StreamClient.php') diff --git a/vendor/OAuth/Common/Http/Client/StreamClient.php b/vendor/OAuth/Common/Http/Client/StreamClient.php new file mode 100755 index 00000000..7f3c5249 --- /dev/null +++ b/vendor/OAuth/Common/Http/Client/StreamClient.php @@ -0,0 +1,92 @@ +normalizeHeaders($extraHeaders); + + if ($method === 'GET' && !empty($requestBody)) { + throw new \InvalidArgumentException('No body expected for "GET" request.'); + } + + if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) { + $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded'; + } + + $host = 'Host: '.$endpoint->getHost(); + // Append port to Host if it has been specified + if ($endpoint->hasExplicitPortSpecified()) { + $host .= ':'.$endpoint->getPort(); + } + + $extraHeaders['Host'] = $host; + $extraHeaders['Connection'] = 'Connection: close'; + + if (is_array($requestBody)) { + $requestBody = http_build_query($requestBody, '', '&'); + } + $extraHeaders['Content-length'] = 'Content-length: '.strlen($requestBody); + + $context = $this->generateStreamContext($requestBody, $extraHeaders, $method); + + $level = error_reporting(0); + $response = file_get_contents($endpoint->getAbsoluteUri(), false, $context); + error_reporting($level); + if (false === $response) { + $lastError = error_get_last(); + if (is_null($lastError)) { + throw new TokenResponseException('Failed to request resource.'); + } + throw new TokenResponseException($lastError['message']); + } + + return $response; + } + + private function generateStreamContext($body, $headers, $method) + { + return stream_context_create( + array( + 'http' => array( + 'method' => $method, + 'header' => implode("\r\n", array_values($headers)), + 'content' => $body, + 'protocol_version' => '1.1', + 'user_agent' => $this->userAgent, + 'max_redirects' => $this->maxRedirects, + 'timeout' => $this->timeout + ), + ) + ); + } +} -- cgit v1.2.3