How to get a unique user identity when signing in to Gmail using Zend Framework

I implemented oAuth Google using the Zend Framework . All I can do right now is authenticate the user using the gmail id and password , after which I show his Google docs. But how to determine the user, whether he is an old user or a new user.

What is the unique identification provided by Google after entering our site.

thank

$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);}


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']);
+3
source share
1 answer

Google () . Id :

$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
+2

Source: https://habr.com/ru/post/1787672/


All Articles