示例#1
0
 public function authenticated($code)
 {
     $client = $this->connect();
     if (isset($_REQUEST['logout'])) {
         unset($_SESSION['access_token']);
     }
     if (isset($code)) {
         $client->authenticate();
         $_SESSION['access_token'] = $client->getAccessToken();
     }
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->getAccessToken()) {
         $token = json_decode($client->getAccessToken(), true);
         /**************/
         $serviceURI = 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' . $token['access_token'];
         global $apiConfig;
         $curl = new apiCurlIO(new $apiConfig['cacheClass'](), new $apiConfig['authClass']());
         $respone = $curl->makeRequest(new apiHttpRequest($serviceURI));
         $auth = json_decode($respone->getResponseBody(), true);
         return $auth;
     }
     return false;
 }
示例#2
0
 public function testCacheHit()
 {
     $io = new apiCurlIO();
     $url = "http://www.googleapis.com";
     // Create a cacheable request/response.
     // Should not be revalidated.
     $cacheReq = new apiHttpRequest($url, "GET");
     $cacheReq->setRequestHeaders(array("Accept" => "*/*"));
     $cacheReq->setResponseBody("{\"a\": \"foo\"}");
     $cacheReq->setResponseHttpCode(200);
     $cacheReq->setResponseHeaders(array("Cache-Control" => "private", "ETag" => "\"this-is-an-etag\"", "Expires" => "Sun, 22 Jan 2022 09:00:56 GMT", "Date: Sun, 1 Jan 2012 09:00:56 GMT", "Content-Type" => "application/json; charset=UTF-8"));
     // Populate the cache.
     $io->setCachedRequest($cacheReq);
     // Execute the same mock request, and expect a cache hit.
     $res = $io->makeRequest(new apiHttpRequest($url, "GET"));
     $this->assertEquals("{\"a\": \"foo\"}", $res->getResponseBody());
     $this->assertEquals(200, $res->getResponseHttpCode());
 }