Revoke OAuth token using API

1,966 views
Skip to first unread message

Tomas Rimkus

unread,
Jan 22, 2016, 8:48:45 AM1/22/16
to AdWords API Forum
Assuming some user gave access to his MCC account using OAuth token, is there a way to revoke that token by using some Google API request? I know that the user can go to his "Connected apps and sites" in his account and revoke access there but I would like to have an option to do that using our system.

PS: I saw the thread from 2012 which says it's not possible, but maybe sth changed since then.

Tomas Rimkus

unread,
Jan 22, 2016, 10:07:48 AM1/22/16
to AdWords API Forum
Apparently AdWords API client libraries don't provide the functionality but it's possible by making a simple http POST request to https://accounts.google.com/o/oauth2/revoke?token=YOUR_REFRESH_TOKEN . Here is how it's implemented in the generic google API client library: https://github.com/google/google-api-php-client/blob/master/src/Google/AccessToken/Revoke.php

Aine Hickey

unread,
May 31, 2016, 11:21:48 AM5/31/16
to AdWords API Forum
Thanks Tomas. I had the same issue, but the code is slightly different.
You're answer set me in the right direction.

For anyone else who has this problem, this is what I did.

Add library to composer:
"google/apiclient": "1.0.*@beta"

Code:
$client = new \Google_Client();
$client->setApplicationName('xxx');
$client->setDeveloperKey('xxx');

$oauth2 = new \Google_Auth_OAuth2($client);
$result = $oauth2->revokeToken('xxx'); // Access or refresh token

Nick Harris

unread,
Feb 15, 2017, 10:21:34 AM2/15/17
to AdWords API Forum
Same issue here too, but had to modify Aine's method a bit to get it to work:
Add library to composer:
"google/apiclient": "^2.0"

Code:
        $client = new \Google_Client();
        $client->setAuthConfig('PATH_TO_JSON_FILE')); // JSON file in Google dev console under credentials
        $client->fetchAccessTokenWithRefreshToken($refreshToken); //        
        $revoke = $client->revokeToken(); // returns true if it worked
Reply all
Reply to author
Forward
0 new messages