diff --git a/.github/workflows/asset-release.yml b/.github/workflows/asset-release.yml index bc4b2bf8d..24a459254 100644 --- a/.github/workflows/asset-release.yml +++ b/.github/workflows/asset-release.yml @@ -3,6 +3,7 @@ name: Add Release Assets on: release: types: [published] + workflow_dispatch: jobs: asset: @@ -10,7 +11,7 @@ jobs: strategy: matrix: operating-system: [ ubuntu-latest ] - php: [ "8.0", "8.3" ] + php: [ "8.1", "8.3" ] name: Upload Release Assets steps: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9f86e493a..ade84792a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,10 +11,10 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ] + php: [ "8.1", "8.2", "8.3", "8.4" ] composer-flags: [""] include: - - php: "8.0" + - php: "8.1" composer-flags: "--prefer-lowest " - php: "8.4" composer-flags: "--prefer-lowest " diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd015477..a0418c111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.18.4](https://github.com/googleapis/google-api-php-client/compare/v2.18.3...v2.18.4) (2025-09-29) + + +### Bug Fixes + +* 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)) + ## [2.18.3](https://github.com/googleapis/google-api-php-client/compare/v2.18.2...v2.18.3) (2025-04-08) diff --git a/composer.json b/composer.json index abacbe84b..240f9d1c8 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "http://developers.google.com/api-client-library/php", "license": "Apache-2.0", "require": { - "php": "^8.0", + "php": "^8.1", "google/auth": "^1.37", "google/apiclient-services": "~0.350", "firebase/php-jwt": "^6.0", diff --git a/docs/oauth-web.md b/docs/oauth-web.md index 904745ed5..18bc5e32b 100644 --- a/docs/oauth-web.md +++ b/docs/oauth-web.md @@ -353,7 +353,7 @@ require_once __DIR__.'/vendor/autoload.php'; session_start(); $client = new Google\Client(); -$client->setAuthConfigFile('client_secrets.json'); +$client->setAuthConfig('client_secrets.json'); $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php'); $client->addScope(Google\Service\Drive::DRIVE_METADATA_READONLY); @@ -421,4 +421,4 @@ $client->revokeToken(); **Note:** Following a successful revocation response, it might take some time before the revocation has full effect. -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. \ No newline at end of file +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. diff --git a/src/AuthHandler/Guzzle6AuthHandler.php b/src/AuthHandler/Guzzle6AuthHandler.php index 352cf915c..05fe1b2b9 100644 --- a/src/AuthHandler/Guzzle6AuthHandler.php +++ b/src/AuthHandler/Guzzle6AuthHandler.php @@ -2,8 +2,8 @@ namespace Google\AuthHandler; -use Google\Auth\CredentialsLoader; use Google\Auth\FetchAuthTokenCache; +use Google\Auth\FetchAuthTokenInterface; use Google\Auth\HttpHandler\HttpHandlerFactory; use Google\Auth\Middleware\AuthTokenMiddleware; use Google\Auth\Middleware\ScopedAccessTokenMiddleware; @@ -28,7 +28,7 @@ public function __construct(?CacheItemPoolInterface $cache = null, array $cacheC public function attachCredentials( ClientInterface $http, - CredentialsLoader $credentials, + FetchAuthTokenInterface $credentials, ?callable $tokenCallback = null ) { // use the provided cache @@ -40,13 +40,21 @@ public function attachCredentials( ); } - return $this->attachCredentialsCache($http, $credentials, $tokenCallback); + return $this->attachToHttp($http, $credentials, $tokenCallback); } public function attachCredentialsCache( ClientInterface $http, FetchAuthTokenCache $credentials, ?callable $tokenCallback = null + ) { + return $this->attachToHttp($http, $credentials, $tokenCallback); + } + + private function attachToHttp( + ClientInterface $http, + FetchAuthTokenInterface $credentials, + ?callable $tokenCallback = null ) { // if we end up needing to make an HTTP request to retrieve credentials, we // can use our existing one, but we need to throw exceptions so the error @@ -63,9 +71,7 @@ public function attachCredentialsCache( $config['handler']->remove('google_auth'); $config['handler']->push($middleware, 'google_auth'); $config['auth'] = 'google_auth'; - $http = new Client($config); - - return $http; + return new Client($config); } public function attachToken(ClientInterface $http, array $token, array $scopes) diff --git a/src/Client.php b/src/Client.php index edfb1f83e..33147925f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -27,6 +27,7 @@ use Google\Auth\Credentials\UserRefreshCredentials; use Google\Auth\CredentialsLoader; use Google\Auth\FetchAuthTokenCache; +use Google\Auth\FetchAuthTokenInterface; use Google\Auth\GetUniverseDomainInterface; use Google\Auth\HttpHandler\HttpHandlerFactory; use Google\Auth\OAuth2; @@ -90,7 +91,7 @@ class Client private $logger; /** - * @var ?CredentialsLoader $credentials + * @var ?FetchAuthTokenInterface $credentials */ private $credentials; @@ -118,10 +119,10 @@ class Client * Your Google Cloud client ID found in https://developers.google.com/console * @type string $client_secret * Your Google Cloud client secret found in https://developers.google.com/console - * @type string|array|CredentialsLoader $credentials + * @type string|array|FetchAuthTokenInterface $credentials * Can be a path to JSON credentials or an array representing those * credentials (@see Google\Client::setAuthConfig), or an instance of - * {@see CredentialsLoader}. + * {@see FetchAuthTokenInterface}. * @type string|array $scopes * {@see Google\Client::setScopes} * @type string $quota_project @@ -213,7 +214,7 @@ public function __construct(array $config = []) ], $config); if (!is_null($this->config['credentials'])) { - if ($this->config['credentials'] instanceof CredentialsLoader) { + if ($this->config['credentials'] instanceof FetchAuthTokenInterface) { $this->credentials = $this->config['credentials']; } else { $this->setAuthConfig($this->config['credentials']); @@ -460,7 +461,8 @@ public function authorize(?ClientInterface $http = null) $authHandler = $this->getAuthHandler(); // These conditionals represent the decision tree for authentication - // 1. Check if a Google\Auth\CredentialsLoader instance has been supplied via the "credentials" option + // 1. Check if an instance of Google\Auth\FetchAuthTokenInterface has + // been supplied via the "credentials" option // 2. Check for Application Default Credentials // 3a. Check for an Access Token // 3b. If access token exists but is expired, try to refresh it diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index 4e53e34b4..4a336705d 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -24,7 +24,7 @@ use Google\Service\Drive; use Google\AuthHandler\AuthHandlerFactory; use Google\Auth\FetchAuthTokenCache; -use Google\Auth\CredentialsLoader; +use Google\Auth\FetchAuthTokenInterface; use Google\Auth\GCECache; use Google\Auth\Credentials\GCECredentials; use GuzzleHttp\Client as GuzzleClient; @@ -40,6 +40,8 @@ use InvalidArgumentException; use Exception; use DomainException; +use Google\Auth\GetUniverseDomainInterface; +use Google\Auth\UpdateMetadataInterface; class ClientTest extends BaseTest { @@ -868,10 +870,12 @@ public function testClientOptions() $this->assertEquals('some-quota-project', $credentials->getQuotaProject()); } - public function testCredentialsOptionWithCredentialsLoader() + public function testCredentialsOptionWithFetchAuthTokenInterface() { $request = null; - $credentials = $this->prophesize('Google\Auth\CredentialsLoader'); + $credentials = $this->prophesize(FetchAuthTokenInterface::class) + ->willImplement(GetUniverseDomainInterface::class) + ->willImplement(UpdateMetadataInterface::class); $credentials->getCacheKey() ->willReturn('cache-key'); $credentials->getUniverseDomain() @@ -947,7 +951,8 @@ public function testUniverseDomainMismatch() 'The configured universe domain (example.com) does not match the credential universe domain (foo.com)' ); - $credentials = $this->prophesize(CredentialsLoader::class); + $credentials = $this->prophesize(FetchAuthTokenInterface::class) + ->willImplement(GetUniverseDomainInterface::class); $credentials->getUniverseDomain() ->shouldBeCalledOnce() ->willReturn('foo.com');