Search code examples
phpoauthgoogle-apigoogle-oauthgoogle-api-php-client

Revoke Google Access Token in PHP


As the title reads, I want to revoke a granted access token programatically (in PHP that is). I found this on their website, but can't seem to find a function in the api client library. Is there a clean library function?

EDIT: As pointed out by DaimTo there is a function called revokeToken(). So this code works in PHP (with composer):

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

Solution

  • try

    $client->revokeToken(); 
    

    or

    $client->revokeToken($accesstoken);
    

    Information found by digging around the Google-api-php-Client