时间:2021-07-01 10:21:17 帮助过:42人阅读
测试地址: http://www.euask.com/oauth/google.php
setAuthConfigFile('client_secrets.json');
$client->setRedirectUri('http://www.euask.com/oauth/google.php');
$client->setScopes(array(
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.me'
));
// $client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$plus = new Google_Service_Oauth2($client);
if (isset($_REQUEST['logout'])) {
session_unset();
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://www.euask.com/oauth/google.php';
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$me = $plus->userinfo->get();
$id = $me['id'];
$name = $me['givenName'];
$email = $me['email'];
$profile_image_url = $me['picture'];
} else {
$auth_url = $client->createAuthUrl();
}
?>
";
print "Name: {$name}
";
print "Email: {$email}
";
print "Image: {$profile_image_url}
";
echo "Sign out";
}
?>
异常描述
我使用帐号 A 登录授权以后,获取到帐号 A 的信息,然后退出。
再使用另一个帐号 B 登陆授权以后,获取的信息依然是帐号 A 的信息。
但过上一段时间(无法确定多久时间),再使用帐号 B 登陆授权,可以获取帐号 B 的信息,再退出。
再使用帐号 A 登陆,获取的信息依然是帐号 B 的信息,这是怎么一回事情啊?
测试地址: http://www.euask.com/oauth/google.php
setAuthConfigFile('client_secrets.json');
$client->setRedirectUri('http://www.euask.com/oauth/google.php');
$client->setScopes(array(
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/plus.me'
));
// $client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$plus = new Google_Service_Oauth2($client);
if (isset($_REQUEST['logout'])) {
session_unset();
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://www.euask.com/oauth/google.php';
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$me = $plus->userinfo->get();
$id = $me['id'];
$name = $me['givenName'];
$email = $me['email'];
$profile_image_url = $me['picture'];
} else {
$auth_url = $client->createAuthUrl();
}
?>
";
print "Name: {$name}
";
print "Email: {$email}
";
print "Image: {$profile_image_url}
";
echo "Sign out";
}
?>