Sets the AuthSub token used for authentication
public setAuthSubToken ( string $token ) : Zend_Gdata_HttpClient | ||
$token | string | The token |
Результат | Zend_Gdata_HttpClient | Provides a fluent interface |
public function testSecureAuthSubSigning() { if (!extension_loaded('openssl')) { $this->markTestSkipped('The openssl extension is not available'); } else { $c = new Zend_Gdata_HttpClient(); $c->setAuthSubPrivateKeyFile("Zend/Gdata/_files/RsaKey.pem", null, true); $c->setAuthSubToken('abcdefg'); $requestData = $c->filterHttpRequest('POST', 'http://www.example.com/feed', array(), 'foo bar', 'text/plain'); $authHeaderCheckPassed = false; $headers = $requestData['headers']; foreach ($headers as $headerName => $headerValue) { if (strtolower($headerName) == 'authorization') { preg_match('/data="([^"]*)"/', $headerValue, $matches); $dataToSign = $matches[1]; preg_match('/sig="([^"]*)"/', $headerValue, $matches); $sig = $matches[1]; if (function_exists('openssl_verify')) { $fp = fopen('Zend/Gdata/_files/RsaCert.pem', 'r', true); $cert = ''; while (!feof($fp)) { $cert .= fread($fp, 8192); } fclose($fp); $pubkeyid = openssl_get_publickey($cert); $verified = openssl_verify($dataToSign, base64_decode($sig), $pubkeyid); $this->assertEquals(1, $verified, 'The generated signature was unable ' . 'to be verified.'); $authHeaderCheckPassed = true; } } } $this->assertEquals(true, $authHeaderCheckPassed, 'Auth header not found for sig verification.'); } }
function setupDocsClient($token = null) { global $authSubURL; $docsClient = null; // Fetch a new AuthSub token? if (!$token && !isset($_SESSION['sessionToken'])) { $next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $scope = 'http://docs.google.com/feeds/ https://docs.google.com/feeds/'; $secure = 0; $session = 1; $permission = 1; // 1 - allows posting notices && allows reading profile data $authSubURL = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } else { if (isset($_SESSION['sessionToken'])) { $httpClient = new Zend_Gdata_HttpClient(); $httpClient->setAuthSubToken($_SESSION['sessionToken']); $docsClient = new Zend_Gdata_Docs($httpClient, 'google-OCRPHPDemo-v0.1'); } else { $httpClient = new Zend_Gdata_HttpClient(); $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken(trim($token), $httpClient); $httpClient->setAuthSubToken($_SESSION['sessionToken']); $docsClient = new Zend_Gdata_Docs($httpClient, 'google-OCRPHPDemo-v0.1'); } } return $docsClient; }
public function picasaDelete($photoId) { $token = $this->get_login_token(); $client = new Zend_Gdata_HttpClient(); $client->setAuthSubToken($token); $client->setClientLoginToken($token); $gphoto = new Zend_Gdata_Photos($client); $photoQuery = $gphoto->newPhotoQuery(); $photoQuery->setUser($this->config['user']); $photoQuery->setAlbumId($this->config['album_id']); $photoQuery->setPhotoId($photoId); $photoQuery->setType('entry'); $entry = $gphoto->getPhotoEntry($photoQuery); $gphoto->deletePhotoEntry($entry, true); }
/** * Retrieve a HTTP client object with AuthSub credentials attached * as the Authorization header * * @param string $token The token to retrieve information about * @param Zend_Gdata_HttpClient $client (optional) HTTP client to use to make the request */ public static function getHttpClient($token, $client = null) { if ($client == null) { $client = new Zend_Gdata_HttpClient(); } if (!$client instanceof Zend_Gdata_HttpClient) { // require_once 'Zend/Gdata/App/HttpException.php'; throw new Zend_Gdata_App_HttpException('Client is not an instance of Zend_Gdata_HttpClient.'); } $useragent = 'Zend_Framework_Gdata/' . Zend_Version::VERSION; $client->setConfig(array('strictredirects' => true, 'useragent' => $useragent)); $client->setAuthSubToken($token); return $client; }
/** * N.B.: A session token must be available before calling this method * * @return void */ public function init() { if (!is_object($this->service)) { $pathToKey = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('app_googleCalendarIntegration_privateKeyPath'); $client = new Zend_Gdata_HttpClient(); $client->setAuthSubPrivateKeyFile($pathToKey, null, true); $sessionToken = $this->getSessionToken(); if (!$sessionToken) { throw new Exception("GoogleCalendarInterface: missing session token"); } $client->setAuthSubToken($sessionToken); $this->service = new Zend_Gdata_Calendar($client, 'google-calendar-plancake-integration'); $this->service->setMajorProtocolVersion(2); $this->service->setMinorProtocolVersion(null); } }