getContents(), true); if (!array_key_exists('type', $jsonKey)) { throw new \InvalidArgumentException('json key is missing the type field'); } if ($jsonKey['type'] == 'service_account') { return new ServiceAccountCredentials($scope, $jsonKey); } elseif ($jsonKey['type'] == 'authorized_user') { return new UserRefreshCredentials($scope, $jsonKey); } else { throw new \InvalidArgumentException('invalid value in the type field'); } } /** * export a callback function which updates runtime metadata. * * @return array updateMetadata function */ public function getUpdateMetadataFunc() { return array($this, 'updateMetadata'); } /** * Updates metadata with the authorization token. * * @param array $metadata metadata hashmap * @param string $authUri optional auth uri * @param callable $httpHandler callback which delivers psr7 request * * @return array updated metadata hashmap */ public function updateMetadata( $metadata, $authUri = null, callable $httpHandler = null ) { $result = $this->fetchAuthToken($httpHandler); if (!isset($result['access_token'])) { return $metadata; } $metadata_copy = $metadata; $metadata_copy[self::AUTH_METADATA_KEY] = array('Bearer ' . $result['access_token']); return $metadata_copy; } }