<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ryan Esteves</title>
    <description>The latest articles on DEV Community by Ryan Esteves (@snargledorf).</description>
    <link>https://dev.to/snargledorf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3946739%2F29941a24-d6a2-4567-b32b-707302987991.jpg</url>
      <title>DEV Community: Ryan Esteves</title>
      <link>https://dev.to/snargledorf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/snargledorf"/>
    <language>en</language>
    <item>
      <title>Fixing Google BigQuery Auth Proxying</title>
      <dc:creator>Ryan Esteves</dc:creator>
      <pubDate>Fri, 22 May 2026 20:15:08 +0000</pubDate>
      <link>https://dev.to/snargledorf/fixing-google-bigquery-auth-proxying-2hb7</link>
      <guid>https://dev.to/snargledorf/fixing-google-bigquery-auth-proxying-2hb7</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;builder.Credential = credential;&lt;/code&gt; - Fails to route authentication traffic through the proxy.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;builder.GoogleCredential = credential;&lt;/code&gt; - Successfully routes OAuth token requests through the proxy.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If your C# application runs behind a proxy, you have probably run into an annoying issue with the Google BigQuery client libraries: your BigQuery query calls route through the proxy perfectly by setting the &lt;code&gt;HttpClientFactory&lt;/code&gt; property on the &lt;code&gt;BigQueryClientBuilder&lt;/code&gt;, but the authentication and token refresh requests ignore the proxy entirely and attempt to hit the standard network, causing timeouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;To resolve this, &lt;strong&gt;set a proxied &lt;code&gt;GoogleCredential&lt;/code&gt; to the &lt;code&gt;GoogleCredential&lt;/code&gt; property instead of the &lt;code&gt;Credential&lt;/code&gt; property on the client builder.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Net&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Google.Apis.Auth.OAuth2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Google.Apis.Http&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Google.Cloud.BigQuery.V2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Configure your proxy&lt;/span&gt;
&lt;span class="n"&gt;IWebProxy&lt;/span&gt; &lt;span class="n"&gt;proxySettings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;WebProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"http://your-proxy-host:8080"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bypassOnLocal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Credentials&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NetworkCredential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Wrap it inside Google's API HttpClientFactory&lt;/span&gt;
&lt;span class="n"&gt;HttpClientFactory&lt;/span&gt; &lt;span class="n"&gt;proxyClientFactory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;HttpClientFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ForProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proxySettings&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// 3. Load credentials and create a new credential using the proxied http client factory &lt;/span&gt;
&lt;span class="n"&gt;GoogleCredential&lt;/span&gt; &lt;span class="n"&gt;credential&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;GoogleCredential&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromFileAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"path/to/service-account.json"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;credential&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateWithHttpClientFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;proxyClientFactory&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// 4. Construct the client&lt;/span&gt;
&lt;span class="n"&gt;BigQueryClient&lt;/span&gt; &lt;span class="n"&gt;bigQueryClient&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;BigQueryClientBuilder&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ProjectId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"your-google-cloud-project-id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;HttpClientFactory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;proxyClientFactory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Proxies BigQuery data calls&lt;/span&gt;
    &lt;span class="n"&gt;GoogleCredential&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;credential&lt;/span&gt;          &lt;span class="c1"&gt;// CRITICAL: Proxies Auth/token calls&lt;/span&gt;
&lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>dotnet</category>
      <category>googlecloud</category>
      <category>aspdotnet</category>
      <category>bigquery</category>
    </item>
  </channel>
</rss>
