How to Get User unique identification upon Gmail login using Zend Framework
I had implemented oAuth Google using Zend Framework. All i can do right now is a user is authenticating using their gmail id and password and after that i am displaying his google Docs. But how to identify a user whether he is a old user or new user.
What is the unique Identification Google is providing after login in our website.
Thank You
$consumer = new Zend_Oauth_Consumer($oauthOptions);
if (!isset($_SESSION['REQUEST_TOKEN'])) {
$_SESSION['REQUEST_TOKEN'] = serialize($consumer->getRequestToken(array('scope' => implode(' ', $SCOPES))));
$approvalUrl = $consumer->getRedirectUrl(array('hd' => 'default'));
echo "<a href=\"$approvalUrl\"><H2>LOGIN WITH GOOGLE</H2></a>";
exit(0)开发者_如何学JAVA;}
if (!isset($_SESSION['ACCESS_TOKEN'])) {
if (!empty($_GET) && isset($_SESSION['REQUEST_TOKEN'])) {
$_SESSION['ACCESS_TOKEN'] = serialize($consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN'])));}
}}
$accessToken = unserialize($_SESSION['ACCESS_TOKEN']);unset($_SESSION['REQUEST_TOKEN']);unset($_SESSION['ACCESS_TOKEN']);
You can store the returned ID from Google in a database and when authenticated (again) search for it. Get the Id like this:
$result = Zend_Auth::getInstance()->authenticate($adapter);
if ($result->isValid()) {
$identity = Zend_Auth::getInstance()->getIdentity();
// Do a database query on your users table looking for this $identity. If exists, they're logging back in
精彩评论