本文介绍了Google OAuth2-isAccessTokenExpired()始终为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在应用程序中使用OAuth,并且要在访问令牌到期时注销用户.
I use OAuth in my application and I want log out the user when the access token is expired.
但是当我使用来检查令牌到期时
But when I checked the token expiration with
$client->isAccessTokenExpired()
它总是返回1.
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (!isset($_SESSION['token'])) {
$authUrl = $client->createAuthUrl();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
$service = new Google_Service_Calendar($client);
$oauth2 = new Google_Service_Oauth2($client);
$userinfo = $oauth2->userinfo->get();
$emailUser = $userinfo->getEmail();
$_SESSION['emailUser'] = $userinfo->getEmail();
}
推荐答案
您可能在运行$client->setAccessToken();
之前检查了到期时间.让我们看看您要检查到期时间的代码.
You probably checking the expiration before running $client->setAccessToken();
. Let us see the code where you are checking the expiration.
这篇关于Google OAuth2-isAccessTokenExpired()始终为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!