Can I retain a Google apps session token permanently for a specific user who logs into my google app
Posted
by Ali
on Stack Overflow
See other posts from Stack Overflow
or by Ali
Published on 2010-05-04T06:26:10Z
Indexed on
2010/05/04
6:28 UTC
Read the original article
Hit count: 408
Hi guys, is it possible to retain upon authorization a single session token for a user who signs into my gogle application. CUrrently my application seems to every now and then require the user to authenticate into google apps. I think it has to do with session dying out or so. I have the following code:
function getCurrentUrl()
{
global $_SERVER;
$php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0,
strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
$host = $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_PORT'] != '' &&
(($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
$port = ':' . $_SERVER['SERVER_PORT'];
} else {
$port = '';
}
return $protocol . $host . $port . $php_request_uri;
}
function getAuthSubUrl($n=false)
{
$next = $n?$n:getCurrentUrl();
$scope = 'http://docs.google.com/feeds/documents https://www.google.com/calendar/feeds/ https://spreadsheets.google.com/feeds/ https://www.google.com/m8/feeds/ https://mail.google.com/mail/feed/atom/';
$secure = false;
$session = true;
//echo Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session).(isset($_SESSION['domain'])?'&hd='.$_SESSION['domain']:'');
}
function _regenerate_token()
{
global $BASE_URL;
if(!$_SESSION['token'])
{
if(isset($_GET['token'])):
$_SESSION['token'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
return;
else:
_regenerate_sessions();
_redirect(getAuthSubUrl($BASE_URL . '/index.php?'.$_SERVER['QUERY_STRING']));
endif;
}
}
_regenerate_token();
I know I'm doing it all wrong here and I don't know why :( I have a CONSUMER SECRET code but only use it whereever I need to access a google service. However something is wrong with my authentication as the user has to periodically 'grant access to my application' and reauthorise himself... help please
© Stack Overflow or respective owner