$metadata metadata hashmap * @param string $authUri optional auth uri * @param callable|null $httpHandler callback which delivers psr7 request * @return array updated metadata hashmap */ public function updateMetadata( $metadata, $authUri = null, ?callable $httpHandler = null ) { $metadata_copy = $metadata; // We do need to set the service api usage metrics irrespective even if // the auth token is set because invoking this method with auth tokens // would mean the intention is to just explicitly set the metrics metadata. $metadata_copy = $this->applyServiceApiUsageMetrics($metadata_copy); if (isset($metadata_copy[self::AUTH_METADATA_KEY])) { // Auth metadata has already been set return $metadata_copy; } $result = $this->fetchAuthToken($httpHandler); if (isset($result['access_token'])) { $metadata_copy[self::AUTH_METADATA_KEY] = ['Bearer ' . $result['access_token']]; } elseif (isset($result['id_token'])) { $metadata_copy[self::AUTH_METADATA_KEY] = ['Bearer ' . $result['id_token']]; } return $metadata_copy; } }