Skip to content

Commit

Permalink
Throw Exception if OAuth is attempted (#42)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brothman authored Jun 30, 2022
1 parent 053bc55 commit 4005971
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions php/ContentSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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..');
}

/**
Expand Down

0 comments on commit 4005971

Please sign in to comment.