Skip to content

Commit 345e2f8

Browse files
authored
Merge branch 'main' into fix-release-job
2 parents 8c4b94d + 217104d commit 345e2f8

File tree

10 files changed

+81
-50
lines changed

10 files changed

+81
-50
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
always_check_pr_title: true
2+

.github/workflows/asset-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
matrix:
2323
operating-system: [ ubuntu-latest ]
24-
php: [ "8.0", "8.3" ]
24+
php: [ "8.1", "8.3" ]
2525

2626
name: Upload Release Assets
2727
steps:

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
14+
php: [ "8.1", "8.2", "8.3", "8.4" ]
1515
composer-flags: [""]
1616
include:
17-
- php: "8.0"
17+
- php: "8.1"
1818
composer-flags: "--prefer-lowest "
1919
- php: "8.4"
2020
composer-flags: "--prefer-lowest "

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [2.18.4](https://github.com/googleapis/google-api-php-client/compare/v2.18.3...v2.18.4) (2025-09-29)
4+
5+
6+
### Bug Fixes
7+
8+
* Ensure credentials can be of type FetchAuthTokenInterface ([#2684](https://github.com/googleapis/google-api-php-client/issues/2684)) ([ed70802](https://github.com/googleapis/google-api-php-client/commit/ed70802cc4886ef1f513a2c0b56a8a972db5e7ab))
9+
10+
## [2.18.3](https://github.com/googleapis/google-api-php-client/compare/v2.18.2...v2.18.3) (2025-04-08)
11+
12+
13+
### Bug Fixes
14+
15+
* Convert Finder lazy iterator to array before deletion ([#2663](https://github.com/googleapis/google-api-php-client/issues/2663)) ([c699405](https://github.com/googleapis/google-api-php-client/commit/c6994051af1568359c97d267d9ef34ccbda31387))
16+
317
## [2.18.2](https://github.com/googleapis/google-api-php-client/compare/v2.18.1...v2.18.2) (2024-12-16)
418

519

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "http://developers.google.com/api-client-library/php",
77
"license": "Apache-2.0",
88
"require": {
9-
"php": "^8.0",
9+
"php": "^8.1",
1010
"google/auth": "^1.37",
1111
"google/apiclient-services": "~0.350",
1212
"firebase/php-jwt": "^6.0",

docs/oauth-web.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ After completing the OAuth 2.0 flow, you should be redirected to `http://localho
258258

259259
After the web server receives the authorization code, it can exchange the authorization code for an access token.
260260

261-
To exchange an authorization code for an access token, use the `authenticate` method:
261+
To exchange an authorization code for an access token, use the `fetchAccessTokenWithAuthCode` method:
262262

263263
```php
264-
$client->authenticate($_GET['code']);
264+
$client->fetchAccessTokenWithAuthCode($_GET['code']);
265265
```
266266

267267
You can retrieve the access token with the `getAccessToken` method:
@@ -353,15 +353,15 @@ require_once __DIR__.'/vendor/autoload.php';
353353
session_start();
354354
355355
$client = new Google\Client();
356-
$client->setAuthConfigFile('client_secrets.json');
356+
$client->setAuthConfig('client_secrets.json');
357357
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
358358
$client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY);
359359
360360
if (! isset($_GET['code'])) {
361361
$auth_url = $client->createAuthUrl();
362362
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
363363
} else {
364-
$client->authenticate($_GET['code']);
364+
$client->fetchAccessTokenWithAuthCode($_GET['code']);
365365
$_SESSION['access_token'] = $client->getAccessToken();
366366
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
367367
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
@@ -421,4 +421,4 @@ $client->revokeToken();
421421
422422
**Note:** Following a successful revocation response, it might take some time before the revocation has full effect.
423423
424-
Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see our [Site Policies](https://developers.google.com/terms/site-policies). Java is a registered trademark of Oracle and/or its affiliates.
424+
Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see our [Site Policies](https://developers.google.com/terms/site-policies). Java is a registered trademark of Oracle and/or its affiliates.

src/AuthHandler/Guzzle6AuthHandler.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Google\AuthHandler;
44

5-
use Google\Auth\CredentialsLoader;
65
use Google\Auth\FetchAuthTokenCache;
6+
use Google\Auth\FetchAuthTokenInterface;
77
use Google\Auth\HttpHandler\HttpHandlerFactory;
88
use Google\Auth\Middleware\AuthTokenMiddleware;
99
use Google\Auth\Middleware\ScopedAccessTokenMiddleware;
@@ -28,7 +28,7 @@ public function __construct(?CacheItemPoolInterface $cache = null, array $cacheC
2828

2929
public function attachCredentials(
3030
ClientInterface $http,
31-
CredentialsLoader $credentials,
31+
FetchAuthTokenInterface $credentials,
3232
?callable $tokenCallback = null
3333
) {
3434
// use the provided cache
@@ -40,13 +40,21 @@ public function attachCredentials(
4040
);
4141
}
4242

43-
return $this->attachCredentialsCache($http, $credentials, $tokenCallback);
43+
return $this->attachToHttp($http, $credentials, $tokenCallback);
4444
}
4545

4646
public function attachCredentialsCache(
4747
ClientInterface $http,
4848
FetchAuthTokenCache $credentials,
4949
?callable $tokenCallback = null
50+
) {
51+
return $this->attachToHttp($http, $credentials, $tokenCallback);
52+
}
53+
54+
private function attachToHttp(
55+
ClientInterface $http,
56+
FetchAuthTokenInterface $credentials,
57+
?callable $tokenCallback = null
5058
) {
5159
// if we end up needing to make an HTTP request to retrieve credentials, we
5260
// can use our existing one, but we need to throw exceptions so the error
@@ -63,9 +71,7 @@ public function attachCredentialsCache(
6371
$config['handler']->remove('google_auth');
6472
$config['handler']->push($middleware, 'google_auth');
6573
$config['auth'] = 'google_auth';
66-
$http = new Client($config);
67-
68-
return $http;
74+
return new Client($config);
6975
}
7076

7177
public function attachToken(ClientInterface $http, array $token, array $scopes)

src/Client.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Google\Auth\Credentials\UserRefreshCredentials;
2828
use Google\Auth\CredentialsLoader;
2929
use Google\Auth\FetchAuthTokenCache;
30+
use Google\Auth\FetchAuthTokenInterface;
3031
use Google\Auth\GetUniverseDomainInterface;
3132
use Google\Auth\HttpHandler\HttpHandlerFactory;
3233
use Google\Auth\OAuth2;
@@ -90,7 +91,7 @@ class Client
9091
private $logger;
9192

9293
/**
93-
* @var ?CredentialsLoader $credentials
94+
* @var ?FetchAuthTokenInterface $credentials
9495
*/
9596
private $credentials;
9697

@@ -118,10 +119,10 @@ class Client
118119
* Your Google Cloud client ID found in https://developers.google.com/console
119120
* @type string $client_secret
120121
* Your Google Cloud client secret found in https://developers.google.com/console
121-
* @type string|array|CredentialsLoader $credentials
122+
* @type string|array|FetchAuthTokenInterface $credentials
122123
* Can be a path to JSON credentials or an array representing those
123124
* credentials (@see Google\Client::setAuthConfig), or an instance of
124-
* {@see CredentialsLoader}.
125+
* {@see FetchAuthTokenInterface}.
125126
* @type string|array $scopes
126127
* {@see Google\Client::setScopes}
127128
* @type string $quota_project
@@ -213,7 +214,7 @@ public function __construct(array $config = [])
213214
], $config);
214215

215216
if (!is_null($this->config['credentials'])) {
216-
if ($this->config['credentials'] instanceof CredentialsLoader) {
217+
if ($this->config['credentials'] instanceof FetchAuthTokenInterface) {
217218
$this->credentials = $this->config['credentials'];
218219
} else {
219220
$this->setAuthConfig($this->config['credentials']);
@@ -460,7 +461,8 @@ public function authorize(?ClientInterface $http = null)
460461
$authHandler = $this->getAuthHandler();
461462

462463
// These conditionals represent the decision tree for authentication
463-
// 1. Check if a Google\Auth\CredentialsLoader instance has been supplied via the "credentials" option
464+
// 1. Check if an instance of Google\Auth\FetchAuthTokenInterface has
465+
// been supplied via the "credentials" option
464466
// 2. Check for Application Default Credentials
465467
// 3a. Check for an Access Token
466468
// 3b. If access token exists but is expired, try to refresh it

src/Task/Composer.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,37 @@ public static function cleanup(
3434
) {
3535
$composer = $event->getComposer();
3636
$extra = $composer->getPackage()->getExtra();
37-
$servicesToKeep = isset($extra['google/apiclient-services'])
38-
? $extra['google/apiclient-services']
39-
: [];
40-
if ($servicesToKeep) {
41-
$vendorDir = $composer->getConfig()->get('vendor-dir');
37+
$servicesToKeep = $extra['google/apiclient-services'] ?? [];
38+
if (empty($servicesToKeep)) {
39+
return;
40+
}
41+
$vendorDir = $composer->getConfig()->get('vendor-dir');
42+
$serviceDir = sprintf(
43+
'%s/google/apiclient-services/src/Google/Service',
44+
$vendorDir
45+
);
46+
if (!is_dir($serviceDir)) {
47+
// path for google/apiclient-services >= 0.200.0
4248
$serviceDir = sprintf(
43-
'%s/google/apiclient-services/src/Google/Service',
49+
'%s/google/apiclient-services/src',
4450
$vendorDir
4551
);
46-
if (!is_dir($serviceDir)) {
47-
// path for google/apiclient-services >= 0.200.0
48-
$serviceDir = sprintf(
49-
'%s/google/apiclient-services/src',
50-
$vendorDir
51-
);
52-
}
53-
self::verifyServicesToKeep($serviceDir, $servicesToKeep);
54-
$finder = self::getServicesToRemove($serviceDir, $servicesToKeep);
55-
$filesystem = $filesystem ?: new Filesystem();
56-
if (0 !== $count = count($finder)) {
57-
$event->getIO()->write(
58-
sprintf('Removing %s google services', $count)
59-
);
60-
foreach ($finder as $file) {
61-
$realpath = $file->getRealPath();
62-
$filesystem->remove($realpath);
63-
$filesystem->remove($realpath . '.php');
64-
}
65-
}
52+
}
53+
self::verifyServicesToKeep($serviceDir, $servicesToKeep);
54+
$finder = self::getServicesToRemove($serviceDir, $servicesToKeep);
55+
$filesystem = $filesystem ?: new Filesystem();
56+
$servicesToRemoveCount = $finder->count();
57+
if (0 === $servicesToRemoveCount) {
58+
return;
59+
}
60+
$event->getIO()->write(
61+
sprintf('Removing %d google services', $servicesToRemoveCount)
62+
);
63+
$pathsToRemove = iterator_to_array($finder);
64+
foreach ($pathsToRemove as $pathToRemove) {
65+
$realpath = $pathToRemove->getRealPath();
66+
$filesystem->remove($realpath);
67+
$filesystem->remove($realpath . '.php');
6668
}
6769
}
6870

tests/Google/ClientTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Google\Service\Drive;
2525
use Google\AuthHandler\AuthHandlerFactory;
2626
use Google\Auth\FetchAuthTokenCache;
27-
use Google\Auth\CredentialsLoader;
27+
use Google\Auth\FetchAuthTokenInterface;
2828
use Google\Auth\GCECache;
2929
use Google\Auth\Credentials\GCECredentials;
3030
use GuzzleHttp\Client as GuzzleClient;
@@ -40,6 +40,8 @@
4040
use InvalidArgumentException;
4141
use Exception;
4242
use DomainException;
43+
use Google\Auth\GetUniverseDomainInterface;
44+
use Google\Auth\UpdateMetadataInterface;
4345

4446
class ClientTest extends BaseTest
4547
{
@@ -868,10 +870,12 @@ public function testClientOptions()
868870
$this->assertEquals('some-quota-project', $credentials->getQuotaProject());
869871
}
870872

871-
public function testCredentialsOptionWithCredentialsLoader()
873+
public function testCredentialsOptionWithFetchAuthTokenInterface()
872874
{
873875
$request = null;
874-
$credentials = $this->prophesize('Google\Auth\CredentialsLoader');
876+
$credentials = $this->prophesize(FetchAuthTokenInterface::class)
877+
->willImplement(GetUniverseDomainInterface::class)
878+
->willImplement(UpdateMetadataInterface::class);
875879
$credentials->getCacheKey()
876880
->willReturn('cache-key');
877881
$credentials->getUniverseDomain()
@@ -947,7 +951,8 @@ public function testUniverseDomainMismatch()
947951
'The configured universe domain (example.com) does not match the credential universe domain (foo.com)'
948952
);
949953

950-
$credentials = $this->prophesize(CredentialsLoader::class);
954+
$credentials = $this->prophesize(FetchAuthTokenInterface::class)
955+
->willImplement(GetUniverseDomainInterface::class);
951956
$credentials->getUniverseDomain()
952957
->shouldBeCalledOnce()
953958
->willReturn('foo.com');

0 commit comments

Comments
 (0)