在 PHP 中撤销 Google 访问令牌
Revoke Google Access Token in PHP
如标题所示,我想以编程方式撤销授予的访问令牌(在 PHP 中)。我在 their website, but can't seem to find a function in the api client library 上找到了这个。有干净的库函数吗?
编辑:
正如 DaimTo 所指出的,有一个名为 revokeToken() 的函数。所以这段代码适用于 PHP (与作曲家):
require_once "vendor/autoload.php";
$client = new Google_Client();
$client->setApplicationName(GOOGLE_APP_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->revokeToken($access_token);
尝试
$client->revokeToken();
或
$client->revokeToken($accesstoken);
找到的信息
<a href="logout.php">Logout</a>
/** logout file **/
<?php
require_once __DIR__ . '/vendor/autoload.php';
session_start();
$accesstoken=$_SESSION['access_token'];
//Unset token and user data from session
unset($_SESSION['access_token']);
unset($_SESSION['userData']);
//Reset OAuth access token
$client = new Google_Client();
//$client->revokeToken();
$client->revokeToken($accesstoken);
//Destroy entire session
session_destroy();
//Redirect to homepage
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/googlelogin/index.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
?>
如标题所示,我想以编程方式撤销授予的访问令牌(在 PHP 中)。我在 their website, but can't seem to find a function in the api client library 上找到了这个。有干净的库函数吗?
编辑: 正如 DaimTo 所指出的,有一个名为 revokeToken() 的函数。所以这段代码适用于 PHP (与作曲家):
require_once "vendor/autoload.php";
$client = new Google_Client();
$client->setApplicationName(GOOGLE_APP_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->revokeToken($access_token);
尝试
$client->revokeToken();
或
$client->revokeToken($accesstoken);
找到的信息
<a href="logout.php">Logout</a>
/** logout file **/
<?php
require_once __DIR__ . '/vendor/autoload.php';
session_start();
$accesstoken=$_SESSION['access_token'];
//Unset token and user data from session
unset($_SESSION['access_token']);
unset($_SESSION['userData']);
//Reset OAuth access token
$client = new Google_Client();
//$client->revokeToken();
$client->revokeToken($accesstoken);
//Destroy entire session
session_destroy();
//Redirect to homepage
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/googlelogin/index.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
?>