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; }
function getAuthSubHttpClient() { if (isset($_SESSION['google_session_token'])) { $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['google_session_token']); return $client; } }
function getAuthSubUrl() { $next = getCurrentUrl(); $scope = 'http://picasaweb.google.com/data'; $secure = 0; $session = 1; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); }
function getAuthSubUrl() { $next = getCurrentUrl(); $scope = 'https://picasaweb.google.com/lh/myphotos?noredirect=1'; $secure = 0; $session = 1; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); }
public function testGetAuthSubTokenUriModifiedBase() { $uri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://www.example.com/foo.php', 'http://www.google.com/calendar/feeds', 0, 1, 'http://www.otherauthservice.com/accounts/AuthSubRequest'); // Note: the scope here is not encoded. It should be encoded, // but the method getAuthSubTokenUri calls urldecode($scope). // This currently works (no reported bugs) as web browsers will // handle the encoding in most cases. $this->assertEquals('http://www.otherauthservice.com/accounts/AuthSubRequest?next=http%3A%2F%2Fwww.example.com%2Ffoo.php&scope=http://www.google.com/calendar/feeds&secure=0&session=1', $uri); }
/** * Logs in via AuthSub. AuthSub is simiar to OAuth, but was developed * before OAuth became the "standard". AuthSub acts in a similar way as * OAuth. You login through Google, granting access to the site. You are * then returned to the site with an access token to authorize with. * * @param String $redirectUrl - URL that you want to redirect to * once a token is assigned * @return String - URL to follow to log into Google Calendar */ function getAuthSubUrl($redirectUrl) { // indicates the app will only access Google Calendar feeds $scope = 'http://www.google.com/calendar/feeds'; $secure = false; // if you are registered with SubAuth, then this can be true $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($redirectUrl, $scope, $secure, $session); }
public function includes() { set_include_path(PLUGIN_DIR . "wildfire.media.youtube/ZendGdata/library/"); require_once PLUGIN_DIR . 'wildfire.media.youtube/ZendGdata/library/Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_YouTube'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_App_Exception'); $httpClient = Zend_Gdata_AuthSub::getHttpClient(Config::get('youtube/token')); return new Zend_Gdata_YouTube($httpClient, 0, 0, Config::get('youtube/developer_key')); }
/** * Upgrade the single-use token to a session token. * * @param string $singleUseToken A valid single use token that is upgradable to a session token. * @return void */ function updateAuthSubToken($singleUseToken) { try { $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Token upgrade for ' . $singleUseToken . ' failed : ' . $e->getMessage(); return; } $_SESSION['sessionToken'] = $sessionToken; header('Location: ' . HOME_URL); }
function generateAuthSubURL() { $next = 'http://localhost/test1.php'; $scope = 'https://www.google.com/h9/feeds'; $authSubHandler = 'https://www.google.com/h9/authsub'; $secure = 0; $session = 1; $authSubURL = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session, $authSubHandler); // 1 - allows posting notices && allows reading profile data $permission = 1; $authSubURL .= '&permission=' . $permission; return '<a href="' . $authSubURL . '">Click here to link your H9 Account</a>'; }
/** * Returns a HTTP client object with the appropriate headers for communicating * with Google using AuthSub authentication. * * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after * it is obtained. The single use token supplied in the URL when redirected * after the user succesfully authenticated to Google is retrieved from the * $_GET['token'] variable. * * @return Zend_Http_Client */ function getAuthSubHttpClient() { global $_SESSION, $_GET; $client = new Zend_Gdata_HttpClient(); if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client); } if (empty($_SESSION['sessionToken'])) { return null; } $client->setAuthSubToken($_SESSION['sessionToken']); return $client; }
function getAuthSubHttpClient($mmm_id, $username) { if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) { $this->redirect('/yts/index/'); exit; return false; } else { if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); $sessionToken = $_SESSION['sessionToken']; $this->time = time(); $this->record['Yt']['mmm_id'] = $mmm_id; $this->record['Yt']['sessionToken'] = $sessionToken; $this->record['Yt']['status'] = '1'; $this->record['Yt']['etime'] = $this->time; /*$qry="insert into yt_login(mmm_id , user_id ,sessionToken , status) values ('$mmm_id', '$username' , '$sessionToken', '1')"; $result = mysql_query($qry); */ } } $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); return $httpClient; }
/** * Returns a HTTP client object with the appropriate headers for communicating * with Google using AuthSub authentication. * * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after * it is obtained. The single use token supplied in the URL when redirected * after the user succesfully authenticated to Google is retrieved from the * $_GET['token'] variable. * * @return Zend_Http_Client */ function getAuthSubHttpClient() { global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase; $client = new Zend_Gdata_HttpClient(); if ($_authSubKeyFile != null) { // set the AuthSub key $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true); } if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client); } $client->setAuthSubToken($_SESSION['sessionToken']); return $client; }
} else { if (preg_match('/^<\\/.+>$/', $el)) { $indent -= $level; // closing tag, decrease indent } if ($indent < 0) { $indent += $level; } $pretty[] = str_repeat(' ', $indent) . $el; } } $xml = implode("\n", $pretty); return $html_output ? htmlentities($xml) : $xml; } $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); $client = Zend_Gdata_AuthSub::getHttpClient($sessionToken); $useH9Sandbox = true; $healthService = new Zend_Gdata_Health($client, 'MyGHAppNamev1.0', $useH9Sandbox); $query = new Zend_Gdata_Health_Query(); $query->setDigest("true"); $profileFeed = $healthService->getHealthProfileFeed($query); $entry = $profileFeed->entry[0]; //To print ccr $ccr = $entry->getCcr(); $xmlStr = $ccr->saveXML($ccr); echo '<p>' . xmlpp($xmlStr, true) . '</p>'; // digest=true was set so we only have 1 entry $allergies = $entry->getCcr()->getAllergies(); $conditions = $entry->getCcr()->getConditions(); $immunizations = $entry->getCcr()->getImmunizations(); $lab_results = $entry->getCcr()->getLabResults();
/** * Convenience method to obtain an authenticted Zend_Http_Client object. * * @return Zend_Http_Client An authenticated client. */ function getAuthSubHttpClient() { try { $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not obtain authenticated Http client object. ' . $e->getMessage(); return; } $httpClient->setHeaders('X-GData-Key', 'key=' . $_SESSION['developerKey']); return $httpClient; }
function revokeToken($client) { $sessionToken = $client->getAuthSubToken(); return Zend_Gdata_AuthSub::AuthSubRevokeToken($sessionToken, $client); }
public function getAuthSubHttpClient() { // Security check $this->throwForbiddenUnless(SecurityUtil::checkPermission('IWagendas::', '::', ACCESS_READ)); //global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase; $client = new Zend_Gdata_HttpClient(); if ($_authSubKeyFile != null) { // set the AuthSub key $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true); } if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client); } $client->setAuthSubToken($_SESSION['sessionToken']); return $client; }
/** * Exchanges the given single-use token for a session * token using AuthSubSessionToken, and returns the result. * @param string $token The single-use token from AuthSubRequest * @return string The upgraded (session) token */ function exchangeToken($token) { return Zend_Gdata_AuthSub::getAuthSubSessionToken($token); }
<?php try { $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Token upgrade for ' . $singleUseToken . ' failed : ' . $e->getMessage(); return; } $_SESSION['sessionToken'] = $sessionToken; header('Location: ' . $_SESSION['homeUrl']);
/** * getYouTubeAuthSubHttpClient * * @param string $key the developer key * @param string $token optional user's authenticated session token * * @return Zend_Http_Client An authenticated client. */ function getYouTubeAuthSubHttpClient($key, $token = '') { if ($token == '') { if (isset($_SESSION['youtube_session_token'])) { $token = $_SESSION['youtube_session_token']; } else { print ' <div class="error-alert"> <p>' . T_('Missing or invalid YouTube session token.') . '</p> </div>'; return false; } } try { $httpClient = Zend_Gdata_AuthSub::getHttpClient($token); } catch (Zend_Gdata_App_Exception $e) { print ' <div class="error-alert"> <p>' . T_('Could not connect to YouTube API. Your YouTube session token may be invalid.') . '</p> <p><i>' . $e->getMessage() . '</i></p> </div>'; return false; } $httpClient->setHeaders('X-GData-Key', 'key=' . $key); return $httpClient; }
/** * If there are some discrepancies in the session or user * wants not to connect his/her Google Calendars with ATutor * then this function will securely log out the user. * * @return void */ public function logout() { // Carefully construct this value to avoid application security problems. $php_self = htmlentities(substr($_SERVER['PHP_SELF'], 0, strcspn($_SERVER['PHP_SELF'], "\n\r")), ENT_QUOTES); //Revoke access for the stored token Zend_Gdata_AuthSub::AuthSubRevokeToken($_SESSION['sessionToken']); unset($_SESSION['sessionToken']); //Close this popup window echo "<script>window.opener.location.reload(true);window.close();</script>"; exit; }
<?php require_once __MLC__ . '/google/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_YouTube'); Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoQuery'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_App_Exception'); $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; $nextUrl = 'http://' . $_SERVER['SERVER_NAME'] . __PHP_ASSETS__ . '/youtube/youtubeAuth.php'; $url = Zend_Gdata_AuthSub::getAuthSubTokenUri($nextUrl, $scope, $secure, $session); ?> <a href="<?php _p($url); ?> " target='_blank'> <strong>Click here to authenticate with YouTube</strong> </a>
public function googleAction() { //$this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full'; if (!isset($_SESSION['cal_token'])) { if (isset($_GET['token'])) { // You can convert the single-use token to a session token. $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); // Store the session token in our session. $_SESSION['cal_token'] = $session_token; } else { // Display link to generate single-use token $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], $my_calendar, 0, 1); echo "Click <a href='{$googleUri}'>here</a> " . "to authorize this application."; exit; } } // Create an authenticated HTTP Client to talk to Google. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']); // Create a Gdata object using the authenticated Http Client $cal = new Zend_Gdata_Calendar($client); var_export($cal->getCalendarListFeed()->count()); }
/** * Processes the workflow to authenticate users. * * Uses the _sessionNs session namespace to store the AuthSub session token * after it is obtained. The single use token supplied in the URL when * redirected after the user succesfully authenticated to Google is * retrieved from the token request parameter * * @return void */ public function processPageLoad() { $this->_sessionNs = new Zend_Session_Namespace('GoogleAuthSub'); $token = $this->_request->getParam('token'); if (!$this->_sessionNs->sessionToken) { if (!$token) { $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector'); $redirector->gotoUrl($this->_getAuthSubUrl()); } elseif ($token) { $this->_client = $this->_getAuthSubHttpClient(); $this->_sessionNs->sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($token, $this->_client); $this->_client->setAuthSubToken($this->_sessionNs->sessionToken); } } else { $this->_client = $this->_getAuthSubHttpClient(); $this->_client->setAuthSubToken($this->_sessionNs->sessionToken); } }
/** * Returns a HTTP client object with the appropriate headers for communicating * with Google using AuthSub authentication. * * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after * it is obtained. The single use token supplied in the URL when redirected * after the user succesfully authenticated to Google is retrieved from the * $_GET['token'] variable. * * @return Zend_Http_Client */ function getAuthSubHttpClient() { global $_SESSION, $_GET; if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); } $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); return $client; }
* You should have received a copy of the GNU General Public License * along with GCalendar. If not, see <http://www.gnu.org/licenses/>. * * @author Allon Moritz * @copyright 2007-2010 Allon Moritz * @since 2.2.0 */ defined('_JEXEC') or die('Restricted access'); $mainframe =& JFactory::getApplication(); $absolute_path = $mainframe->getCfg('absolute_path'); ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . JPATH_COMPONENT . DS . 'libraries'); require_once 'Zend' . DS . 'Loader.php'; Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_HttpClient'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); $params =& JComponentHelper::getParams('com_gcalendar'); $domain = $params->get('google_apps_domain'); $u = JFactory::getURI(); $next = JRoute::_($u->toString() . '?option=com_gcalendar&task=' . JRequest::getCmd('nextTask')); $scope = 'http://www.google.com/calendar/feeds/'; $session = true; $secure = false; $hd = ''; if (!empty($domain)) { $hd = '&hd=' . $domain; } $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session, Zend_Gdata_AuthSub::AUTHSUB_REQUEST_URI); echo "<a href=\"" . $authSubUrl . $hd . "\">Please Login to access the calendar data.</a>"; ?>
public function testGetHttpClientProvidesNewClientWhenNullPassed() { $client = Zend_Gdata_AuthSub::getHttpClient($this->token); $this->assertTrue($client instanceof Zend_Gdata_HttpClient); $this->assertEquals($this->token, $client->getAuthSubToken()); }
if (get_magic_quotes_gpc()) { $q = stripslashes($q); } $gdata = new Zend_Gdata_Base($client); $gdata->setQuery($q); $feed = $gdata->getBaseFeed(); } /** * Filter php_self to avoid a security vulnerability. */ $php_self = htmlentities(substr($_SERVER['PHP_SELF'], 0, strcspn($_SERVER['PHP_SELF'], "\n\r")), ENT_QUOTES); /** * Logout and revoke AuthSub token when we are done with it. */ if (isset($_GET['logout'])) { Zend_Gdata_AuthSub::AuthSubRevokeToken($_SESSION['base_token']); unset($_SESSION['base_token']); header('Location: ' . $php_self); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Google Base Demo</title> <style> body{ font-family: Arial; } input,select{font-size: 32px;} </style> </head>
function comment($entry, $comment) { $username = $_SESSION['username']; $query = "select token from user where username='******'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $token = $row['token']; $httpClient = Zend_Gdata_AuthSub::getHttpClient($token); $developerKey = 'AI39si5uCFW5FETweIaPnbNJUP88YvpOtSoy7FSUnYnTFVH4liFKzqWTkndATtgiltByN54tPcVjsScyh3S28P-D4PC4n73alg'; $applicationId = 'EazySubs'; $clientId = 'EazySubs'; $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey); try { $videoEntry = $yt->getVideoEntry($entry); $newComment = $yt->newCommentEntry(); $newComment->content = $yt->newContent()->setText($comment); // post the comment to the comments feed URL for the video $commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl(); $updatedVideoEntry = $yt->insertEntry($newComment, $commentFeedPostUrl, 'Zend_Gdata_YouTube_CommentEntry'); return true; } catch (Exception $e) { return false; } }
public function action_import() { $this->template->content = "Muahhaa"; $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full'; if (!isset($_SESSION['cal_token'])) { if (isset($_GET['token'])) { // You can convert the single-use token to a session token. $session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); // Store the session token in our session. $_SESSION['cal_token'] = $session_token; } else { // Display link to generate single-use token $url = url::site('admin/import', TRUE); $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri($url, $my_calendar, 0, 1); $this->template->content = "Click <a href='{$googleUri}'>here</a> to authorize this application."; return; } } // Create an authenticated HTTP Client to talk to Google. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']); // Create a Gdata object using the authenticated Http Client $this->cal = new Zend_Gdata_Calendar($client); $this->template->content = ""; if (isset($_POST['selectedCalendar'])) { $_SESSION['selectedCal'] = $_POST['selectedCalendar']; } $this->_fetchCalendarCache(); $this->importSelectCal(); if ($_SESSION['selectedCal']) { $this->_fetchEventsCache($_SESSION['selectedCal']); $this->template->content .= View::factory('admin/import_calEvents', array('events' => $_SESSION['eventsCache'][$_SESSION['selectedCal']], 'existingRooms' => ORM::factory('room')->find_all()->as_array())); } }
$entry = new Zend_Gdata_Photos_AlbumEntry(); $entry->setTitle($photos->newTitle($name)); $result = $photos->insertAlbumEntry($entry); if ($result) { return $result; } else { echo "There was an issue with the album creation."; } } /* * ********************************************** If we're signed in we can go ahead and retrieve data * ********************************************** */ set_time_limit('10000'); if (isset($_SESSION['google_token'])) { $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['google_token']); $userInfo = $_SESSION['google_userInfo']; $album_ids = explode(',', $_GET['album_ids']); foreach ($album_ids as $album_id) { $singleAlbum = fetchSingleAlbums($album_id); if (!file_exists(ABSOLUTE_PATH . "/assets/images/archive")) { mkdir(ABSOLUTE_PATH . "/assets/images/archive"); } $filepath = $album_id; if (!file_exists(ABSOLUTE_PATH . "/assets/images/albums/{$filepath}")) { mkdir(ABSOLUTE_PATH . "/assets/images/albums/{$filepath}"); } $result = addAlbum($client, 'Test Album'); $albumId = $result->getGphotoId()->getText(); foreach ($singleAlbum as $photo) { $url = $photo->source;