public function testScopeIsAlwaysArray() { // include the mock AppIdentityService class require_once __DIR__ . '/mocks/AppIdentityService.php'; $scope1 = ['scopeA', 'scopeB']; $scope2 = 'scopeA scopeB'; $scope3 = 'scopeA'; $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine'; $g = new AppIdentityCredentials($scope1); $g->fetchAuthToken(); $this->assertEquals($scope1, AppIdentityService::$scope); $g = new AppIdentityCredentials($scope2); $g->fetchAuthToken(); $this->assertEquals(explode(' ', $scope2), AppIdentityService::$scope); $g = new AppIdentityCredentials($scope3); $g->fetchAuthToken(); $this->assertEquals([$scope3], AppIdentityService::$scope); }
/** * Obtains the default FetchAuthTokenInterface implementation to use * in this environment. * * If supplied, $scope is used to in creating the credentials instance if * this does not fallback to the Compute Engine defaults. * * @param string|array scope the scope of the access request, expressed * either as an Array or as a space-delimited String. * * @param $client GuzzleHttp\ClientInterface optional client. * @throws DomainException if no implementation can be obtained. */ public static function getCredentials($scope = null, $client = null) { $creds = CredentialsLoader::fromEnv($scope); if (!is_null($creds)) { return $creds; } $creds = CredentialsLoader::fromWellKnownFile($scope); if (!is_null($creds)) { return $creds; } if (AppIdentityCredentials::onAppEngine()) { return new AppIdentityCredentials($scope); } if (GCECredentials::onGce($client)) { return new GCECredentials(); } throw new \DomainException(self::notFound()); }