From 4005971d0557f0f22bb001b035a8ccc22dc73f61 Mon Sep 17 00:00:00 2001 From: Benji Rothman Date: Thu, 30 Jun 2022 16:22:32 -0400 Subject: [PATCH] Throw Exception if OAuth is attempted (#42) Temporary update to throw an exception if OAuth is attempted due to OOB deprecation: https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html#disallowed-oob A new, approved OAuth flow will be added in the future. removed the getToken method and lines 317-324 so we don't demonstrate an unsupported approach + we avoid unreachable code. --- php/ContentSession.php | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/php/ContentSession.php b/php/ContentSession.php index 8893ba1..db0c8a3 100644 --- a/php/ContentSession.php +++ b/php/ContentSession.php @@ -299,29 +299,8 @@ public function getHome() { return rtrim($home, '\\/'); } - private function getToken(Google_Client $client) { - $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); - $client->setScopes('https://www.googleapis.com/auth/content'); - $client->setAccessType('offline'); // So that we get a refresh token - - printf("Visit the following URL and log in:\n\n\t%s\n\n", - $client->createAuthUrl()); - print ('Then type the resulting code here: '); - $code = trim(fgets(STDIN)); - $client->authenticate($code); - - return $client->getAccessToken(); - } - protected function cacheToken(Google_Client $client) { - print (str_repeat('*', 40) . "\n"); - print ("Your token was missing or invalid, fetching a new one\n"); - $token = $this->getToken($client); - $tokenFile = join(DIRECTORY_SEPARATOR, - [$this->configDir, self::OAUTH_TOKEN_FILE_NAME]); - file_put_contents($tokenFile, json_encode($token, JSON_PRETTY_PRINT)); - printf("Token saved to %s\n", $tokenFile); - print (str_repeat('*', 40) . "\n"); + throw new Exception('This example currently only supports the service account flow..'); } /**