public function testShouldReturnTokenInfo()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $g = new GCECredentials();
     $this->assertEquals($wantedTokens, $g->fetchAuthToken($httpHandler));
 }
 /**
  * Abstract the GCECredentials call so we can mock it in the unit tests!
  *
  * @codeCoverageIgnore
  * @return bool
  */
 protected function onGce($httpHandler)
 {
     return GCECredentials::onGce($httpHandler);
 }
 /**
  * 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 callable $httpHandler callback which delivers psr7 request
  * @param array $cacheConfig configuration for the cache when it's present
  * @param CacheItemPoolInterface $cache
  *
  * @return CredentialsLoader
  *
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)
 {
     $creds = null;
     $jsonKey = CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile();
     if (!is_null($jsonKey)) {
         $creds = CredentialsLoader::makeCredentials($scope, $jsonKey);
     }
     if (AppIdentityCredentials::onAppEngine() && !GCECredentials::onAppEngineFlexible()) {
         $creds = new AppIdentityCredentials($scope);
     }
     if (GCECredentials::onGce($httpHandler)) {
         $creds = new GCECredentials();
     }
     if (is_null($creds)) {
         throw new \DomainException(self::notFound());
     }
     if (!is_null($cache)) {
         $creds = new FetchAuthTokenCache($creds, $cacheConfig, $cache);
     }
     return $creds;
 }
$app['config'] = Yaml::parse(file_get_contents($config));
// determine the datamodel backend using the app configuration
$app['bookshelf.model'] = function ($app) {
    /** @var array $config */
    $config = $app['config'];
    if (empty($config['bookshelf_backend'])) {
        throw new \DomainException('"bookshelf_backend" must be set in bookshelf config');
    }
    // Data Model
    switch ($config['bookshelf_backend']) {
        case 'mongodb':
            return new MongoDb($config['mongo_url'], $config['mongo_database'], $config['mongo_collection']);
        case 'datastore':
            return new Datastore($config['google_project_id']);
        case 'cloudsql':
            // Add Unix Socket for CloudSQL 2nd Gen when applicable
            $socket = GCECredentials::onGce() ? ';unix_socket=/cloudsql/' . $config['cloudsql_connection_name'] : '';
            return new CloudSql($config['mysql_dsn'] . $socket, $config['mysql_user'], $config['mysql_password']);
        default:
            throw new \DomainException("Invalid \"bookshelf_backend\" given: {$config['bookshelf_backend']}. " . "Possible values are cloudsql, mongodb, or datastore.");
    }
};
// Turn on debug locally
if (in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server') {
    $app['debug'] = true;
} else {
    $app['debug'] = filter_var(getenv('BOOKSHELF_DEBUG'), FILTER_VALIDATE_BOOLEAN);
}
// add service parameters
$app['bookshelf.page_size'] = 10;
return $app;
 /**
  * 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 callable $httpHandler callback which delivers psr7 request
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, callable $httpHandler = 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($httpHandler)) {
         return new GCECredentials();
     }
     throw new \DomainException(self::notFound());
 }