小编Kro*_*oll的帖子

Google OAuth2 - isAccessTokenExpired()始终为true

我在我的应用程序中使用OAuth,并且我希望在访问令牌过期时注销用户.

但是当我检查令牌到期时

 $client->isAccessTokenExpired()
Run Code Online (Sandbox Code Playgroud)

它总是返回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();
}
Run Code Online (Sandbox Code Playgroud)

php google-oauth

5
推荐指数
1
解决办法
2836
查看次数

标签 统计

google-oauth ×1

php ×1