Exemplo n.º 1
0
 /**
  * Configure HTTP Client
  *
  * @return ClientInterface
  */
 protected function initHttpClient()
 {
     // Middleware
     $obj_stack = HandlerStack::create();
     $obj_stack->push(ApplicationDefaultCredentials::getMiddleware(['https://www.googleapis.com/auth/datastore']));
     // Create the HTTP client
     return new Client(['handler' => $obj_stack, 'base_url' => self::BASE_URL, 'auth' => 'google_auth']);
 }
 public function __construct($bucket = null)
 {
     $this->bucket = $bucket ?: getenv('GOOGLE_CLOUD_STORAGE_BUCKET');
     if (!$this->bucket) {
         throw new ConfigurationException("GOOGLE_CLOUD_STORGE_BUCKET is not set");
     }
     // create middleware
     $middleware = ApplicationDefaultCredentials::getMiddleware(config('storage.scopes'));
     $stack = HandlerStack::create();
     $stack->push($middleware);
     // create the HTTP client
     $this->client = new Client(['handler' => $stack, 'auth' => 'google_auth']);
 }
 public function testSuccedsIfNoDefaultFilesButIsOnGCE()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     // simulate the response from GCE.
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $this->assertNotNull(ApplicationDefaultCredentials::getMiddleware('a scope', $httpHandler));
 }