From 63d3a595d42260983ad2cfd48f40063078600cdd Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Feb 2024 13:55:35 -0800 Subject: [PATCH 01/11] feat: add universe domain support --- composer.json | 2 +- src/Client.php | 28 ++++++++++++++++++++++++++- src/Service.php | 4 ++++ src/Service/Resource.php | 16 ++++++++------- tests/Google/ClientTest.php | 12 ++++++++++++ tests/Google/Service/ResourceTest.php | 1 + 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 8d8aa95fc..f0c10955e 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "require": { "php": "^7.4|^8.0", - "google/auth": "^1.33", + "google/auth": "dev-add-universe-domain-cache as 1.39", "google/apiclient-services": "~0.200", "firebase/php-jwt": "~6.0", "monolog/monolog": "^2.9||^3.0", diff --git a/src/Client.php b/src/Client.php index 31b3f1d5f..5fef81fdc 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\GetUniverseDomainInterface; use Google\Auth\HttpHandler\HttpHandlerFactory; use Google\Auth\OAuth2; use Google\AuthHandler\AuthHandlerFactory; @@ -176,7 +177,10 @@ public function __construct(array $config = []) // Setting api_format_v2 will return more detailed error messages // from certain APIs. - 'api_format_v2' => false + 'api_format_v2' => false, + + // Setting the universe domain will change the + 'universe_domain' => GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN, ], $config); if (!is_null($this->config['credentials'])) { @@ -428,6 +432,7 @@ public function authorize(ClientInterface $http = null) // 3b. If access token exists but is expired, try to refresh it // 4. Check for API Key if ($this->credentials) { + $this->checkUniverseDomain($this->credentials); return $authHandler->attachCredentials( $http, $this->credentials, @@ -437,6 +442,7 @@ public function authorize(ClientInterface $http = null) if ($this->isUsingApplicationDefaultCredentials()) { $credentials = $this->createApplicationDefaultCredentials(); + $this->checkUniverseDomain($credentials); return $authHandler->attachCredentialsCache( $http, $credentials, @@ -452,6 +458,7 @@ public function authorize(ClientInterface $http = null) $scopes, $token['refresh_token'] ); + $this->checkUniverseDomain($credentials); return $authHandler->attachCredentials( $http, $credentials, @@ -1297,4 +1304,23 @@ private function createUserRefreshCredentials($scope, $refreshToken) return new UserRefreshCredentials($scope, $creds); } + + private function checkUniverseDomain($credentials) + { + $credentialsUniverse = $credentials instanceof GetUniverseDomainInterface + ? $credentials->getUniverseDomain() + : GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN; + if ($credentialsUniverse !== $this->getUniverseDomain()) { + throw new DomainException(sprintf( + 'The configured universe domain (%s) does not match the credential universe domain (%s)', + $this->getUniverseDomain(), + $credentialsUniverse + )); + } + } + + public function getUniverseDomain() + { + return $this->config['universe_domain']; + } } diff --git a/src/Service.php b/src/Service.php index c97ee9d4f..2c6788b98 100644 --- a/src/Service.php +++ b/src/Service.php @@ -23,7 +23,11 @@ class Service { public $batchPath; + /** + * @deprecated use $rootUrlTemplate instead + */ public $rootUrl; + public $rootUrlTemplate; public $version; public $servicePath; public $serviceName; diff --git a/src/Service/Resource.php b/src/Service/Resource.php index ecf402b18..edc3a36ee 100644 --- a/src/Service/Resource.php +++ b/src/Service/Resource.php @@ -45,8 +45,8 @@ class Resource 'prettyPrint' => ['type' => 'string', 'location' => 'query'], ]; - /** @var string $rootUrl */ - private $rootUrl; + /** @var string $rootUrlTemplate */ + private $rootUrlTemplate; /** @var \Google\Client $client */ private $client; @@ -65,7 +65,7 @@ class Resource public function __construct($service, $serviceName, $resourceName, $resource) { - $this->rootUrl = $service->rootUrl; + $this->rootUrlTemplate = $service->rootUrlTemplate ?? $service->rootUrl; $this->client = $service->getClient(); $this->servicePath = $service->servicePath; $this->serviceName = $serviceName; @@ -268,12 +268,14 @@ public function createRequestUri($restPath, $params) $requestUrl = $this->servicePath . $restPath; } - // code for leading slash - if ($this->rootUrl) { - if ('/' !== substr($this->rootUrl, -1) && '/' !== substr($requestUrl, 0, 1)) { + if ($this->rootUrlTemplate) { + // code for universe domain + $rootUrl = str_replace('UNIVERSE_DOMAIN', $this->client->getUniverseDomain(), $this->rootUrlTemplate); + // code for leading slash + if ('/' !== substr($rootUrl, -1) && '/' !== substr($requestUrl, 0, 1)) { $requestUrl = '/' . $requestUrl; } - $requestUrl = $this->rootUrl . $requestUrl; + $requestUrl = $rootUrl . $requestUrl; } $uriTemplateVars = []; $queryVars = []; diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index 94ce8b876..51d10d06b 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -25,6 +25,7 @@ use Google\AuthHandler\AuthHandlerFactory; use Google\Auth\FetchAuthTokenCache; use Google\Auth\GCECache; +use Google\Auth\Credentials\GCECredentials; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; @@ -689,11 +690,20 @@ public function testOnGceCacheAndCacheOptions() $mockCacheItem->get() ->shouldBeCalledTimes(1) ->willReturn(true); + $mockUniverseDomainCacheItem = $this->prophesize(CacheItemInterface::class); + $mockUniverseDomainCacheItem->isHit() + ->willReturn(true); + $mockUniverseDomainCacheItem->get() + ->shouldBeCalledTimes(1) + ->willReturn('googleapis.com'); $mockCache = $this->prophesize(CacheItemPoolInterface::class); $mockCache->getItem($prefix . GCECache::GCE_CACHE_KEY) ->shouldBeCalledTimes(1) ->willReturn($mockCacheItem->reveal()); + $mockCache->getItem(GCECredentials::cacheKey . 'universe_domain') + ->shouldBeCalledTimes(1) + ->willReturn($mockUniverseDomainCacheItem->reveal()); $client = new Client(['cache_config' => $cacheConfig]); $client->setCache($mockCache->reveal()); @@ -849,6 +859,8 @@ public function testCredentialsOptionWithCredentialsLoader() $credentials = $this->prophesize('Google\Auth\CredentialsLoader'); $credentials->getCacheKey() ->willReturn('cache-key'); + $credentials->getUniverseDomain() + ->willReturn('googleapis.com'); // Ensure the access token provided by our credentials loader is used $credentials->updateMetadata([], null, Argument::any()) diff --git a/tests/Google/Service/ResourceTest.php b/tests/Google/Service/ResourceTest.php index 17000880a..fb8aaa2c9 100644 --- a/tests/Google/Service/ResourceTest.php +++ b/tests/Google/Service/ResourceTest.php @@ -59,6 +59,7 @@ public function setUp(): void $this->client->getLogger()->willReturn($logger->reveal()); $this->client->shouldDefer()->willReturn(true); $this->client->getHttpClient()->willReturn(new GuzzleClient()); + $this->client->getUniverseDomain()->willReturn('googleapis.com'); $this->service = new TestService($this->client->reveal()); } From b28eeabc0936ce5251894379b2971e2f82091cc5 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Feb 2024 07:56:59 -0800 Subject: [PATCH 02/11] update services dep --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f0c10955e..927af27ac 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": "^7.4|^8.0", "google/auth": "dev-add-universe-domain-cache as 1.39", - "google/apiclient-services": "~0.200", + "google/apiclient-services": "dev-universe-domain as 0.340", "firebase/php-jwt": "~6.0", "monolog/monolog": "^2.9||^3.0", "phpseclib/phpseclib": "^3.0.34", From 6de828e33ddd81f73487224eb5a77ad8365231e0 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Feb 2024 08:37:17 -0800 Subject: [PATCH 03/11] add tests --- tests/Google/ClientTest.php | 19 ++++++++++++ tests/Google/Service/ResourceTest.php | 42 +++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index 51d10d06b..81ea7525e 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -24,6 +24,7 @@ use Google\Service\Drive; use Google\AuthHandler\AuthHandlerFactory; use Google\Auth\FetchAuthTokenCache; +use Google\Auth\CredentialsLoader; use Google\Auth\GCECache; use Google\Auth\Credentials\GCECredentials; use GuzzleHttp\Client as GuzzleClient; @@ -38,6 +39,7 @@ use ReflectionMethod; use InvalidArgumentException; use Exception; +use DomainException; class ClientTest extends BaseTest { @@ -925,4 +927,21 @@ public function testQueryParamsForAuthUrl() ]); $this->assertStringContainsString('&enable_serial_consent=true', $authUrl1); } + public function testUniverseDomainMismatch() + { + $this->expectException(DomainException::class); + $this->expectExceptionMessage( + 'The configured universe domain (example.com) does not match the credential universe domain (foo.com)' + ); + + $credentials = $this->prophesize(CredentialsLoader::class); + $credentials->getUniverseDomain() + ->shouldBeCalledOnce() + ->willReturn('foo.com'); + $client = new Client([ + 'universe_domain' => 'example.com', + 'credentials' => $credentials->reveal(), + ]); + $client->authorize(); + } } diff --git a/tests/Google/Service/ResourceTest.php b/tests/Google/Service/ResourceTest.php index fb8aaa2c9..86e0bef24 100644 --- a/tests/Google/Service/ResourceTest.php +++ b/tests/Google/Service/ResourceTest.php @@ -35,10 +35,11 @@ class TestService extends \Google\Service { - public function __construct(Client $client) + public function __construct(Client $client, $rootUrl = null) { parent::__construct($client); - $this->rootUrl = "https://test.example.com"; + $this->rootUrl = $rootUrl ?: "https://test.example.com"; + $this->rootUrlTemplate = $rootUrl ?: "https://test.UNIVERSE_DOMAIN"; $this->servicePath = ""; $this->version = "v1beta1"; $this->serviceName = "test"; @@ -59,7 +60,7 @@ public function setUp(): void $this->client->getLogger()->willReturn($logger->reveal()); $this->client->shouldDefer()->willReturn(true); $this->client->getHttpClient()->willReturn(new GuzzleClient()); - $this->client->getUniverseDomain()->willReturn('googleapis.com'); + $this->client->getUniverseDomain()->willReturn('example.com'); $this->service = new TestService($this->client->reveal()); } @@ -107,6 +108,37 @@ public function testCall() $this->assertFalse($request->hasHeader('Content-Type')); } + public function testCallWithUniverseDomainTemplate() + { + $client = $this->prophesize(Client::class); + $logger = $this->prophesize("Monolog\Logger"); + $this->client->getLogger()->willReturn($logger->reveal()); + $this->client->shouldDefer()->willReturn(true); + $this->client->getHttpClient()->willReturn(new GuzzleClient()); + $this->client->getUniverseDomain()->willReturn('example-universe-domain.com'); + + $this->service = new TestService($this->client->reveal()); + + $resource = new GoogleResource( + $this->service, + "test", + "testResource", + [ + "methods" => [ + "testMethod" => [ + "parameters" => [], + "path" => "method/path", + "httpMethod" => "POST", + ] + ] + ] + ); + $request = $resource->call("testMethod", [[]]); + $this->assertEquals("https://test.example-universe-domain.com/method/path", (string) $request->getUri()); + $this->assertEquals("POST", $request->getMethod()); + $this->assertFalse($request->hasHeader('Content-Type')); + } + public function testCallWithPostBody() { $resource = new GoogleResource( @@ -131,9 +163,9 @@ public function testCallWithPostBody() public function testCallServiceDefinedRoot() { - $this->service->rootUrl = "https://sample.example.com"; + $service = new TestService($this->client->reveal(), "https://sample.example.com"); $resource = new GoogleResource( - $this->service, + $service, "test", "testResource", [ From bb02b39a105b61b02dd043334d5b3f3515b1ff21 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Feb 2024 13:51:36 -0800 Subject: [PATCH 04/11] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 927af27ac..23aaf3a81 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "require": { "php": "^7.4|^8.0", - "google/auth": "dev-add-universe-domain-cache as 1.39", + "google/auth": "^1.37", "google/apiclient-services": "dev-universe-domain as 0.340", "firebase/php-jwt": "~6.0", "monolog/monolog": "^2.9||^3.0", From 5623323a2e551a08f6c402911527dcf6a3fc43ea Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 22 Feb 2024 17:55:08 -0500 Subject: [PATCH 05/11] update documentation regarding setting API key and access token directly --- src/Client.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5fef81fdc..3105fc6cb 100644 --- a/src/Client.php +++ b/src/Client.php @@ -136,6 +136,10 @@ public function __construct(array $config = []) // Simple API access key, also from the API console. Ensure you get // a Server key, and not a Browser key. + // **NOTE:** The universe domain is assumed to be "googleapis.com" unless + // explicitly set. When setting an API ley directly via this option, there + // is no way to verify the universe domain. Be sure to set the + // "universe_domain" option if "googleapis.com" is not intended. 'developer_key' => '', // For use with Google Cloud Platform @@ -179,7 +183,8 @@ public function __construct(array $config = []) // from certain APIs. 'api_format_v2' => false, - // Setting the universe domain will change the + // Setting the universe domain will change the default rootUrl of the service. + // The universe domain is assumed to be "googleapis.com" if not set explicitly. 'universe_domain' => GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN, ], $config); @@ -511,6 +516,11 @@ public function isUsingApplicationDefaultCredentials() * as calling `clear()` will remove all cache items, including any items not * related to Google API PHP Client.) * + * **NOTE:** The universe domain is assumed to be "googleapis.com" unless + * explicitly set. When setting an access token directly via this method, there + * is no way to verify the universe domain. Be sure to set the "universe_domain" + * option if "googleapis.com" is not intended. + * * @param string|array $token * @throws InvalidArgumentException */ From 9304048f5c92675a3a305fd5d4310a00cab137cc Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Feb 2024 10:49:55 -0800 Subject: [PATCH 06/11] chore: fix client phpdoc --- src/Client.php | 99 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/Client.php b/src/Client.php index 31b3f1d5f..046670551 100644 --- a/src/Client.php +++ b/src/Client.php @@ -105,47 +105,84 @@ class Client /** * Construct the Google Client. * - * @param array $config + * @param array $config { + * An array of required and optional arguments. + * + * @type string $application_name + * The name of your application + * @type string $base_path + * The base URL for the service. This is only accounted for when calling + * {@see Client::authorize()} directly. + * @type string $client_id + * 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 + * Can be a path to JSON credentials or an array representing those + * credentials (@see Google\Client::setAuthConfig), or an instance of + * {@see CredentialsLoader}. + * @type string|array $scopes + * {@see Google\Client::setScopes} + * @type string $quota_project + * Sets X-Goog-User-Project, which specifies a user project to bill + * for access charges associated with the request. + * @type string $redirect_uri + * @type string $state + * @type string $developer_key + * Simple API access key, also from the API console. Ensure you get + * a Server key, and not a Browser key. + * @type bool $use_application_default_credentials + * For use with Google Cloud Platform + * fetch the ApplicationDefaultCredentials, if applicable + * {@see https://developers.google.com/identity/protocols/application-default-credentials} + * @type string $signing_key + * @type string $signing_algorithm + * @type string $subject + * @type string $hd + * @type string $prompt + * @type string $openid + * @type bool $include_granted_scopes + * @type string $login_hint + * @type string $request_visible_actions + * @type string $access_type + * @type string $approval_prompt + * @type array $retry + * Task Runner retry configuration + * {@see \Google\Task\Runner} + * @type array $retry_map + * @type CacheItemPoolInterface $cache + * Cache class implementing {@see CacheItemPoolInterface}. Defaults + * to {@see MemoryCacheItemPool}. + * @type array $cache_config + * Cache config for downstream auth caching. + * @type callable $token_callback + * Function to be called when an access token is fetched. Follows + * the signature `function (string $cacheKey, string $accessToken)`. + * @type \Firebase\JWT $jwt + * Service class used in {@see Client::verifyIdToken()}. Explicitly + * pass this in to avoid setting {@see \Firebase\JWT::$leeway} + * @type bool $api_format_v2 + * Setting api_format_v2 will return more detailed error messages + * from certain APIs. + * } */ public function __construct(array $config = []) { $this->config = array_merge([ 'application_name' => '', - - // Don't change these unless you're working against a special development - // or testing environment. 'base_path' => self::API_BASE_PATH, - - // https://developers.google.com/console 'client_id' => '', 'client_secret' => '', - - // Can be a path to JSON credentials or an array representing those - // credentials (@see Google\Client::setAuthConfig), or an instance of - // Google\Auth\CredentialsLoader. 'credentials' => null, - // @see Google\Client::setScopes 'scopes' => null, - // Sets X-Goog-User-Project, which specifies a user project to bill - // for access charges associated with the request 'quota_project' => null, - 'redirect_uri' => null, 'state' => null, - - // Simple API access key, also from the API console. Ensure you get - // a Server key, and not a Browser key. 'developer_key' => '', - - // For use with Google Cloud Platform - // fetch the ApplicationDefaultCredentials, if applicable - // @see https://developers.google.com/identity/protocols/application-default-credentials 'use_application_default_credentials' => false, 'signing_key' => null, 'signing_algorithm' => null, 'subject' => null, - - // Other OAuth2 parameters. 'hd' => '', 'prompt' => '', 'openid.realm' => '', @@ -154,28 +191,12 @@ public function __construct(array $config = []) 'request_visible_actions' => '', 'access_type' => 'online', 'approval_prompt' => 'auto', - - // Task Runner retry configuration - // @see Google\Task\Runner 'retry' => [], 'retry_map' => null, - - // Cache class implementing Psr\Cache\CacheItemPoolInterface. - // Defaults to Google\Auth\Cache\MemoryCacheItemPool. 'cache' => null, - // cache config for downstream auth caching 'cache_config' => [], - - // function to be called when an access token is fetched - // follows the signature function ($cacheKey, $accessToken) 'token_callback' => null, - - // Service class used in Google\Client::verifyIdToken. - // Explicitly pass this in to avoid setting JWT::$leeway 'jwt' => null, - - // Setting api_format_v2 will return more detailed error messages - // from certain APIs. 'api_format_v2' => false ], $config); From a4a811a0e0cde0b90f58314bca3fd661b47845f0 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Feb 2024 16:54:04 -0700 Subject: [PATCH 07/11] undeprecate root url --- src/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service.php b/src/Service.php index 2c6788b98..9909a87f4 100644 --- a/src/Service.php +++ b/src/Service.php @@ -24,7 +24,7 @@ class Service { public $batchPath; /** - * @deprecated use $rootUrlTemplate instead + * Only used in getBatch */ public $rootUrl; public $rootUrlTemplate; From 708e46ee8271828e738523dc17ba574f492474fb Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Feb 2024 17:13:11 -0700 Subject: [PATCH 08/11] add universe domain env var support --- src/Client.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index f38d79a8a..a586152b3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -171,7 +171,8 @@ class Client * from certain APIs. * @type string $universe_domain * Setting the universe domain will change the default rootUrl of the service. - * The universe domain is assumed to be "googleapis.com" if not set explicitly. + * If not set explicitly, the universe domain will be "googleapis.com", or the + * value provided in the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. * } */ public function __construct(array $config = []) @@ -205,8 +206,9 @@ public function __construct(array $config = []) 'cache_config' => [], 'token_callback' => null, 'jwt' => null, - 'api_format_v2' => false - 'universe_domain' => GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN, + 'api_format_v2' => false, + 'universe_domain' => getenv('GOOGLE_CLOUD_UNIVERSE_DOMAIN') + ?: GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN, ], $config); if (!is_null($this->config['credentials'])) { From 90ad66633fecc8b7ede98ec560afafce9df7911b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 27 Feb 2024 17:25:34 -0600 Subject: [PATCH 09/11] Update src/Client.php Co-authored-by: Vishwaraj Anand --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index a586152b3..c7724bd08 100644 --- a/src/Client.php +++ b/src/Client.php @@ -171,8 +171,8 @@ class Client * from certain APIs. * @type string $universe_domain * Setting the universe domain will change the default rootUrl of the service. - * If not set explicitly, the universe domain will be "googleapis.com", or the - * value provided in the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + * If not set explicitly, the universe domain will be the value provided in the + *. "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable, or "googleapis.com". * } */ public function __construct(array $config = []) From ac2e2cb575478180a60b8ac08da74196aab778bc Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 28 Feb 2024 15:39:42 -0600 Subject: [PATCH 10/11] add Universe Domain support for Batch --- src/Http/Batch.php | 7 ++++++- src/Service.php | 2 +- tests/Google/ServiceTest.php | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Http/Batch.php b/src/Http/Batch.php index f37045c01..d16708f20 100644 --- a/src/Http/Batch.php +++ b/src/Http/Batch.php @@ -62,7 +62,12 @@ public function __construct( ) { $this->client = $client; $this->boundary = $boundary ?: mt_rand(); - $this->rootUrl = rtrim($rootUrl ?: $this->client->getConfig('base_path'), '/'); + $rootUrl = rtrim($rootUrl ?: $this->client->getConfig('base_path'), '/'); + $this->rootUrl = str_replace( + 'UNIVERSE_DOMAIN', + $this->client->getUniverseDomain(), + $rootUrl + ); $this->batchPath = $batchPath ?: self::BATCH_PATH; } diff --git a/src/Service.php b/src/Service.php index 9909a87f4..8c8fe5fa7 100644 --- a/src/Service.php +++ b/src/Service.php @@ -69,7 +69,7 @@ public function createBatch() return new Batch( $this->client, false, - $this->rootUrl, + $this->rootUrlTemplate ?? $this->rootUrl, $this->batchPath ); } diff --git a/tests/Google/ServiceTest.php b/tests/Google/ServiceTest.php index 82abeb423..10bb44c7d 100644 --- a/tests/Google/ServiceTest.php +++ b/tests/Google/ServiceTest.php @@ -80,6 +80,7 @@ function ($request) { )->willReturn($response->reveal()); $client->getConfig('base_path')->willReturn(''); + $client->getUniverseDomain()->willReturn(''); $model = new TestService($client->reveal()); $batch = $model->createBatch(); From 30effefce50ca98b84d8198eb72f4beb14ee55b4 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 23 Apr 2024 17:53:08 -0700 Subject: [PATCH 11/11] Update apiclient-services minimum version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 23aaf3a81..c128a4f7e 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": "^7.4|^8.0", "google/auth": "^1.37", - "google/apiclient-services": "dev-universe-domain as 0.340", + "google/apiclient-services": "~0.350", "firebase/php-jwt": "~6.0", "monolog/monolog": "^2.9||^3.0", "phpseclib/phpseclib": "^3.0.34",